ช่วงความเชื่อมั่นสำหรับค่าตอบสนองเฉลี่ยของทุก 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
___