Fill in the blanks in the following simulation for R, which finds the approximat
ID: 3912206 • Letter: F
Question
Fill in the blanks in the following simulation for R, which finds the approximate variance of N, the number of rolls of a die needed to get the face having just one dot.
onesixth <- 1/6
sumn <- 0
sumn2 <- 0
for (i in 1:10000) {
n <- 0
while(TRUE) { ________________________________________
if (______________________________ < onesixth) break
}
sumn <- sumn + n
sumn2 <- sumn2 + n^2
}
approxvarn <- ____________________________________________
cat("the approx. value of Var(N) is ",approxvarn," ")
Explanation / Answer
Solution:
onesixth <- 1/6
sumn <- 0
sumn2 <- 0
for (i in 1:10000) {
n <- 0
while(TRUE) { n <- n + 1
if (runif(1) < onesixth) break
}
sumn <- sumn + n
sumn2 <- sumn2 + n^2
}
approxvarn <- sumn2/10000 - (sumn/10000)^2
cat("the approx. value of Var(N) is ",approxvarn," ")
Sample Output:
Note: If you have any doubt, please cmment below, before giving any negative reply. If you liked it then go ahead and hit the thumbs up button.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.