开始使用免费开始使用

改变正态分布的均值

在本练习中,您将通过抽样来计算美国成年男性平均身高的 95% 置信区间。回顾课程内容:美国成年男性的身高服从正态分布,均值为 177 厘米,标准差为 8 厘米。

在使用上述样本统计量从该分布抽样之后,您将把身高的均值改为 185 厘米,同时保持标准差不变,以探索再次抽样后平均身高的均值和置信区间会发生什么变化。

以下内容已为您导入:random、以 np 命名的 NumPy,以及以 st 命名的 SciPy 的 stats 模块。

本练习是课程的一部分

Python 中的蒙特卡洛模拟

查看课程

练习说明

  • 从均值为 177、标准差为 8 的正态分布中抽样 1,000 次;将结果存入 heights_177_8
  • 从均值为 185、标准差为 8 的正态分布中抽样 1,000 次;将结果存入 heights_185_8

交互式实操练习

通过完成这段示例代码来试试这个练习。

random.seed(1222)

# Sample 1,000 times from the normal distribution where the mean is 177
heights_177_8 = ____
print(np.mean(heights_177_8))
upper = np.quantile(heights_177_8, 0.975)
lower = np.quantile(heights_177_8, 0.025)
print([lower, upper])

# Sample 1,000 times from the normal distribution where the mean is 185
heights_185_8 = ____
print(np.mean(heights_185_8))
upper = np.quantile(heights_185_8, 0.975)
lower = np.quantile(heights_185_8, 0.025)
print([lower, upper])
编辑并运行代码