LoslegenKostenlos loslegen

Markov chain density plots

Whereas a trace plot captures a Markov chain's longitudinal behavior, a density plot illustrates the final distribution of the chain values. In turn, the density plot provides an approximation of the posterior model. You will construct and examine density plots of the \(m\) Markov chain below. The mcmc.list object sleep_sim and sleep_chains data frame are in your workspace:

sleep_sim <- coda.samples(model = sleep_jags, variable.names = c("m", "s"), n.iter = 10000)
sleep_chains <- data.frame(sleep_sim[[1]], iter = 1:10000)

Diese Übung ist Teil des Kurses

Bayesian Modeling with RJAGS

Kurs anzeigen

Anleitung zur Übung

  • Apply plot() to sleep_sim with trace = FALSE to construct density plots for the \(m\) and \(s\) chains.

  • Apply ggplot() to sleep_chains to re-construct a density plot of the \(m\) chain.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Use plot() to construct density plots of the m and s chains


# Use ggplot() to construct a density plot of the m chain
ggplot(___, aes(x = ___)) + 
    ___()
Code bearbeiten und ausführen