2016-08-24 86 views
0
x1000 <- rep(NA, 1000) 
N = 10 

for(i in 1:1000){ 
    x1000[i] <- mean(rpois(1000, 0.3)) 
} 
hist(x1000, freq = F) 

curve(dnorm(x1000, mean = 0.3, sd = sqrt(0.3))) 

我想要得到疊加曲線。然而,它給了我:如何使用R得到dnorm曲線

Error in curve(dnorm(x1000, mean = 0.3, sd = sqrt(0.3))) : 
    'expr' must be a function, or a call or an expression containing 'x' 

回答

1

你接近,這是你自找的(技術)是什麼:

hist(x1000, col="red", freq=F) 
curve(dnorm(x, mean=.3,sd=sqrt(.3)), col="blue", add=T) # expression containing 'x' 

enter image description here

但我覺得你真的想要的是:

curve(dnorm(x, mean=mean(x1000),sd=sd(x1000)), col="blue", add=T) 

enter image description here

或者:

curve(dnorm(x, mean=mean(x1000),sd=sqrt(mean(x1000)/length(x1000)), col="blue", add=T) 

enter image description here

+0

也許用戶 「真的希望」'曲線(dnorm(X,平均值= 3,SD =開方(0.3/1000),山口=「藍色(平均值/平均值的標準誤差) – mnel

+1

當他繪製均值的採樣分佈並因此需要平均值的標準誤差(σ/ sqrt(n))時,他對標準偏差進行了誤計算。 sd(x1000)是一個估計(因此你的graphy作品)。因爲x1000是一種手段樣本(不是原始數據)。 – mnel

+0

@mnel我明白了。是的,你可能是對的。我在你的版本中修正了括號/參數的位置(他們略微偏離了)並添加了它。乾杯。 –