Plot many types of plots of parameter estimates. See examples for typical use cases.

  pars = "population",
  regex_pars = character(0),
  type = "combo",
  ncol = 1,
  prior = FALSE



An mcpfit object.


Character vector. One of:

  • Vector of parameter names.

  • "population" (default): plots all population parameters.

  • "varying": plots all varying effects. To plot a particular varying effect, use regex_pars = "^name".


Vector of regular expressions. This will typically just be the beginning of the parameter name(s), i.e., "^cp_" plots all change points, "^my_varying" plots all levels of a particular varying effect, and "^cp_|^my_varying" plots both.


String or vector of strings. Calls bayesplot::mcmc_>>type<<(). Common calls are "combo", "trace", and "dens_overlay". Current options include 'acf', 'acf_bar', 'areas', 'areas_ridges', 'combo', 'dens', 'dens_chains', 'dens_overlay', 'hist', 'intervals', 'rank_hist', 'rank_overlay', 'trace', 'trace_highlight', and 'violin".


Number of columns in plot. This is useful when you have many parameters and only one plot type.


TRUE/FALSE. Plot using prior samples? Useful for mcp(..., sample = "both")


A ggplot2 object.


For other type, it calls bayesplot::mcmc_type(). Use these directly on fit$mcmc_post or fit$mcmc_prior if you want finer control of plotting, e.g., bayesplot::mcmc_dens(fit$mcmc_post). There are also a number of useful plots in the coda package, i.e., coda::gelman.plot(fit$mcmc_post) and coda::crosscorr.plot(fit$mcmc_post)

In any case, if you see a few erratic lines or parameter estimates, this is a sign that you may want to increase argument 'adapt' and 'iter' in mcp.


# Typical usage. ex_fit is an mcpfit object.

if (FALSE) {
# More options
plot_pars(ex_fit, regex_pars = "^cp_")  # Plot only change points
plot_pars(ex_fit, pars = c("int_3", "time_3"))  # Plot these parameters
plot_pars(ex_fit, type = c("trace", "violin"))  # Combine plots
# Some plots only take pairs. hex is good to assess identifiability
plot_pars(ex_fit, type = "hex", pars = c("cp_1", "time_2"))

# Visualize the priors:
plot_pars(ex_fit, prior = TRUE)

# Useful for varying effects:
# plot_pars(my_fit, pars = "varying", ncol = 3)  # plot all varying effects
# plot_pars(my_fit, regex_pars = "my_varying", ncol = 3)  # plot all levels of a particular varying

# Customize multi-column ggplots using "*" instead of "+" (patchwork)
plot_pars(ex_fit, type = c("trace", "dens_overlay")) * theme_bw(10)