开始使用免费开始使用

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.

本练习是课程的一部分

Bayesian Modeling with RJAGS

查看课程

练习说明

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

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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
编辑并运行代码