plot_pars: Plot individual parameters

Description Usage Arguments Details Value Author(s) Examples

View source: R/plot.R

Description

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

Usage

1
2
3
4
5
6
7
8
plot_pars(
  fit,
  pars = "population",
  regex_pars = character(0),
  type = "combo",
  ncol = 1,
  prior = FALSE
)

Arguments

fit

An mcpfit object.

pars

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".

regex_pars

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.

type

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".

ncol

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

prior

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

Details

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.

Value

A ggplot2 object.

Author(s)

Jonas Kristoffer Lindeløv jonas@lindeloev.dk

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Typical usage. ex_fit is an mcpfit object.
plot_pars(ex_fit)

## Not run: 
# 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)
library(ggplot2)
plot_pars(ex_fit, type = c("trace", "dens_overlay")) * theme_bw(10)

## End(Not run)

mcp documentation built on Aug. 3, 2020, 5:07 p.m.