(Reproducible example added.)
I am little bit confused about rnorm function.
I expected mean(rnorm(100,mean=0,sd=1))
to be 0; and sd(rnorm(100,mean=0,sd=1))
to be 1. But gave different results. Where am I wrong?
Reproducible Example:
mean(rnorm(100,mean=0,sd=1))
# [1] 0.07872548
sd(rnorm(100,mean=0,sd=1))
# [1] 1.079348
Any help is greatly appreciated.
rnorm(100)
gives you a random sample of 100 values from distribution mean = 0 and sd = 1. Because it is random, the actual value of mean(rnorm(100))
depends on which particular values you get back. There is no guarantee that the mean will be 0, but statistically it should converge to 0 as you use larger sample sizes. For example, try mean(rnorm(10000))
; it will probably be closer to 0 than before.
Edit: If you want to force the sample to have a particular mean and standard deviation, check out this question: "Generate random numbers with fixed mean and sd".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With