Compute various point-estimates, such as the mean, the median or the MAP, to describe posterior distributions.
Usage
point_estimate(x, ...)
# S3 method for numeric
point_estimate(x, centrality = "all", dispersion = FALSE, threshold = 0.1, ...)
# S3 method for stanreg
point_estimate(
x,
centrality = "all",
dispersion = FALSE,
effects = c("fixed", "random", "all"),
component = c("location", "all", "conditional", "smooth_terms", "sigma",
"distributional", "auxiliary"),
parameters = NULL,
...
)
# S3 method for brmsfit
point_estimate(
x,
centrality = "all",
dispersion = FALSE,
effects = c("fixed", "random", "all"),
component = c("conditional", "zi", "zero_inflated", "all"),
parameters = NULL,
...
)
# S3 method for BFBayesFactor
point_estimate(x, centrality = "all", dispersion = FALSE, ...)
Arguments
- x
Vector representing a posterior distribution, or a data frame of such vectors. Can also be a Bayesian model. bayestestR supports a wide range of models (see, for example,
methods("hdi")
) and not all of those are documented in the 'Usage' section, because methods for other classes mostly resemble the arguments of the.numeric
or.data.frame
methods.- ...
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:
"median"
,"mean"
,"MAP"
or"all"
.- dispersion
Logical, if
TRUE
, computes indices of dispersion related to the estimate(s) (SD
andMAD
formean
andmedian
, respectively).- threshold
For
centrality = "trimmed"
(i.e. trimmed mean), indicates the fraction (0 to 0.5) of observations to be trimmed from each end of the vector before the mean is computed.- effects
Should results for fixed effects, random effects or both be returned? Only applies to mixed models. May be abbreviated.
- 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.
- parameters
Regular expression pattern that describes the parameters that should be returned. Meta-parameters (like
lp__
orprior_
) are filtered by default, so only parameters that typically appear in thesummary()
are returned. Useparameters
to select specific parameters for the output.
Note
There is also a plot()
-method implemented in the see-package.
References
Makowski, D., Ben-Shachar, M. S., Chen, S. H. A., \& 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)
point_estimate(rnorm(1000))
#> Point Estimate
#>
#> Median | Mean | MAP
#> --------------------
#> 0.05 | 0.03 | 0.14
point_estimate(rnorm(1000), centrality = "all", dispersion = TRUE)
#> Point Estimate
#>
#> Median | MAD | Mean | SD | MAP
#> ----------------------------------------
#> -0.04 | 0.96 | -4.90e-03 | 0.94 | -0.16
point_estimate(rnorm(1000), centrality = c("median", "MAP"))
#> Point Estimate
#>
#> Median | MAP
#> --------------
#> -0.04 | -0.17
df <- data.frame(replicate(4, rnorm(100)))
point_estimate(df, centrality = "all", dispersion = TRUE)
#> Point Estimate
#>
#> Parameter | Median | MAD | Mean | SD | MAP
#> ------------------------------------------------
#> X1 | -0.07 | 1.06 | -0.07 | 0.99 | -0.09
#> X2 | 0.06 | 0.98 | 0.09 | 0.97 | 0.02
#> X3 | 0.02 | 1.03 | -0.07 | 1.01 | -0.53
#> X4 | -0.21 | 0.84 | -0.12 | 0.90 | -0.42
point_estimate(df, centrality = c("median", "MAP"))
#> Point Estimate
#>
#> Parameter | Median | MAP
#> --------------------------
#> X1 | -0.07 | -0.09
#> X2 | 0.06 | 0.02
#> X3 | 0.02 | -0.53
#> X4 | -0.21 | -0.42
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"))
}