虛無假設
在這個練習中,我們設定虛無假設為:
短與長的時間長度對總行駛距離沒有影響。
我們將「效果量為 0」解讀為:如果把短時間與長時間的樣本互相洗牌,讓兩個新樣本各自都混合了短與長的旅程,接著計算檢定統計量,則其平均值會是 0。
在這個練習中,你的目標是完成洗牌與重抽樣。請從預先定義的 group_duration_short 與 group_duration_long(尚未洗牌的時間長度分組)開始。
本練習屬於課程
Python 線性建模入門
練習說明
- 使用
np.concatenate()合併兩個母群,然後使用np.random.shuffle()將其中的值洗牌。 - 將
shuffle_bucket對半切開,並對每個shuffle_half使用np.random.choice()進行重抽樣。 - 以
resample_half2減去resample_half1來計算test_statistic。 - 將
effect_size設為test_statistic的np.mean(),並印出結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Shuffle the time-ordered distances, then slice the result into two populations.
shuffle_bucket = np.____((group_duration_short, group_duration_long))
np.random.shuffle(____)
slice_index = len(shuffle_bucket)//2
shuffled_half1 = shuffle_bucket[0:____]
shuffled_half2 = shuffle_bucket[____:]
# Create new samples from each shuffled population, and compute the test statistic
resample_half1 = np.random.choice(____, size=500, replace=____)
resample_half2 = np.random.choice(____, size=500, replace=____)
test_statistic = ____ - ____
# Compute and print the effect size
effect_size = np.mean(____)
print('Test Statistic, after shuffling, mean = {}'.format(____))