describe_posterior {bayestestR} | R Documentation |
Describe Posterior Distributions
Description
Compute indices relevant to describe and characterize the posterior distributions.
Usage
describe_posterior(posterior, ...)
## S3 method for class 'numeric'
describe_posterior(
posterior,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
keep_iterations = FALSE,
bf_prior = NULL,
BF = 1,
verbose = TRUE,
...
)
## S3 method for class 'data.frame'
describe_posterior(
posterior,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
keep_iterations = FALSE,
bf_prior = NULL,
BF = 1,
rvar_col = NULL,
verbose = TRUE,
...
)
## S3 method for class 'stanreg'
describe_posterior(
posterior,
centrality = "median",
dispersion = FALSE,
ci = 0.95,
ci_method = "eti",
test = c("p_direction", "rope"),
rope_range = "default",
rope_ci = 0.95,
keep_iterations = FALSE,
bf_prior = NULL,
diagnostic = c("ESS", "Rhat"),
priors = FALSE,
effects = "fixed",
component = "location",
parameters = NULL,
BF = 1,
verbose = TRUE,
...
)
Arguments
posterior |
A vector, data frame or model of posterior draws.
bayestestR supports a wide range of models (see |
... |
Additional arguments to be passed to or from methods. |
centrality |
The point-estimates (centrality indices) to compute. Character
(vector) or list with one or more of these options: |
dispersion |
Logical, if |
ci |
Value or vector of probability of the CI (between 0 and 1)
to be estimated. Default to |
ci_method |
The type of index used for Credible Interval. Can be |
test |
The indices of effect existence to compute. Character (vector) or
list with one or more of these options: |
rope_range |
ROPE's lower and higher bounds. Should be a vector of two
values (e.g., |
rope_ci |
The Credible Interval (CI) probability, corresponding to the proportion of HDI, to use for the percentage in ROPE. |
keep_iterations |
If |
bf_prior |
Distribution representing a prior for the computation of Bayes factors / SI. Used if the input is a posterior, otherwise (in the case of models) ignored. |
BF |
The amount of support required to be included in the support interval. |
verbose |
Toggle off warnings. |
rvar_col |
A single character - the name of an |
diagnostic |
Diagnostic metrics to compute. Character (vector) or list
with one or more of these options: |
priors |
Add the prior used for each parameter. |
effects |
Should variables for fixed effects ( For models of from packages brms or rstanarm there are additional options:
|
component |
Which type of parameters to return, such as parameters for the conditional model, the zero-inflated part of the model, the dispersion term, etc. See details in section Model Components. May be abbreviated. Note that the conditional component also refers to the count or mean component - names may differ, depending on the modeling package. There are three convenient shortcuts (not applicable to all model classes):
|
parameters |
Regular expression pattern that describes the parameters
that should be returned. Meta-parameters (like |
Details
One or more components of point estimates (like posterior mean or median),
intervals and tests can be omitted from the summary output by setting the
related argument to NULL
. For example, test = NULL
and centrality = NULL
would only return the HDI (or CI).
Model components
Possible values for the component
argument depend on the model class.
Following are valid options:
-
"all"
: returns all model components, applies to all models, but will only have an effect for models with more than just the conditional model component. -
"conditional"
: only returns the conditional component, i.e. "fixed effects" terms from the model. Will only have an effect for models with more than just the conditional model component. -
"smooth_terms"
: returns smooth terms, only applies to GAMs (or similar models that may contain smooth terms). -
"zero_inflated"
(or"zi"
): returns the zero-inflation component. -
"location"
: returns location parameters such asconditional
,zero_inflated
, orsmooth_terms
(everything that are fixed or random effects - depending on theeffects
argument - but no auxiliary parameters). -
"distributional"
(or"auxiliary"
): components likesigma
,dispersion
,beta
orprecision
(and other auxiliary parameters) are returned.
For models of class brmsfit
(package brms), even more options are
possible for the component
argument, which are not all documented in detail
here. See also ?insight::find_parameters
.
References
Makowski, D., Ben-Shachar, M. S., Chen, S. H. A., and Lüdecke, D. (2019). Indices of Effect Existence and Significance in the Bayesian Framework. Frontiers in Psychology 2019;10:2767. doi:10.3389/fpsyg.2019.02767
Examples
library(bayestestR)
x <- rnorm(1000)
describe_posterior(x, verbose = FALSE)
describe_posterior(x,
centrality = "all",
dispersion = TRUE,
test = "all",
verbose = FALSE
)
describe_posterior(x, ci = c(0.80, 0.90), verbose = FALSE)
df <- data.frame(replicate(4, rnorm(100)))
describe_posterior(df, verbose = FALSE)
describe_posterior(
df,
centrality = "all",
dispersion = TRUE,
test = "all",
verbose = FALSE
)
describe_posterior(df, ci = c(0.80, 0.90), verbose = FALSE)
df <- data.frame(replicate(4, rnorm(20)))
head(reshape_iterations(
describe_posterior(df, keep_iterations = TRUE, verbose = FALSE)
))
# rstanarm models
# -----------------------------------------------
model <- suppressWarnings(
rstanarm::stan_glm(
mpg ~ wt + gear,
data = mtcars, chains = 2, iter = 200,
refresh = 0
)
)
describe_posterior(model)
describe_posterior(model, centrality = "all", dispersion = TRUE, test = "all")
describe_posterior(model, ci = c(0.80, 0.90))
describe_posterior(model, rope_range = list(c(-10, 5), c(-0.2, 0.2), "default"))
# emmeans estimates
# -----------------------------------------------
describe_posterior(emmeans::emtrends(model, ~1, "wt"))
# BayesFactor objects
# -----------------------------------------------
bf <- BayesFactor::ttestBF(x = rnorm(100, 1, 1))
describe_posterior(bf)
describe_posterior(bf, centrality = "all", dispersion = TRUE, test = "all")
describe_posterior(bf, ci = c(0.80, 0.90))