1
votes

Let Xi~U(0,30) be random variables. If one takes a sample of n=12, then we are interested in knowing the probability of the proportion to be greater than 18 i.e. $P(\overline X_{12}>18)$

Without using simulation and applied the CLT, the answer is .1150

Here is my approach to implement this in R using simulation:

SimProb<-function(N)
{
n=12

M<-matrix(runif(1,0,30),N,n)
rowMeann<-rowMeans(M)

for(i in 1:N)
{
  if(rowMeann[i]>18)
    c=cumsum(rowMeann[i])
    c

}
prob<-1-c
return(prob)
}

The code does not show any error but does not work properly.

When I was checking, it turns out c= 6.083532 which can't be.

For different values of N, SimProb returns only negative values, I don't understand why.

Could someone please help me?

1

1 Answers

2
votes

Here's a step-by-step solution.

  1. To generate a single sample we may use runif(12, 0, 30).
  2. The corresponding sample mean then is mean(runif(12, 0, 30)).
  3. As to estimate the true probability, we need to simulate many instances like that, which can be done with, e.g.

replicate(mean(runif(12, 0, 30)), n = 10000)
  1. Then we want to find (number of times mean(runif(12, 0, 30)) is greater than 18) / 10000, which can be done with

set.seed(1)
mean(replicate(mean(runif(12, 0, 30)), n = 10000) > 18)
# [1] 0.1163

which is indeed very close to your provided value.