CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Bayesian Modeling with RJAGS

Afficher le cours

Instructions

  • Use jags.model() to COMPILE sleep_model and initialize 4 parallel chains. Store the output in a jags object named sleep_jags_multi.

  • SIMULATE a sample of 1,000 draws from the posterior model of m and s. Store this mcmc.list in sleep_sim_multi.

  • Check out the head() of sleep_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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# 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
Modifier et exécuter le code