(a) Ten cards labelled 1,2,3, ..., 10 are shuffled and turned over one-by-one. Each time the ith card shows the number i it is considered a "hit". So if the second card turned shows "2" it is a "hit" otherwise not. Let the random variable X = the total number of "hits". Use simulations to estimate E[X]. in R
R code with comments
--------
#set the random seed
set.seed(123)
#set the number of simulations
R<-1000
#initialize the variable to hold number of hits
x<-numeric(R)
#do the simulations
for (i in 1:R) {
#flip the 10 cards
s<-sample(1:10,size=10,replace=FALSE)
#find the number of hits
x[i]<-sum(s==1:10)
}
#print the estimate of E(X)
sprintf('The estimated E(X)=%.4f',mean(x))
------
Get this
Get Answers For Free
Most questions answered within 1 hours.