Compute indices relevant to describe and characterize the posterior distributions.

describe_posterior(
  posteriors,
  centrality = "median",
  dispersion = FALSE,
  ci = 0.89,
  ci_method = "hdi",
  test = c("p_direction", "rope"),
  rope_range = "default",
  rope_ci = 0.89,
  ...
)

# S3 method for numeric
describe_posterior(
  posteriors,
  centrality = "median",
  dispersion = FALSE,
  ci = 0.89,
  ci_method = "hdi",
  test = c("p_direction", "rope"),
  rope_range = "default",
  rope_ci = 0.89,
  bf_prior = NULL,
  BF = 1,
  ...
)

# S3 method for stanreg
describe_posterior(
  posteriors,
  centrality = "median",
  dispersion = FALSE,
  ci = 0.89,
  ci_method = "hdi",
  test = c("p_direction", "rope"),
  rope_range = "default",
  rope_ci = 0.89,
  bf_prior = NULL,
  diagnostic = c("ESS", "Rhat"),
  priors = FALSE,
  effects = c("fixed", "random", "all"),
  parameters = NULL,
  BF = 1,
  ...
)

# S3 method for stanmvreg
describe_posterior(
  posteriors,
  centrality = "median",
  dispersion = FALSE,
  ci = 0.89,
  ci_method = "hdi",
  test = "p_direction",
  rope_range = "default",
  rope_ci = 0.89,
  bf_prior = NULL,
  diagnostic = c("ESS", "Rhat"),
  priors = FALSE,
  effects = c("fixed", "random", "all"),
  parameters = NULL,
  ...
)

# S3 method for MCMCglmm
describe_posterior(
  posteriors,
  centrality = "median",
  dispersion = FALSE,
  ci = 0.89,
  ci_method = "hdi",
  test = c("p_direction", "rope"),
  rope_range = "default",
  rope_ci = 0.89,
  diagnostic = "ESS",
  parameters = NULL,
  ...
)

# S3 method for brmsfit
describe_posterior(
  posteriors,
  centrality = "median",
  dispersion = FALSE,
  ci = 0.89,
  ci_method = "hdi",
  test = c("p_direction", "rope"),
  rope_range = "default",
  rope_ci = 0.89,
  bf_prior = NULL,
  diagnostic = c("ESS", "Rhat"),
  effects = c("fixed", "random", "all"),
  component = c("conditional", "zi", "zero_inflated", "all"),
  parameters = NULL,
  BF = 1,
  ...
)

# S3 method for BFBayesFactor
describe_posterior(
  posteriors,
  centrality = "median",
  dispersion = FALSE,
  ci = 0.89,
  ci_method = "hdi",
  test = c("p_direction", "rope", "bf"),
  rope_range = "default",
  rope_ci = 0.89,
  priors = TRUE,
  ...
)

Arguments

posteriors

A vector, data frame or model of posterior draws.

centrality

The point-estimates (centrality indices) to compute. Character (vector) or list with one or more of these options: "median", "mean", "MAP" or "all".

dispersion

Logical, if TRUE, computes indices of dispersion related to the estimate(s) (SD and MAD for mean and median, respectively).

ci

Value or vector of probability of the CI (between 0 and 1) to be estimated. Default to .89 (89%) for Bayesian models and .95 (95%) for frequentist models.

ci_method

The type of index used for Credible Interval. Can be "HDI" (default, see hdi), "ETI" (see eti) or "SI" (see si).

test

The indices of effect existence to compute. Character (vector) or list with one or more of these options: "p_direction" (or "pd"), "rope", "p_map", "equivalence_test" (or "equitest"), "bayesfactor" (or "bf") or "all" to compute all tests. For each "test", the corresponding bayestestR function is called (e.g. rope or p_direction) and its results included in the summary output.

rope_range

ROPE's lower and higher bounds. Should be a list of two values (e.g., c(-0.1, 0.1)) or "default". If "default", the bounds are set to x +- 0.1*SD(response).

rope_ci

The Credible Interval (CI) probability, corresponding to the proportion of HDI, to use for the percentage in ROPE.

...

Additional arguments to be passed to or from methods.

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.

diagnostic

Diagnostic metrics to compute. Character (vector) or list with one or more of these options: "ESS", "Rhat", "MCSE" or "all".

priors

Add the prior used for each parameter.

effects

Should results for fixed effects, random effects or both be returned? Only applies to mixed models. May be abbreviated.

parameters

Regular expression pattern that describes the parameters that should be returned. Meta-parameters (like lp__ or prior_) are filtered by default, so only parameters that typically appear in the summary() are returned. Use parameters to select specific parameters for the output.

component

Should results for all parameters, parameters for the conditional model or the zero-inflated part of the model be returned? May be abbreviated. Only applies to brms-models.

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

References

Examples

