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

densplot(object, ...)

# S3 method for mcmc.list
densplot(object, start = NULL, end = NULL,
  thin = NULL, ...)

# S3 method for JointAI
densplot(object, start = NULL, end = NULL,
  thin = NULL, subset = c(analysis_main = TRUE), vlines = NULL,
  nrow = NULL, ncol = NULL, joined = FALSE, use_ggplot = FALSE,
  keep_aux = FALSE, warn = TRUE, mess = TRUE, ...)

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 parameters/variables/nodes (columns in the MCMC sample). Uses the same logic as the argument monitor_params in lm_imp, glm_imp, clm_imp, lme_imp, glme_imp, survreg_imp and coxph_imp.

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 and columns in the plot layout; automatically chosen if unspecified

ncol

optional number of rows and columns in the plot layout; automatically chosen if unspecified

joined

logical; should the chains be combined before plotting?

use_ggplot

logical; Should ggplot be used instead of the base graphics?

keep_aux

logical; Should constant effects of auxiliary variables be kept in the output?

warn

logical; should warnings be given? Default is TRUE. Note: this applies only to warnings given directly by JointAI.

mess

logical; should messages be given? Default is TRUE. Note: this applies only to messages given directly by JointAI.

See also

The vignette Parameter Selection contains some examples how to specify the argument subset.

Examples

# fit a JointAI object: mod <- lm_imp(y ~ C1 + C2 + M2, data = wideDF, n.iter = 100)
#> This is new software. Please report any bugs to the package maintainer.
# Example 1: basic densityplot densplot(mod)
# Example 2: 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))))
# Example 3: 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)))
# Example 4: ggplot version densplot(mod, use_ggplot = TRUE)
#> Registered S3 methods overwritten by 'ggplot2': #> method from #> [.quosures rlang #> c.quosures rlang #> print.quosures rlang
# Example 5: changing how the ggplot version looks (using standard ggplot syntax) library(ggplot2) densplot(mod, use_ggplot = TRUE) + xlab("value") + theme(legend.position = 'bottom') + scale_color_brewer(palette = 'Dark2', name = 'chain')