分層設計實驗
你正在與一個政府機關合作,他們想進行一項實驗,了解某些特定政府政策如何影響多個地區中個人的淨資產。
他們請你協助規劃實驗設計,並提醒你:資料中可能有一小群人的淨資產已經很高,擔心這群人會掩蓋任何實驗觀察到的效果。你正好知道該怎麼做!
運用你的實驗設計知識,對提供的 wealth_data DataFrame 依照 high_wealth 欄進行區組隨機化(分層)。這個 DataFrame 共有 2000 列,其中有 200 位高淨資產受試者(high_wealth 為 1)。
本練習屬於課程
Python 的實驗設計
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the first block
strata_1 = wealth_data[wealth_data[____] == ____]
strata_1['Block'] = ____
# Create two groups assigning to Treatment or Control
strata_1_g1 = strata_1.____(____, replace=False)
strata_1_g1['T_C'] = ____
strata_1_g2 = strata_1.drop(strata_1_g1.index)
strata_1_g2[____] = 'C'