比例差异的显著性
通勤骑行仍不常见,但华盛顿特区的比例不低。过去几年里,这一比例提高了超过 1 个百分点,但这是否是统计上显著的增长?在本练习中,您将先计算比例的标准误,然后计算两样本比例的 Z 统计量。
比例的标准误(SE)公式为:
$$SE_P = \frac{1}{N}\sqrt{SE_n^2 - P^2SE_N^2}$$
两样本 Z 统计量的公式为:
$$Z = \frac{x_1 - x_2}{\sqrt{SE_{x_1}^2 + SE_{x_2}^2}}$$
数据框 dc 已加载。它包含控制台中显示的列:总就业人数与骑行通勤人数的估计值(以 "_est" 结尾)和误差范围(以 "_moe" 结尾)。
已从 numpy 模块导入 sqrt 函数。
本练习是课程的一部分
使用 Python 分析美国人口普查数据
练习说明
- 通过用骑行者人数除以总就业人数来计算
bike_share - 通过用 MOE 除以
Z_CRIT来计算骑行者和总就业人数估计值的 SE - 计算比例的 SE:
se_bike是子总体的 SE,即 $SE_n$;bike_share是比例 $P$;se_total是总体的 SE,即 \(SE_N\) - 计算 $Z$:\(x_1\) 和 \(x_2\) 分别是 2017 年和 2011 年的
bike_share;\(SE_{x_1}\) 和 \(SE_{x_2}\) 分别是 2017 年和 2011 年的se_p
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Set the critical Z score for 90% confidence
Z_CRIT = 1.645
# Calculate share of bike commuting
dc["bike_share"] = ____
# Calculate standard errors of the estimate from MOEs
dc["se_bike"] = ____
dc["se_total"] = ____
dc["se_p"] = sqrt(____**2 - ____**2 * ____**2)**0.5 / dc["total_est"]
# Calculate the two sample statistic between 2011 and 2017
Z = (dc[dc["year"] == 2017]["bike_share"] - ____) / \
sqrt(____**2 + ____**2)
print(Z_CRIT < Z)