Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 1 Suppose n different cards are contained in a bag. You pick at card at

ID: 3351466 • Letter: P

Question

Problem 1 Suppose n different cards are contained in a bag. You pick at card at random, observe which one you picked, and place it in the bag. This procedure is repeated until you draw a card that you drew previously: let X be the total number of times you pick a card (a) Evaluate P(X > k) for k 1, 2, , n. oll (b) Write an R script file (or an R function) that can be used to estimate, via simulation, P(X>10) for the case where n = 30, Please turn in your R code, and talk about your output: you may find it easiest to give a short discussion here, which may require you to generate mltiple numbers

Explanation / Answer

set.seed(1001) #Fixing seed so as to get same output everytime
nnMC <- 1e5 #Number of simulations for the Monte Carlo

rand_number <- function(n){ #Function for generating a realised value of the RV
obs <- c(n+1)
s <- sample(1:n,1)
while(sum(!is.na(match(obs,s)))==0){
obs <- c(obs,s)
s <- sample(1:n,1)
}
length(obs)
}

### Evaluating P(X>k)

prob <- function(n,k){ #Function for calculating the prob
res <- numeric(nnMC)
for(i in 1:nnMC){
s <- rand_number(n)
if(s>k)
res[i] <- 1
}
sum(res)/nnMC
}

prob(30,10) #The P(X>10) when n=30

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote