Multiple chains
Trace plots help us diagnose the quality of a Markov chain simulation. A "good" Markov chain will exhibit stability as the chain length increases and consistency across repeated simulations, or multiple chains. You will use RJAGS
to run and construct trace plots for four parallel chains below. The defined sleep_model
is in your workspace.
Este exercício faz parte do curso
Bayesian Modeling with RJAGS
Instruções do exercício
Use
jags.model()
to COMPILEsleep_model
and initialize 4 parallel chains. Store the output in a jags object namedsleep_jags_multi
.SIMULATE a sample of 1,000 draws from the posterior model of
m
ands
. Store this mcmc.list insleep_sim_multi
.Check out the
head()
ofsleep_sim_multi
. Note the 4 list items containing the 4 parallel chains.Use
plot()
to construct trace plots for the multiple chains. Suppress the density plots.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# COMPILE the model
sleep_jags_multi <- jags.model(textConnection(sleep_model), data = list(Y = sleep_study$diff_3), ___)
# SIMULATE the posterior
sleep_sim_multi <- coda.samples(model = ___, variable.names = c("m", "s"), n.iter = ___)
# Check out the head of sleep_sim_multi
# Construct trace plots of the m and s chains