Pergunta

I am working with the language [R] to generate a sample of M = 32000 averages each calculated by averaging 36 independent values ​​of the random variable continuous uniform distribution (0, 1) is generated as follows:

sampleA<-1:32000

for ( i in 1:32000){
    MuestraAUnif<- runif(36)
    sampleA[i]<-mean(MuestraAUnif)
}

For the sample generated ask me calculate relative frequency of observed averages greater than L = 0.32 +4 * 1 / 100 and compare it with the probability (approximated by "Central limit theorem") that the average N values ​​greater than L. as follows:

    L<- 0.32+4*1/100
    sigma<- sqrt(1/12) #(b-a)/12 
    miu = 0.5 #(a+b)/2
    greaterA <-sum(sampleA > L) #values of the sample greater than L are 23693
    xBar<- greaterA/length(sampleA) 
    X <- sum(sampleA) 
    n<-32000
    Zn<- (X - n*miu)/(sigma*sqrt(n))

    cat("P(xBar >",L,") = P(Z>", Zn, ")=","1 - P (Z < ", Zn,") =",1-pnorm(Zn),"\n") #print the theoretical prob Xbar greater than L
    cat("sum (sampleA >",L,")/","M=", n," para N =", 36,":",xBar, "\n") #print the sampling probability print when is greater than L

The output is:

P(xBar > 0.36 ) = P(Z> -3.961838 )= 1 - P (Z <  -3.961838 ) = 0.9999628 
sum (sampleA > 0.36 )/ M= 32000  para N = 36 : 0.7377187 

My question is: Why are so far values​​?, Presumably they should be much closer (0.9999628 is far from 0.7377187). Am I doing something wrong with my implementation?. Excuse my English.

Foi útil?

Solução

Melkhiah66. You did everything right only change MuestraAUnif<- runif(2) for MuestraAUnif<- runif(32) and it should work

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top