การกระจายเชิงทำนายหลัง posterior
data frame weight_chains (ใน workspace ของคุณ) มีการทำนาย posterior จำนวน 100,000 ค่า ซึ่งก็คือ Y_180 สำหรับน้ำหนักของผู้ใหญ่ที่มีส่วนสูง 180 ซม.:
> head(weight_chains, 2)
a b s iter m_180 Y_180
1 -113.9029 1.072505 8.772007 1 79.14803 71.65811
2 -115.0644 1.077914 8.986393 2 78.96014 75.78893
จะใช้การทำนาย 100,000 ค่านี้เพื่อประมาณ การกระจายเชิงทำนายหลัง posterior สำหรับน้ำหนักของผู้ใหญ่ที่มีส่วนสูง 180 ซม. โดยข้อมูล bdims อยู่ใน workspace แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การสร้างแบบจำลอง Bayesian ด้วย RJAGS
คำแนะนำการฝึกหัด
- ใช้ค่า
Y_180จำนวน 10,000 ค่า เพื่อสร้างช่วงความน่าเชื่อถือ posterior 95% สำหรับน้ำหนักของผู้ใหญ่ที่มีส่วนสูง 180 ซม. - สร้าง density plot จากการทำนายที่เป็นไปได้ทั้ง 100,000 ค่า
- สร้าง scatterplot ของข้อมูล
wgtเทียบกับhgtในbdims- ใช้
geom_abline()เพื่อวางแนวโน้มการถดถอย posterior ทับลงบนกราฟ - ใช้
geom_segment()เพื่อวางเส้นแนวตั้งที่hgtเท่ากับ 180 ซึ่งแสดงขอบเขตล่างและบน (yและyend) ของci_180
- ใช้
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Construct a posterior credible interval for the prediction
ci_180 <- quantile(___, probs = c(___, ___))
ci_180
# Construct a density plot of the posterior predictions
ggplot(___, aes(x = ___)) +
geom_density() +
geom_vline(xintercept = ci_180, color = "red")
# Visualize the credible interval on a scatterplot of the data
ggplot(___, aes(x = ___, y = ___)) +
geom_point() +
geom_abline(intercept = mean(___), slope = mean(___), color = "red") +
geom_segment(x = 180, xend = 180, y = ___, yend = ___, color = "red")