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

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 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 stanfit
rhat(object, pars = NULL, ...)

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

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

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

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.

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.

See also

Examples

library(rstanarm) fit <- stan_glm(mpg ~ wt, data = mtcars, refresh = 0) np <- nuts_params(fit) head(np)
#> Iteration Parameter Value Chain #> 1 1 accept_stat__ 0.7959114 1 #> 2 2 accept_stat__ 0.9530362 1 #> 3 3 accept_stat__ 0.9324149 1 #> 4 4 accept_stat__ 0.9940184 1 #> 5 5 accept_stat__ 0.9783435 1 #> 6 6 accept_stat__ 0.9573124 1
tail(np)
#> Iteration Parameter Value Chain #> 23995 995 energy__ 93.36461 4 #> 23996 996 energy__ 89.54952 4 #> 23997 997 energy__ 88.68174 4 #> 23998 998 energy__ 90.49492 4 #> 23999 999 energy__ 89.65802 4 #> 24000 1000 energy__ 88.86220 4
lp <- log_posterior(fit) head(lp)
#> Iteration Value Chain #> 1 1 -88.12764 1 #> 2 2 -88.74532 1 #> 3 3 -91.04726 1 #> 4 4 -90.13570 1 #> 5 5 -88.06601 1 #> 6 6 -88.77880 1
tail(lp)
#> Iteration Value Chain #> 3995 995 -87.72254 4 #> 3996 996 -88.32615 4 #> 3997 997 -87.69828 4 #> 3998 998 -88.24352 4 #> 3999 999 -88.42873 4 #> 4000 1000 -88.70642 4