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

กระแสน้ำส่งผลต่อผลการแข่งขันอย่างไรตามตำแหน่งเลน?

เพื่อวัดผลของหมายเลขเลนต่อผลการแข่งขัน ให้ทำ linear regression กับข้อมูล f_13 เทียบกับ lanes จากนั้นทำ pairs bootstrap เพื่อหา confidence interval 95% และสร้างกราฟแสดงผลการ regression โดย array lanes และ f_13 อยู่ใน namespace แล้ว

หมายเหตุ: แม้จะสามารถคำนวณ error bar ของค่าเฉลี่ยความแตกต่างเชิงเศษส่วน (fractional difference) และนำมาใช้ใน regression ได้ แต่เนื้อหาส่วนนั้นอยู่นอกเหนือขอบเขตของคอร์สนี้

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

กรณีศึกษาด้านการคิดเชิงสถิติ

ดูคอร์ส

คำแนะนำการฝึกหัด

  • คำนวณ slope และ intercept ของเส้น f_13 เทียบกับ lanes โดยใช้ np.polyfit()
  • ใช้ dcst.draw_bs_pairs_linreg() เพื่อสร้าง bootstrap replicate จำนวน 10,000 ค่าของ slope และ intercept โดยเก็บไว้ใน bs_reps_slope และ bs_reps_int ตามลำดับ
  • ใช้ bootstrap replicate คำนวณ confidence interval 95% ของ slope
  • แสดงค่า slope และ confidence interval 95% บนหน้าจอ (ส่วนนี้ทำไว้ให้แล้ว)
  • ใช้ np.array() สร้างค่า x สำหรับพล็อตเส้น bootstrap โดย x ควรมีค่าตั้งแต่ 1 ถึง 8
  • กราฟมีข้อมูลอยู่แล้ว ให้เขียนลูป for เพื่อเพิ่มเส้น bootstrap 100 เส้นลงในกราฟ โดยใช้ keyword argument color='red', alpha=0.2 และ linewidth=0.5

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# Compute the slope and intercept of the frac diff/lane curve
____, ____ = ____

# Compute bootstrap replicates
bs_reps_slope, bs_reps_int = ____

# Compute 95% confidence interval of slope
conf_int = ____

# Print slope and confidence interval
print("""
slope: {0:.5f} per lane
95% conf int: [{1:.5f}, {2:.5f}] per lane""".format(slope, *conf_int))

# x-values for plotting regression lines
x = ____

# Plot 100 bootstrap replicate lines
for i in ____:
    _ = ____(____, ____[i] * ____ + ____[i], 
                 color='red', alpha=0.2, linewidth=0.5)
   
# Update the plot
plt.draw()
plt.show()
แก้ไขและรันโค้ด