開始使用免費開始

兩樣本平均數檢定統計量

要判斷兩個母體的平均數是否不同,所用的檢定統計量與你在第 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_noxbar_yes。樣本標準差為 s_nos_yes。樣本大小為 n_non_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)
編輯並執行程式碼