map_estimate {bayestestR} | R Documentation |
Maximum A Posteriori probability estimate (MAP)
Description
Find the Highest Maximum A Posteriori probability estimate (MAP) of a
posterior, i.e., the value associated with the highest probability density
(the "peak" of the posterior distribution). In other words, it is an estimation
of the mode for continuous parameters. Note that this function relies on
estimate_density()
, which by default uses a different smoothing bandwidth
("SJ"
) compared to the legacy default implemented the base R density()
function ("nrd0"
).
Usage
map_estimate(x, ...)
## S3 method for class 'numeric'
map_estimate(x, precision = 2^10, method = "kernel", verbose = TRUE, ...)
## S3 method for class 'brmsfit'
map_estimate(
x,
precision = 2^10,
method = "kernel",
effects = "fixed",
component = "conditional",
parameters = NULL,
verbose = TRUE,
...
)
## S3 method for class 'data.frame'
map_estimate(
x,
precision = 2^10,
method = "kernel",
rvar_col = NULL,
verbose = TRUE,
...
)
## S3 method for class 'get_predicted'
map_estimate(
x,
precision = 2^10,
method = "kernel",
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, |
... |
Currently not used. |
precision |
Number of points of density data. See the |
method |
Density estimation method. Can be |
verbose |
Toggle off warnings. |
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 |
rvar_col |
A single character - the name of an |
use_iterations |
Logical, if |
Value
A numeric value if x
is a vector. If x
is a model-object,
returns a data frame with following columns:
-
Parameter
: The model parameter(s), ifx
is a model-object. Ifx
is a vector, this column is missing. -
MAP_Estimate
: The MAP estimate for the posterior or each model parameter.
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
.
Examples
library(bayestestR)
posterior <- rnorm(10000)
map_estimate(posterior)
plot(density(posterior))
abline(v = as.numeric(map_estimate(posterior)), col = "red")
model <- rstanarm::stan_glm(mpg ~ wt + cyl, data = mtcars)
map_estimate(model)
model <- brms::brm(mpg ~ wt + cyl, data = mtcars)
map_estimate(model)