The plot method for stapreg-objects provides a convenient interface to the MCMC module in the bayesplot package for plotting MCMC draws and diagnostics. It is also straightforward to use the functions from the bayesplot package directly rather than via the plot method. Examples of both methods of plotting are given below.

# S3 method for stapreg
plot(x, plotfun = "intervals", pars = NULL,
  regex_pars = NULL, ...)

Arguments

x

A fitted model object returned by one of the rstap modeling functions. See stapreg-objects.

plotfun

A character string naming the bayesplot MCMC function to use. The default is to call mcmc_intervals. plotfun can be specified either as the full name of a bayesplot plotting function (e.g. "mcmc_hist") or can be abbreviated to the part of the name following the "mcmc_" prefix (e.g. "hist"). To get the names of all available MCMC functions see available_mcmc.

pars

An optional character vector of parameter names.

regex_pars

An optional character vector of regular expressions to use for parameter selection. regex_pars can be used in place of pars or in addition to pars. Currently, all functions that accept a regex_pars argument ignore it for models fit using optimization.

...

Additional arguments to pass to plotfun for customizing the plot. These are described on the help pages for the individual plotting functions. For example, the arguments accepted for the default plotfun="intervals" can be found at mcmc_intervals.

Value

Either a ggplot object that can be further customized using the ggplot2 package, or an object created from multiple ggplot objects (e.g. a gtable object created by arrangeGrob).

References

Gabry, J., Simpson, D., Vehtari, A., Betancourt, M., and Gelman, A. (2018). Visualization in Bayesian workflow. Journal of the Royal Statistical Society Series A, accepted for publication. arXiv preprint: http://arxiv.org/abs/1709.01449.

See also

  • The vignettes in the bayesplot package for many examples.

  • MCMC-overview (bayesplot) for links to the documentation for all the available plotting functions.

  • color_scheme_set (bayesplot) to change the color scheme used for plotting.

  • pp_check for graphical posterior predictive checks.

Examples

if (FALSE) { # Not run for CRAN check speed fit_glm <- stap_glm(formula = y ~ sex + sap(Fast_Food), subject_data = homog_subject_data, distance_data = homog_distance_data, family = gaussian(link = 'identity'), subject_ID = 'subj_id', prior = normal(location = 0, scale = 5, autoscale = F), prior_intercept = normal(location = 25, scale = 5, autoscale = F), prior_stap = normal(location = 0, scale = 3, autoscale = F), prior_theta = log_normal(location = 1, scale = 1), prior_aux = cauchy(location = 0,scale = 5), max_distance = max(homog_distance_data$Distance), chains = CHAINS, iter = ITER, refresh = -1,verbose = F) plot(fit_glm, plotfun = 'mcmc_hist', pars = "Fast_Food") }