เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การแสดงภาพ 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)
แก้ไขและรันโค้ด