การวินิจฉัยและการทำซ้ำของ Markov chain

การสร้างแบบจำลอง Bayesian ด้วย RJAGS

Alicia Johnson

Associate Professor, Macalester College

ผลลัพธ์ของ Markov chain

การสร้างแบบจำลอง Bayesian ด้วย RJAGS

คำถามที่ควรพิจารณา

  • Markov chain ที่ "ดี" มีลักษณะอย่างไร?

  • การประมาณค่า posterior ด้วย Markov chain แม่นยำแค่ไหน?

  • ควรรัน Markov chain กี่รอบ?

การสร้างแบบจำลอง Bayesian ด้วย RJAGS

การวินิจฉัย: trace plot

การสร้างแบบจำลอง Bayesian ด้วย RJAGS

การวินิจฉัย: trace plot

ดี: มีเสถียรภาพ!

ไม่ดี: ไม่มีเสถียรภาพ

การสร้างแบบจำลอง Bayesian ด้วย RJAGS

การวินิจฉัย: หลาย chain

# COMPILE the model
sleep_jags <- jags.model(..., n.chains = 1)

การสร้างแบบจำลอง Bayesian ด้วย RJAGS

การวินิจฉัย: หลาย chain

# COMPILE the model
sleep_jags <- jags.model(..., n.chains = 2)

การสร้างแบบจำลอง Bayesian ด้วย RJAGS

การวินิจฉัย: หลาย chain

# COMPILE the model
sleep_jags <- jags.model(..., n.chains = 4)

การสร้างแบบจำลอง Bayesian ด้วย RJAGS

การวินิจฉัย: หลาย chain

# COMPILE the model
sleep_jags <- jags.model(..., n.chains = 4)

การสร้างแบบจำลอง Bayesian ด้วย RJAGS
summary(sleep_sim)
1. Empirical mean and standard deviation for each variable,
   plus standard error of the mean:

   Mean    SD Naive SE Time-series SE
m 29.10 8.968   0.2836         0.2820
s 40.07 7.887   0.2494         0.4227

2. Quantiles for each variable:

   2.5%   25%   50%   75% 97.5%
m 11.42 23.27 28.85 34.76 46.76
s 28.31 34.65 38.93 43.91 57.56
  • ค่าประมาณ ของค่าเฉลี่ย posterior ของ $m$ = 29.10 ms

  • (Naive) standard error ของค่าประมาณนี้ = 0.2836 ms
    SD / $\sqrt{\text{number of iterations}}$

การสร้างแบบจำลอง Bayesian ด้วย RJAGS

การวินิจฉัย: standard error

  • ค่าเฉลี่ย ที่ประมาณได้ = 29.10 ms

  • (Naive) standard error = 0.2836 ms

  • $29.10 \pm 2*0.2836$
การสร้างแบบจำลอง Bayesian ด้วย RJAGS

ขั้นตอนการทำงานกับ Markov chain

  • กำหนด คอมไพล์ และ simulate โมเดล

  • ตรวจสอบการวินิจฉัยต่อไปนี้:

    • Trace plot
    • ผลลัพธ์จากหลาย chain
    • Standard error
  • สรุปผลการ simulate

การสร้างแบบจำลอง Bayesian ด้วย RJAGS

การสรุป Markov chain: การทำซ้ำได้

sleep_jags <- jags.model(textConnection(sleep_model), 
    data = list(Y = sleep_study$diff_3),
    inits = list(.RNG.name = "base::Wichmann-Hill",
                 .RNG.seed = 1989))
การสร้างแบบจำลอง Bayesian ด้วย RJAGS

มาฝึกกันเถอะ!

การสร้างแบบจำลอง Bayesian ด้วย RJAGS

Preparing Video For Download...