Compute various point-estimates, such as the mean, the median or the MAP, to describe posterior distributions.

point_estimate(x, centrality = "median", dispersion = FALSE, ...)

# S3 method for stanreg
point_estimate(x, centrality = "median",
  dispersion = FALSE, effects = c("fixed", "random", "all"),
  parameters = NULL, ...)

# S3 method for brmsfit
point_estimate(x, centrality = "median",
  dispersion = FALSE, effects = c("fixed", "random", "all"),
  component = c("conditional", "zi", "zero_inflated", "all"),
  parameters = NULL, ...)

# S3 method for BFBayesFactor
point_estimate(x, centrality = "median",
  dispersion = FALSE, ...)

Arguments

x

Vector representing a posterior distribution. Can also be a stanreg, brmsfit or a BayesFactor model.

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

...

Additional arguments to be passed to or from methods.

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.

References

Vignette In-Depth 1: Comparison of Point-Estimates

Examples

library(bayestestR) point_estimate(rnorm(1000))
#> # Point Estimates #> #> Median #> 0.018 #>
point_estimate(rnorm(1000), centrality = "all", dispersion = TRUE)
#> # Point Estimates #> #> Median MAD Mean SD MAP #> 0.063 1 0.0092 1 0.19 #>
point_estimate(rnorm(1000), centrality = c("median", "MAP"))
#> # Point Estimates #> #> Median MAP #> -0.0084 -0.041 #>
df <- data.frame(replicate(4, rnorm(100))) point_estimate(df, centrality = "all", dispersion = TRUE)
#> # Point Estimates #> #> Parameter Median MAD Mean SD MAP #> X1 0.018 0.95 0.066 1.01 -0.046 #> X2 -0.022 0.97 -0.053 1.01 -0.058 #> X3 0.042 1.02 0.011 0.98 0.039 #> X4 0.140 0.84 0.070 1.02 0.215 #>
point_estimate(df, centrality = c("median", "MAP"))
#> # Point Estimates #> #> Parameter Median MAP #> X1 0.018 -0.046 #> X2 -0.022 -0.058 #> X3 0.042 0.039 #> X4 0.140 0.215 #>
if (FALSE) { # rstanarm models # ----------------------------------------------- library(rstanarm) model <- rstanarm::stan_glm(mpg ~ wt + cyl, data = mtcars) point_estimate(model, centrality = "all", dispersion = TRUE) point_estimate(model, centrality = c("median", "MAP")) # emmeans estimates # ----------------------------------------------- library(emmeans) point_estimate(emtrends(model, ~1, "wt"), centrality = c("median", "MAP")) # brms models # ----------------------------------------------- library(brms) model <- brms::brm(mpg ~ wt + cyl, data = mtcars) point_estimate(model, centrality = "all", dispersion = TRUE) point_estimate(model, centrality = c("median", "MAP")) # BayesFactor objects # ----------------------------------------------- library(BayesFactor) bf <- ttestBF(x = rnorm(100, 1, 1)) point_estimate(bf, centrality = "all", dispersion = TRUE) point_estimate(bf, centrality = c("median", "MAP")) }