Skip to contents

A Bayesian p-value (p) is here defined in terms of the quantile-based (1-p) * 100% credible interval (CRI) that just includes a threshold (Kery and Schaub 2011). By default a p-value of 0.05 indicates that the 95% CRI just includes the threshold value.Note that the function contains the sample-size correction \(p_{c} = p * n / (n + 1)\) to avoid p-values of 0. The function can still return p-values of 1.To use as a measure of certainty in the direction of the estimate (i.e., positive or negative), see probability_direction().For p-values converted to bits, see svalue().To convert MCMC objects to information, see directional_information().

Usage

pvalue(x, side = "both", threshold = 0, na_rm = FALSE)

Arguments

x

A numeric vector of MCMC values.

side

A character vector of length 1 indicating whether to calculate p-values for the left tail ("left"), right tail ("right"), or two-sided ("both"; default).

threshold

A number of the threshold value.

na_rm

A flag specifying whether to remove missing values.

Value

A number between 0 and 1. If x has NA values but na_rm is FALSE, returns NA_real.

References

Kery, M., and Schaub, M. 2011. Bayesian population analysis using WinBUGS: a hierarchical perspective. Academic Press, Boston. Available from https://www.vogelwarte.ch/en/research/population-biology/book-bpa/.

Examples

x <- rnorm(1e6, qnorm(0.05, lower.tail = TRUE))
pvalue(x) # should be 0.05 * 2
#> [1] 0.099858
pvalue(x, side = "left") # should be 0.95
#> [1] 0.950071
pvalue(x, side = "right") # should be 0.05
#> [1] 0.049929