開始使用免費開始

假設檢定:女子選手在準決賽與決賽的游法是否相同?

以分數改善幅度的平均值作為檢定統計量,檢定決賽與準決賽表現是否相同的虛無假設。在虛無假設下,若檢定統計量大於或等於命名空間中已有的 f_mean,就視為至少與觀察值同樣極端。

準決賽與決賽的時間已存於 numpy 陣列 semi_timesfinal_times 中。

本練習屬於課程

統計思維個案研究

檢視課程

練習說明

  • 使用 np.empty() 建立一個可容納 1000 次排列重抽的空陣列,命名為 perm_reps
  • 撰寫一個 for 迴圈來產生排列重抽。
    • 使用你剛寫的 swap_random() 函式產生一組排列樣本。將結果分別存入 semi_permfinal_perm
    • 由這組排列樣本計算 f 的值。
    • 將此排列樣本的平均值存入 perm_reps 陣列。
  • 計算 p 值並將其印出。

動手互動練習

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

# Set up array of permutation replicates
perm_reps = ____

for i in range(1000):
    # Generate a permutation sample
    semi_perm, final_perm = ____
    
    # Compute f from the permutation sample
    f = (____ - ____) / ____
    
    # Compute and store permutation replicate
    perm_reps[i] = ____

# Compute and print p-value
print('p =', ____(____ >= ____) / 1000)
編輯並執行程式碼