均值是否等于方差?
在 Poisson 模型中,其中一个假设是均值应与方差相同。正如您在讲解中学到的,如果该假设不成立,就会出现过度离散。如果不对过度离散进行调整,您会对给定模型的标准误产生错误解读。
在本练习中,您将先计算雌性蟹的卫星数量的均值和方差。
crab 数据集已加载到您的工作区。
本练习是课程的一部分
Python 中的广义线性模型
练习说明
- 使用
numpy的mean()计算并打印卫星数量变量sat的样本均值,命名为sat_mean。 - 使用
numpy的var()计算并打印卫星数量变量sat的样本方差,命名为sat_var。 - 计算并打印
sat_var与sat_mean的比值。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Compute and print sample mean of the number of satellites: sat_mean
____ = np.____(____.____)
print('Sample mean:', round(____, 3))
# Compute and print sample variance of the number of satellites: sat_var
____ = np.____(____.____)
print('Sample variance:', round(____, 3))
# Compute ratio of variance to mean
print('Ratio:', round(____/____, 3))