2016-08-24 21 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我明白了。是的,你可能是对的。我在你的版本中修正了括号/参数的位置(他们略微偏离了)并添加了它。干杯。 –