【发布时间】:2021-07-30 11:55:19
【问题描述】:
问题
晚上好。
我正在学习中心极限定理。作为练习,我进行了模拟,试图找出公平骰子的平均值(我知道,这是一个玩具问题)。
我抽取了 4000 个样本,在每个样本中我掷了一个骰子 50 次(底部的代码截图)。对于这 4000 个样本中的每一个,我计算了平均值。然后,我使用matplotlib 将这 4000 个样本均值绘制在直方图中(bin 大小为 0.03)。
结果如下:
问题
鉴于 CLT(样本大小 >= 30)的条件得到遵守,为什么样本均值不呈正态分布?
具体来说,为什么直方图看起来像两个正态分布叠加在一起?更有趣的是,为什么“外部”分布看起来是“离散的”,并且以定期间隔出现空白?
结果似乎系统性地关闭了。
非常感谢所有帮助。我很迷茫。
补充代码
我用来生成 4000 个样本均值的代码。
"""
Take multiple samples of dice rolls. For
each sample, compute the sample mean.
With the sample means, plot a histogram.
By the Central Limit Theorem, the sample
means should be normally distributed.
"""
sample_means = []
num_samples = 4000
for i in range(num_samples):
# Large enough for CLT to hold
num_rolls = 50
sample = []
for j in range(num_rolls):
observation = random.randint(1, 6)
sample.append(observation)
sample_mean = sum(sample) / len(sample)
sample_means.append(sample_mean)
【问题讨论】:
-
当 num_rolls 等于 50 时,每个可能的平均值都是分母为 50 的分数。要正确获取所有可能的值,您可以使用
bins=np.arange(3.01, 4, 0.02) -
@JohanC 谢谢你的回复,这很有意义。我尝试从
3.01开始,但没有任何变化。也就是说,我将卷数增加到 500(从 50 个),现在分布更接近正常。我认为你在做某事! -
问题完全在于直方图中离散结果的位置,而不是 CLT。
标签: matplotlib jupyter-notebook statistics simulation