การแสดงภาพ P-Value
ในแบบฝึกหัดนี้ จะได้แสดงภาพ p-value ซึ่งบ่งบอกโอกาสที่เอฟเฟกต์ (หรือ "ความเร็ว") ที่ประมาณไว้นั้นเกิดจากความแปรปรวนแบบสุ่มในตัวอย่าง เป้าหมายคือแสดงภาพค่านี้ในรูปของสัดส่วนจุดในการกระจายของ test statistic แบบสับเปลี่ยนที่อยู่ทางขวาของค่าเฉลี่ย test statistic ("effect size") ที่คำนวณจากตัวอย่างที่ยังไม่ได้สับเปลี่ยน
เพื่อเตรียมความพร้อม เราได้โหลด group_duration_short และ group_duration_long รวมถึงฟังก์ชัน compute_test_statistic(), shuffle_and_split() และ plot_test_statistic_effect() ไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Introduction to Linear Modeling in Python
คำแนะนำการฝึกหัด
- ใช้
compute_test_statistic()เพื่อหาค่าtest_statistic_unshuffledจากgroup_duration_shortและgroup_duration_longจากนั้นใช้np.mean()คำนวณ effect size - ใช้
shuffle_and_split()เพื่อสร้างshuffle_half1และshuffle_half2แล้วใช้compute_test_statistic()คำนวณtest_statistic_shuffled - สร้างบูลีนมาสก์
conditionสำหรับค่าtest_statistic_shuffledที่มากกว่าหรือเท่ากับeffect_sizeจากนั้นใช้มาสก์นี้คำนวณp_value - แสดงผล
p_valueและพล็อต test statistic ทั้งสองด้วยplot_test_statistic_effect()
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Compute the test stat distribution and effect size for two population groups
test_statistic_unshuffled = compute_test_statistic(____, ____)
effect_size = np.mean(____)
# Randomize the two populations, and recompute the test stat distribution
shuffled_half1, ____ = shuffle_and_split(group_duration_short, ____)
test_statistic_shuffled = compute_test_statistic(shuffled_half1, ____)
# Compute the p-value as the proportion of shuffled test stat values >= the effect size
condition = ____ >= ____
p_value = len(test_statistic_shuffled[____]) / len(test_statistic_shuffled)
# Print p-value and overplot the shuffled and unshuffled test statistic distributions
print("The p-value is = {}".format(____))
fig = plot_test_stats_and_pvalue(test_statistic_unshuffled, test_statistic_shuffled)