开始使用免费开始使用

改变正态分布的标准差

您将继续探索美国成年男性的身高。您已经知道它们近似服从均值为 177 厘米、标准差为 8 厘米的正态分布。

在本练习中,您同样需要从正态分布中抽样,并计算平均身高的 95% 置信区间。不过这一次,您将在不改变均值的前提下,将标准差改为 15。您将探索在再次进行抽样时,平均值与置信区间会发生什么变化!

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

本练习是课程的一部分

Python 中的蒙特卡洛模拟

查看课程

练习说明

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

交互式实操练习

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

random.seed(1231)
heights_177_8 = st.norm.rvs(loc=177, scale=8, size=1000)
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 standard deviation is 15
heights_177_15 = ____
print(np.mean(heights_177_15))
upper = np.quantile(heights_177_15, 0.975)
lower = np.quantile(heights_177_15, 0.025)
print([lower, upper])
编辑并运行代码