Storing Markov chains
Let \(m\) be the average change in reaction time after 3 days of sleep deprivation. In a previous exercise, you obtained an approximate sample of 10,000 draws from the posterior model of \(m\). You stored the resulting mcmc.list
object as sleep_sim
which is loaded in your workspace:
sleep_sim <- coda.samples(model = sleep_jags, variable.names = c("m", "s"), n.iter = 10000)
In fact, the sample of \(m\) values in sleep_sim
is a dependent Markov chain, the distribution of which converges to the posterior. You will examine the contents of sleep_sim
and, to have finer control over your analysis, store the contents in a data frame.
This exercise is part of the course
Bayesian Modeling with RJAGS
Exercise instructions
Check out the
head()
of thesleep_sim
list object.The first
sleep_sim
list item contains the \(m\) and \(s\) chains. Store these in a data frame namedsleep_chains
. Include a variableiter
that records the corresponding iteration number,1:10000
, for each chain element.Check out the first 6 rows of
sleep_chains
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Check out the head of sleep_sim
# Store the chains in a data frame
sleep_chains <- data.frame(___, iter = ___)
# Check out the head of sleep_chains