視覺化檢定統計量
在這個練習中,你會用兩種方式產生的檢定統計量的分佈來接近虛無假設。
首先,你會檢視兩個「母體」,依早與晚的時間分組,並計算檢定統計量的分佈。接著,將這兩個母體洗牌,使資料不再依時間排序,且各自同時包含早與晚的時間,然後重新計算檢定統計量的分佈。
為了讓你快速上手,我們已經預先載入兩個時間長度分組 group_duration_short 與 group_duration_long,以及兩個函式 shuffle_and_split() 和 plot_test_statistic()。
本練習屬於課程
Python 線性建模入門
練習說明
- 使用
np.random.choice()對group_duration_short與group_duration_long進行重新抽樣,並取兩者差來計算test_statistic_unshuffled。 - 對原始的
group_duration_short與group_duration_long(以此順序指定)使用shuffle_and_split(),以建立兩個新的混合母體。 - 對洗牌後的母體重新抽樣,並以
resample_long減去resample_short來計算新的test_statistic_shuffled。 - 使用
plot_test_statistic()同時繪製兩個檢定統計量的分佈,並加以視覺比較。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# From the unshuffled groups, compute the test statistic distribution
resample_short = np.random.choice(____, size=500, replace=____)
resample_long = np.random.choice(____, size=500, replace=____)
test_statistic_unshuffled = ____ - ____
# Shuffle two populations, cut in half, and recompute the test statistic
shuffled_half1, shuffled_half2 = shuffle_and_split(____, ____)
resample_half1 = np.random.choice(____, size=500, replace=____)
resample_half2 = np.random.choice(____, size=500, replace=____)
test_statistic_shuffled = resample_half2 - resample_half1
# Plot both the unshuffled and shuffled results and compare
fig = plot_test_statistic(____, label='Unshuffled')
fig = plot_test_statistic(____, label='Shuffled')