point_estimate {bayestestR} | R Documentation |
Point-estimates of posterior distributions
Description
Compute various point-estimates, such as the mean, the median or the MAP, to describe posterior distributions.
Usage
point_estimate(x, ...)
## S3 method for class 'numeric'
point_estimate(x, centrality = "all", dispersion = FALSE, threshold = 0.1, ...)
## S3 method for class 'data.frame'
point_estimate(
x,
centrality = "all",
dispersion = FALSE,
threshold = 0.1,
rvar_col = NULL,
...
)
## S3 method for class 'brmsfit'
point_estimate(
x,
centrality = "all",
dispersion = FALSE,
effects = "fixed",
component = "conditional",
parameters = NULL,
...
)
## S3 method for class 'get_predicted'
point_estimate(
x,
centrality = "all",
dispersion = FALSE,
use_iterations = FALSE,
verbose = TRUE,
...
)
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, |
... |
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 |
threshold |
For |
rvar_col |
A single character - the name of an |
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 |
use_iterations |
Logical, if |
verbose |
Toggle off warnings. |
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
.
Note
There is also a plot()
-method implemented in the see-package.
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)
point_estimate(rnorm(1000))
point_estimate(rnorm(1000), centrality = "all", dispersion = TRUE)
point_estimate(rnorm(1000), centrality = c("median", "MAP"))
df <- data.frame(replicate(4, rnorm(100)))
point_estimate(df, centrality = "all", dispersion = TRUE)
point_estimate(df, centrality = c("median", "MAP"))
# rstanarm models
# -----------------------------------------------
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
# -----------------------------------------------
point_estimate(
emmeans::emtrends(model, ~1, "wt", data = mtcars),
centrality = c("median", "MAP")
)
# brms models
# -----------------------------------------------
model <- brms::brm(mpg ~ wt + cyl, data = mtcars)
point_estimate(model, centrality = "all", dispersion = TRUE)
point_estimate(model, centrality = c("median", "MAP"))
# BayesFactor objects
# -----------------------------------------------
bf <- BayesFactor::ttestBF(x = rnorm(100, 1, 1))
point_estimate(bf, centrality = "all", dispersion = TRUE)
point_estimate(bf, centrality = c("median", "MAP"))