如何使用 R 获得 dnorm 曲线
How to get dnorm curve using R
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)))
我正在尝试获取叠加曲线。但是,它给了我:
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'
你很接近,这就是你要求的(技术上):
hist(x1000, col="red", freq=F)
curve( dnorm(x, mean=.3,sd=sqrt(.3)), col="blue", add=T) # expression containing 'x'
但我认为你真正想要的是:
curve( dnorm(x, mean=mean(x1000),sd=sd(x1000)), col="blue", add=T)
或者:
curve( dnorm(x, mean=mean(x1000),sd=sqrt(mean(x1000)/length(x1000)), col="blue", add=T)
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)))
我正在尝试获取叠加曲线。但是,它给了我:
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'
你很接近,这就是你要求的(技术上):
hist(x1000, col="red", freq=F)
curve( dnorm(x, mean=.3,sd=sqrt(.3)), col="blue", add=T) # expression containing 'x'
但我认为你真正想要的是:
curve( dnorm(x, mean=mean(x1000),sd=sd(x1000)), col="blue", add=T)
或者:
curve( dnorm(x, mean=mean(x1000),sd=sqrt(mean(x1000)/length(x1000)), col="blue", add=T)