# p_map: Bayesian p-value based on the density at the Maximum A... In DominiqueMakowski/bayestestR: Understand and Describe Bayesian Models and Posterior Distributions

## Description

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 0 divided by the density at the Maximum A Posteriori (MAP).

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26``` ```p_map(x, precision = 2^10, method = "kernel", ...) p_pointnull(x, precision = 2^10, method = "kernel", ...) ## S3 method for class 'stanreg' p_map( x, precision = 2^10, method = "kernel", effects = c("fixed", "random", "all"), component = c("location", "all", "conditional", "smooth_terms", "sigma", "distributional", "auxiliary"), parameters = NULL, ... ) ## S3 method for class 'brmsfit' p_map( x, precision = 2^10, method = "kernel", effects = c("fixed", "random", "all"), component = c("conditional", "zi", "zero_inflated", "all"), parameters = NULL, ... ) ```

## Arguments

 `x` Vector representing a posterior distribution, or a data frame of such vectors. Can also be a Bayesian model (`stanreg`, `brmsfit`, `MCMCglmm`, `mcmc` or `bcplm`) or a `BayesFactor` model. `precision` Number of points of density data. See the `n` parameter in `density`. `method` Density estimation method. Can be `"kernel"` (default), `"logspline"` or `"KernSmooth"`. `...` Currently not used. `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__` 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.

## Details

Note that this method is sensitive to the density estimation `method` (see the section in the examples below).

#### Strengths and Limitations

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.

## References

• 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. doi: 10.3389/fpsyg.2019.02767

• Mills, J. A. (2018). Objective Bayesian Precise Hypothesis Testing. University of Cincinnati.

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41``` ```library(bayestestR) p_map(rnorm(1000, 0, 1)) p_map(rnorm(1000, 10, 1)) ## Not run: library(rstanarm) model <- stan_glm(mpg ~ wt + gear, data = mtcars, chains = 2, iter = 200, refresh = 0) p_map(model) library(emmeans) p_map(emtrends(model, ~1, "wt")) library(brms) model <- brms::brm(mpg ~ wt + cyl, data = mtcars) p_map(model) library(BayesFactor) bf <- 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" = p_map(x, method = "kernel"), "KernSmooth" = p_map(x, method = "KernSmooth"), "logspline" = 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")]) ## End(Not run) ```