比例差異的顯著性
以自行車通勤的人仍不多,但華盛頓特區的比例不錯。近幾年已經上升超過 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}}$$
已載入 DataFrame dc。它包含(在主控台中顯示)總就業人口與自行車通勤者的估計值(以 "_est" 結尾)與誤差範圍(以 "_moe" 結尾)。
numpy 模組中的 sqrt 函式已經匯入。
本練習屬於課程
使用 Python 分析美國 Census 資料
練習說明
- 以騎車人數除以總就業人口數,計算
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)