0

我正在用語言[R]生成一個M = 32000平均值的樣本,每個平均值通過平均36個獨立值隨機變量連續均勻分佈(0,1)如下產生:[R]中的中心極限定理

sampleA<-1:32000 

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

對於樣品生成提問計算觀察到的平均比L = 0.32 4 * 1 /大100的相對頻率,並將其與概率(用「Central limit theorem」近似)的平均比較N值大於L.如下:

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 

輸出是:

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 

我的問題是:爲什麼是迄今爲止值,想必他們應該是非常接近(0.9999628遠未0.7377187)。我在做我的執行有問題嗎?請原諒我的英語。

回答

2

Melkhiah66。你做的一切權利只是改變 MuestraAUnif<- runif(2)MuestraAUnif<- runif(32) ,它應該工作

+0

我已經做了,是我的錯拷貝,但仍然無法正常工作,或不告訴我,我想 – franvergara66 2012-01-30 02:59:37

+0

我使用seet.seed結果( 129)並得到:sum(sampleA> 0.3599999999999999866773)/ M = 32000.00000000000000000 N = 36.0000000000000000000:0.998125000000000039968。不是你所期望的? – aatrujillob 2012-01-30 03:09:10

+0

對於N = 36,理想值應該是 P(Xbar> 0.36)= P(Z> -2.909845)= 1 -P(Z <-2.909845)= 0.998192 總和(樣品a> 0.36)/ M = 32000 :0.9984063,但你的答案非常接近,你做了什麼? – franvergara66 2012-01-30 03:18:52