Skip to contents

The probability of direction (PD) is the proportion of the (posterior) distribution above (right) or below (left) a threshold.

Usage

probability_direction(x, side = "median", threshold = 0, na_rm = FALSE)

Arguments

x

A numeric vector of MCMC values.

side

A character vector of length 1 indicating whether to calculate the directional probability for the left tail ("left"; x < threshold), or the right tail ("right"; x > threshold). Defaults to "median", which uses the side of the median of x via direction().

threshold

A number of the threshold value, which is excluded from the interval for the probability.

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.

Details

By default, the direction is based on the side of the median value, but it can be specified to measure support for specific hypotheses. A right-side PD of 0.9 indicates that the interval spanning from the threshold to infinity has a coverage of 90%. Can be used as a measure of certainty in the direction of the estimate (e.g., positive or negative when using a threshold of 0). NOTE: probability estimates of 0 or 1 are corrected towards 0.5 by adding or subtracting 1 / (length(x) + 1), where x is a vector of MCMC samples. Ideally, x should be large enough as to make the correction negligible.

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. Front. Psychol. 10: 2767. doi:10.3389/fpsyg.2019.02767 .

Examples

x <- rnorm(1e6, qnorm(0.05, lower.tail = TRUE))
probability_direction(x, side = "left")
#> [1] 0.949519
probability_direction(x, side = "right") # = 1 - probability_direction(x, side = "left")
#> [1] 0.050481
probability_direction(c(0, 0, 1), side = "right") # returns P(X >0) = 1/3 instead of P(X >= 0) = 1
#> [1] 0.3333333
probability_direction(c(1, 1), side = "right") # p = 1 - 1/(n+1)
#> [1] 0.6666667