library(bayestestR) x <- rnorm(1000) describe_posterior(x)
#> # Description of Posterior Distributions #> #> Parameter | Median | 89% CI | pd | 89% ROPE | % in ROPE #> --------------------------------------------------------------------------- #> Posterior | 0.026 | [-1.592, 1.570] | 51.30% | [-0.100, 0.100] | 8.642 #>
describe_posterior(x, centrality = "all", dispersion = TRUE, test = "all")
#> Warning: Prior not specified! Please specify a prior (in the form 'prior = distribution_normal(1000, 0, 1)') to get meaningful results.
#> # Description of Posterior Distributions #> #> Parameter | Median | MAD | Mean | SD | MAP | 89% CI | p_map | pd | p_ROPE | ps | 89% ROPE | % in ROPE | ROPE_Equivalence | BF #> ------------------------------------------------------------------------------------------------------------------------------------------------------------- #> Posterior | 0.026 | 0.970 | 0.012 | 0.984 | -0.024 | [-1.592, 1.570] | 1.000 | 51.30% | 0.077 | 0.474 | [-0.100, 0.100] | 8.642 | Undecided | 1 #>
describe_posterior(x, ci = c(0.80, 0.90))
#> # Description of Posterior Distributions #> #> Parameter | Median | CI | pd | 89% ROPE | % in ROPE #> ---------------------------------------------------------------------------------- #> Posterior | 0.026 | 80% CI [-1.256, 1.170] | 51.30% | [-0.100, 0.100] | 8.642 #> Posterior | 0.026 | 90% CI [-1.611, 1.627] | 51.30% | [-0.100, 0.100] | 8.642 #>
df <- data.frame(replicate(4, rnorm(100))) describe_posterior(df)
#> # Description of Posterior Distributions #> #> Parameter | Median | 89% CI | pd | 89% ROPE | % in ROPE #> --------------------------------------------------------------------------- #> X1 | 0.085 | [-1.268, 1.996] | 52.00% | [-0.100, 0.100] | 6.667 #> X2 | -0.009 | [-2.154, 1.161] | 50.00% | [-0.100, 0.100] | 13.333 #> X3 | -0.014 | [-1.185, 2.008] | 51.00% | [-0.100, 0.100] | 4.444 #> X4 | 0.082 | [-1.575, 1.621] | 55.00% | [-0.100, 0.100] | 15.556 #>
describe_posterior(df, centrality = "all", dispersion = TRUE, test = "all")
#> Warning: Prior not specified! Please specify priors (with column order matching 'posterior') to get meaningful results.
#> # Description of Posterior Distributions #> #> Parameter | Median | MAD | Mean | SD | MAP | 89% CI | p_MAP | pd | p_ROPE | ps | 89% ROPE | % in ROPE | ROPE_Equivalence | BF #> -------------------------------------------------------------------------------------------------------------------------------------------------------------- #> X1 | 0.085 | 0.946 | 0.033 | 1.007 | 0.514 | [-1.268, 1.996] | 0.868 | 52.00% | 0.060 | 0.500 | [-0.100, 0.100] | 6.667 | Undecided | 1 #> X2 | -0.009 | 1.038 | -0.047 | 1.043 | -0.183 | [-2.154, 1.161] | 0.991 | 50.00% | 0.120 | 0.460 | [-0.100, 0.100] | 13.333 | Undecided | 1 #> X3 | -0.014 | 1.174 | 0.152 | 1.083 | -0.439 | [-1.185, 2.008] | 0.934 | 51.00% | 0.040 | 0.490 | [-0.100, 0.100] | 4.444 | Undecided | 1 #> X4 | 0.082 | 0.730 | 0.022 | 0.960 | 0.162 | [-1.575, 1.621] | 0.959 | 55.00% | 0.140 | 0.490 | [-0.100, 0.100] | 15.556 | Undecided | 1 #>
describe_posterior(df, ci = c(0.80, 0.90))
#> # Description of Posterior Distributions #> #> Parameter | Median | CI | pd | 89% ROPE | % in ROPE #> ---------------------------------------------------------------------------------- #> X1 | 0.085 | 80% CI [-0.934, 1.451] | 52.00% | [-0.100, 0.100] | 6.667 #> X1 | 0.085 | 90% CI [-1.627, 1.813] | 52.00% | [-0.100, 0.100] | 6.667 #> X2 | -0.009 | 80% CI [-1.208, 1.161] | 50.00% | [-0.100, 0.100] | 13.333 #> X2 | -0.009 | 90% CI [-1.703, 1.730] | 50.00% | [-0.100, 0.100] | 13.333 #> X3 | -0.014 | 80% CI [-1.228, 1.354] | 51.00% | [-0.100, 0.100] | 4.444 #> X3 | -0.014 | 90% CI [-1.228, 2.008] | 51.00% | [-0.100, 0.100] | 4.444 #> X4 | 0.082 | 80% CI [-0.771, 1.621] | 55.00% | [-0.100, 0.100] | 15.556 #> X4 | 0.082 | 90% CI [-1.630, 1.621] | 55.00% | [-0.100, 0.100] | 15.556 #>
if (FALSE) { # rstanarm models # ----------------------------------------------- if (require("rstanarm") && require("emmeans")) { model <- 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)) # emmeans estimates # ----------------------------------------------- describe_posterior(emtrends(model, ~1, "wt")) } # brms models # ----------------------------------------------- if (require("brms")) { model <- brms::brm(mpg ~ wt + cyl, data = mtcars) describe_posterior(model) describe_posterior(model, centrality = "all", dispersion = TRUE, test = "all") describe_posterior(model, ci = c(0.80, 0.90)) } # BayesFactor objects # ----------------------------------------------- if (require("BayesFactor")) { bf <- 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)) } }