兩樣本平均數檢定統計量
要判斷兩個母體的平均數是否不同,所用的檢定統計量與你在第 1 章看到的 z 分數不同。這個統計量稱為「t」,可以用每個樣本的三個值代入下列公式計算:
$$ t = \dfrac{(\bar{x}_{\text{child}} - \bar{x}_{\text{adult}})}{\sqrt{\dfrac{s_{\text{child}}^2}{n_{\text{child}}} + \dfrac{s_{\text{adult}}^2}{n_{\text{adult}}}}} $$
在找出某些託運為何延遲的原因時,你可能會想知道:準時送達的貨件,其重量是否「小於」延遲送達的貨件。late_shipments 資料集已分成「yes」組(late == "Yes")與「no」組(late == "No")。貨件的重量記錄在變數 weight_kilograms 中。
兩組的樣本平均數已提供為 xbar_no 與 xbar_yes。樣本標準差為 s_no 與 s_yes。樣本大小為 n_no 與 n_yes。另已載入 numpy 並命名為 np。
本練習屬於課程
Python 中的假設檢定
練習說明
- 計算 \(t\) 檢定統計量的分子。
- 計算 \(t\) 檢定統計量的分母。
- 使用這兩個數字計算 \(t\) 檢定統計量。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Calculate the numerator of the test statistic
numerator = ____
# Calculate the denominator of the test statistic
denominator = ____
# Calculate the test statistic
t_stat = ____
# Print the test statistic
print(t_stat)