Session Ready
Exercise

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.

Instructions
100 XP
  • Check out the head() of the sleep_sim list object.

  • The first sleep_sim list item contains the \(m\) and \(s\) chains. Store these in a data frame named sleep_chains. Include a variable iter that records the corresponding iteration number, 1:10000, for each chain element.

  • Check out the first 6 rows of sleep_chains.