開始使用免費開始

青蛙資料的置換檢定

青蛙 A 的平均擊打力為 0.71 牛頓(N),青蛙 B 為 0.42 N,兩者差異為 0.29 N。也有可能兩隻青蛙實際上施力相同,而你觀察到的差異只是隨機造成。你將在假設兩隻青蛙的擊打力量分佈相同的前提下,計算出現至少 0.29 N 平均擊打力差異的機率。我們會使用置換檢定,並以「平均數差」作為檢定統計量來檢驗此假設。

為了方便,你可以直接使用已存成陣列的資料 force_aforce_b

本練習屬於課程

Statistical Thinking in Python(第 2 部分)

檢視課程

練習說明

  • 定義一個函式,呼叫介面為 diff_of_means(data_1, data_2),回傳兩個資料集平均數的差(data_1 的平均數減去 data_2 的平均數)。
  • 使用此函式計算在青蛙實驗中觀察到的經驗平均差。
  • 抽取 10,000 次以平均數差為統計量的置換重抽樣。
  • 計算 p 值。
  • 列印 p 值。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

def diff_of_means(data_1, data_2):
    """Difference in means of two arrays."""

    # The difference of means of data_1, data_2: diff
    diff = ____

    return diff

# Compute difference of mean impact force from experiment: empirical_diff_means
empirical_diff_means = ____

# Draw 10,000 permutation replicates: perm_replicates
perm_replicates = draw_perm_reps(____, ____,
                                 ____, size=10000)

# Compute p-value: p
p = np.sum(____ >= ____) / len(____)

# Print the result
print('p-value =', p)
編輯並執行程式碼