p_map | R Documentation |
Compute a Bayesian equivalent of the p-value, related to the odds that a parameter (described by its posterior distribution) has against the null hypothesis (h0) using Mills' (2014, 2017) Objective Bayesian Hypothesis Testing framework. It corresponds to the density value at the null (e.g., 0) divided by the density at the Maximum A Posteriori (MAP).
p_map(x, ...)
p_pointnull(x, ...)
## S3 method for class 'numeric'
p_map(x, null = 0, precision = 2^10, method = "kernel", ...)
## S3 method for class 'get_predicted'
p_map(
x,
null = 0,
precision = 2^10,
method = "kernel",
use_iterations = FALSE,
verbose = TRUE,
...
)
## S3 method for class 'data.frame'
p_map(x, null = 0, precision = 2^10, method = "kernel", rvar_col = NULL, ...)
## S3 method for class 'brmsfit'
p_map(
x,
null = 0,
precision = 2^10,
method = "kernel",
effects = "fixed",
component = "conditional",
parameters = NULL,
...
)
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. |
null |
The value considered as a "null" effect. Traditionally 0, but could also be 1 in the case of ratios of change (OR, IRR, ...). |
precision |
Number of points of density data. See the |
method |
Density estimation method. Can be |
use_iterations |
Logical, if |
verbose |
Toggle off warnings. |
rvar_col |
A single character - the name of an |
effects |
Should results for fixed effects ( |
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 |
Note that this method is sensitive to the density estimation method
(see the section in the examples below).
Strengths: Straightforward computation. Objective property of the posterior distribution.
Limitations: Limited information favoring the null hypothesis. Relates on density approximation. Indirect relationship between mathematical definition and interpretation. Only suitable for weak / very diffused priors.
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 as conditional
,
zero_inflated
, or smooth_terms
(everything that are fixed or random
effects - depending on the effects
argument - but no auxiliary
parameters).
"distributional"
(or "auxiliary"
): components like sigma
,
dispersion
, beta
or precision
(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
.
Makowski D, Ben-Shachar MS, Chen SHA, Lüdecke D (2019) Indices of Effect Existence and Significance in the Bayesian Framework. Frontiers in Psychology 2019;10:2767. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.3389/fpsyg.2019.02767")}
Mills, J. A. (2018). Objective Bayesian Precise Hypothesis Testing. University of Cincinnati.
library(bayestestR)
p_map(rnorm(1000, 0, 1))
p_map(rnorm(1000, 10, 1))
model <- suppressWarnings(
rstanarm::stan_glm(mpg ~ wt + gear, data = mtcars, chains = 2, iter = 200, refresh = 0)
)
p_map(model)
p_map(suppressWarnings(
emmeans::emtrends(model, ~1, "wt", data = mtcars)
))
model <- brms::brm(mpg ~ wt + cyl, data = mtcars)
p_map(model)
bf <- BayesFactor::ttestBF(x = rnorm(100, 1, 1))
p_map(bf)
# ---------------------------------------
# Robustness to density estimation method
set.seed(333)
data <- data.frame()
for (iteration in 1:250) {
x <- rnorm(1000, 1, 1)
result <- data.frame(
Kernel = as.numeric(p_map(x, method = "kernel")),
KernSmooth = as.numeric(p_map(x, method = "KernSmooth")),
logspline = as.numeric(p_map(x, method = "logspline"))
)
data <- rbind(data, result)
}
data$KernSmooth <- data$Kernel - data$KernSmooth
data$logspline <- data$Kernel - data$logspline
summary(data$KernSmooth)
summary(data$logspline)
boxplot(data[c("KernSmooth", "logspline")])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.