Learn R Programming

bayesplot (version 1.11.1)

bayesplot-extractors: Extract quantities needed for plotting from model objects

Description

Generics and methods for extracting quantities needed for plotting from various types of model objects. Currently methods are provided for stanfit (rstan), CmdStanMCMC (cmdstanr), and stanreg (rstanarm) objects, but adding new methods should be relatively straightforward.

Usage

log_posterior(object, ...)

nuts_params(object, ...)

rhat(object, ...)

neff_ratio(object, ...)

# S3 method for stanfit log_posterior(object, inc_warmup = FALSE, ...)

# S3 method for stanreg log_posterior(object, inc_warmup = FALSE, ...)

# S3 method for CmdStanMCMC log_posterior(object, inc_warmup = FALSE, ...)

# S3 method for stanfit nuts_params(object, pars = NULL, inc_warmup = FALSE, ...)

# S3 method for stanreg nuts_params(object, pars = NULL, inc_warmup = FALSE, ...)

# S3 method for list nuts_params(object, pars = NULL, ...)

# S3 method for CmdStanMCMC nuts_params(object, pars = NULL, ...)

# S3 method for stanfit rhat(object, pars = NULL, ...)

# S3 method for stanreg rhat(object, pars = NULL, regex_pars = NULL, ...)

# S3 method for CmdStanMCMC rhat(object, pars = NULL, ...)

# S3 method for stanfit neff_ratio(object, pars = NULL, ...)

# S3 method for stanreg neff_ratio(object, pars = NULL, regex_pars = NULL, ...)

# S3 method for CmdStanMCMC neff_ratio(object, pars = NULL, ...)

Value

log_posterior()

log_posterior() methods return a molten data frame (see reshape2::melt()). The data frame should have columns "Iteration" (integer), "Chain" (integer), and "Value" (numeric). See Examples, below.

nuts_params()

nuts_params() methods return a molten data frame (see reshape2::melt()). The data frame should have columns "Parameter" (factor), "Iteration" (integer), "Chain" (integer), and "Value" (numeric). See Examples, below.

rhat(), neff_ratio()

Methods return (named) vectors.

Arguments

object

The object to use.

...

Arguments passed to individual methods.

inc_warmup

A logical scalar (defaulting to FALSE) indicating whether to include warmup draws, if applicable.

pars

An optional character vector of parameter names. For nuts_params() these will be NUTS sampler parameter names rather than model parameters. If pars is omitted all parameters are included.

regex_pars

An optional regular expression to use for parameter selection. Can be specified instead of pars or in addition to pars. When using pars for tidy parameter selection, the regex_pars argument is ignored since select helpers perform a similar function.

See Also

MCMC-nuts, MCMC-diagnostics

Examples

Run this code
if (FALSE) {
library(rstanarm)
fit <- stan_glm(mpg ~ wt, data = mtcars, refresh = 0)

np <- nuts_params(fit)
head(np)
tail(np)

lp <- log_posterior(fit)
head(lp)
tail(lp)
}

Run the code above in your browser using DataLab