For speed and illustration purposes, we will use 10 iterations, with no burn in period and taking every third sample. This leaves only 9 samples. We DO NOT recommend this setting. The recommended settings are 80000 iterations, with 10000 burn in period and taking every 35th sample. This is commented out and listed underneath the below R code.
We use this to evaluate the convergence of the model parameters. We should expect to see R-hat values of approximately 1.05. The plot function will give you a visual summary for each parameter monitored.
Using the ggplot2 and tidybayes R packages, we will check the trace plots to assess the convergence of individual parameters. We expect to see a ‘caterpillar’ like appearance of the chains over the iterations.
sample_draws <- tidybayes::tidy_draws(mod$JAGS$BUGSoutput$sims.matrix)
var <- sample_draws %>% dplyr::select(.chain, .iteration, .draw,`P[1,2,1,1]`) %>%
dplyr::mutate(chain = rep(1:2, each=mod$JAGS$BUGSoutput$n.keep)) %>%
dplyr::mutate(iteration = rep(1:mod$JAGS$BUGSoutput$n.keep, 2))
ggplot2::ggplot(data=var) +
ggplot2::geom_line(ggplot2::aes(x=iteration, y=`P[1,2,1,1]`, color=as.factor(chain)))