Learn R Programming

JointAI (version 0.1.0)

densplot: Plot posterior density from JointAI model

Description

Plots a set of densities (per MC chain and coefficient) from the MCMC sample of an object of class JointAI

Usage

densplot(object, ...)

# S3 method for JointAI densplot(object, start = NULL, end = NULL, thin = NULL, subset = "main", vlines = NULL, nrow = NULL, ncol = NULL, ...)

Arguments

object

object inheriting from class JointAI

...

additional parameters passed to plot

start

the first iteration of interest (see window.mcmc)

end

the last iteration of interest (see window.mcmc)

thin

thinning interval (see window.mcmc)

subset

subset of monitored parameters (columns in the MCMC sample). Can be specified as a numeric vector of columns, a vector of column names, as subset = "main" or NULL. If NULL, all monitored nodes will be plotted. subset = "main" (default) the main parameters of the analysis model will be plotted (regression coefficients/fixed effects, and, if available, standard deviation of the residual and random effects covariance matrix).

vlines

list, where each element is a named list of parameters that can be passed to abline to create vertical lines. Each of the list elements needs to contain at least v = <x location>, where <x location> is a vector of the same length as the number of plots (see examples).

nrow

optional; number of rows in the plotting layout (determined automatically if not specified)

ncol

optional; number of columns in the plotting layout (determined automatically if not specified)

Examples

Run this code
# NOT RUN {
mod <- lm_imp(y ~ C1 + C2 + M2, data = wideDF, n.iter = 100)

# densplot without vertical lines
densplot(mod)

# use vlines to mark zero
densplot(mod, col = c("darkred", "darkblue", "darkgreen"),
         vlines = list(list(v = rep(0, nrow(summary(mod)$stats)),
                            col = grey(0.8))))

# use vlines to visualize the posterior mean and 2.5% and 97.5% quantiles
densplot(mod, vlines = list(list(v = summary(mod)$stats[, "Mean"], lty = 1, lwd = 2),
                            list(v = summary(mod)$stats[, "2.5%"], lty = 2),
                            list(v = summary(mod)$stats[, "97.5%"], lty = 2)))

# }

Run the code above in your browser using DataLab