Get startedGet started for free

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.

This exercise is part of the course

Bayesian Modeling with RJAGS

View Course

Exercise 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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
Edit and Run Code