使用 rnorm 创建的正态随机变量的平均值输出为什么不等于 10,而在 R 中进行手动计算时为 10?
当我们发现使用 rnorm(“sample_size”,10) 创建的正态随机变量的平均值不为 10 时,这是因为 rnorm 会创建一个随机变量,因此平均值会发生变化,但当我们增加样本大小时,平均值将逐渐接近 10。
查看下面给出的示例以了解随着样本大小的增加,输出平均值的差异。
示例
以下说明了使用 rnorm 创建的正态随机变量的平均值的输出差异,随着样本大小的增加而变化的情况 -
mean(rnorm(100,mean=10)) mean(rnorm(100,mean=10)) mean(rnorm(100,mean=10)) mean(rnorm(100,mean=10)) mean(rnorm(100,mean=10)) mean(rnorm(100,mean=10)) mean(rnorm(100,mean=10)) mean(rnorm(1000,mean=10)) mean(rnorm(1000,mean=10)) mean(rnorm(1000,mean=10)) mean(rnorm(10000,mean=10)) mean(rnorm(10000,mean=10)) mean(rnorm(10000,mean=10)) mean(rnorm(10000,mean=10)) mean(rnorm(10000,mean=10)) mean(rnorm(100000,mean=10)) mean(rnorm(100000,mean=10)) mean(rnorm(100000,mean=10)) mean(rnorm(100000,mean=10)) mean(rnorm(100000,mean=10)) mean(rnorm(1000000,mean=10)) mean(rnorm(1000000,mean=10)) mean(rnorm(1000000,mean=10)) mean(rnorm(1000000,mean=10)) mean(rnorm(1000000,mean=10)) mean(rnorm(10000000,mean=10)) mean(rnorm(10000000,mean=10)) mean(rnorm(10000000,mean=10)) mean(rnorm(100000000,mean=10))
输出如下
[1] 10.13626 [1] 9.892686 [1] 9.938534 [1] 9.918113 [1] 10.12262 [1] 10.05268 [1] 10.06714 [1] 9.953736 [1] 10.02104 [1] 9.973183 [1] 9.994081 [1] 10.00588 [1] 9.983589 [1] 10.00452 [1] 10.00093 [1] 9.999846 [1] 9.999979 [1] 9.996462 [1] 10.00455 [1] 10.00049 [1] 9.999261 [1] 9.998425 [1] 9.999633 [1] 10.00064 [1] 9.998785 [1] 10.00003 [1] 9.999948 [1] 9.99997
广告