手算信賴區間
面試常見的兩種方式會考到信賴區間:一是要你用簡單方式解釋概念,二是說明如何計算,甚至要你實作。在這個練習中,你要練習後者,手動產生一個信賴區間,只使用已為你匯入的套件。
我們已替你指定 95% 信賴區間所需的 z 分數與樣本平均,分別存在 z_score 與 sample_mean 變數,讓題目更聚焦。
本練習屬於課程
用 Python 練習統計面試題
練習說明
- 使用為你匯入的
sem()函式與z_score變數,計算標準誤與誤差範圍(margin of error)。 - 使用為你匯入的
sample_mean變數,計算並印出信賴區間的下界。 - 使用為你匯入的
sample_mean變數,計算並印出信賴區間的上界。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
from scipy.stats import sem, t
data = [1, 2, 3, 4, 5]
confidence = 0.95
# Compute the standard error and margin of error
std_err = sem(____)
margin_error = std_err * ____
# Compute and print the lower threshold
lower = sample_mean - ____
print(____)
# Compute and print the upper threshold
upper = sample_mean + ____
print(____)