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

ช่วงความเชื่อมั่นสำหรับค่าตอบสนองเฉลี่ยของทุก Observation

ช่วงความเชื่อมั่นสำหรับค่าตอบสนองเฉลี่ยสามารถคำนวณได้สำหรับทุก observation ในชุดข้อมูล การใช้ augment() กับชุดข้อมูล twins โดยตรงจะให้ค่าพยากรณ์และค่า standard error ของ Foster twin จากข้อมูล Biological ทั้งหมด

โปรดทราบว่าการคำนวณเส้นถดถอยมีความเสถียรมากกว่าบริเวณกลางของข้อมูล ดังนั้นค่าพยากรณ์ที่ค่า IQ สุดโต่งจึงมีความแปรปรวนมากกว่าบริเวณกลางของช่วง IQ ของตัวแปรอิสระ

ค่าพยากรณ์ IQ ของ Foster twin ที่คำนวณไว้ครั้งที่แล้วถูกเก็บไว้ใน predictions และแสดงผลในกราฟด้วย geom_smooth()

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

การอนุมานสำหรับการถดถอยเชิงเส้นใน R

ดูคอร์ส

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

สร้างกราฟที่ได้ผลเหมือน geom_smooth() ด้วยตัวเอง โดยใช้ predictions และกำหนด aesthetics กับ data ให้แต่ละ geom

  • เพิ่ม layer จุด (point) ของ Foster เทียบกับ Biological โดยใช้ data = twins
  • เพิ่ม layer เส้น (line) ของ .fitted เทียบกับ Biological โดยใช้ data = predictions และกำหนดสีเส้นเป็น "blue"
  • เพิ่ม layer ribbon โดย map x เป็น Biological, ymin เป็น lower_mean_prediction และ ymax เป็น upper_mean_prediction พร้อมกำหนด data = predictions และความโปร่งใส alpha เป็น 0.2

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

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

# This plot is shown
ggplot(twins, aes(x = Biological, y = Foster)) + 
  geom_point() +
  geom_smooth(method = "lm") 

ggplot() + 
  # Add a point layer of Foster vs. Biological, using twins
  ___(aes(___, ___), data = ___) +
  # Add a line layer of .fitted vs Biological, using predictions, colored blue
  ___ +
  # Add a ribbon layer of lower_mean_prediction to upper_mean_prediction vs Biological, 
  # using predictions, transparency of 0.2
  ___
แก้ไขและรันโค้ด