p_to_bf: Convert p-values to (pseudo) Bayes Factors

View source: R/p_to_bf.R

p_to_bfR Documentation

Convert p-values to (pseudo) Bayes Factors

Description

Convert p-values to (pseudo) Bayes Factors. This transformation has been suggested by Aust, Pawel, and Wagenmakers (2026), but is based on a vast amount of assumptions. It might therefore be not reliable. Use at your own risks.

Usage

p_to_bf(x, ...)

## S3 method for class 'numeric'
p_to_bf(x, n_obs = NULL, log = FALSE, ...)

## Default S3 method:
p_to_bf(x, n_obs = NULL, log = FALSE, ...)

Arguments

x

A (frequentist) model object, or a (numeric) vector of p-values. p-values must come from a two-tailed z- or t-test or from an F- or a \chi^2-test with a single degree of freedom. p-values must not be corrected for multiple testing.

...

Arguments passed to parameters::p_value() if x is a model object.

n_obs

(Effective) number of observations. For mixed models this must be supplied and generally corresponds to the number of clusters. Either length 1, or same length as p.

log

Whether to return log Bayes Factors. Note: The print() method always shows BF - the "log_BF" column is only accessible from the returned data frame.

Value

A data frame with the p-values and pseudo-Bayes factors (against the null).

References

  • Aust, F., Pawel, S., & Wagenmakers, E.J. (2026). Extracting Bayesian Evidence from Frequentist p-Values. Preprint available on ArXiv: https://arxiv.org/abs/2607.12132

See Also

bic_to_bf() for approximate Bayes factors based on BICs.

Examples



# Compare to BIC-approximated and pseudo BF
# --------------------------------------------
m0 <- lm(mpg ~ 1, data = mtcars)
m1 <- lm(mpg ~ am, data = mtcars)
m2 <- lm(mpg ~ factor(cyl), data = mtcars)

# BIC-approximated BF, m1 against null model
bayesfactor_models(m1, denominator = m0)
# bic_to_bf(BIC(m1), denominator = BIC(m0)) # equivalent

# pseudo-BF based on p-values
p_to_bf(m1)[-1, ] # dropping intercept

# When using a p-value from an F/chisq-test with more than one degree of
# freedom, the pseudo-BF is not reliable:
bayesfactor_models(m2, denominator = m0)
p_to_bf(anova(m2), n_obs = nrow(mtcars))



# Mixed models
# ------------------

data("sleepstudy", package = "lme4")
mixed0 <- lmerTest::lmer(Reaction ~ 1 + (Days | Subject), data = sleepstudy)
mixed1 <- lmerTest::lmer(Reaction ~ Days + (Days | Subject), data = sleepstudy)

bayesfactor_models(mixed1, denominator = mixed0)

p_to_bf(
  mixed1,
  n_obs = nlevels(lme4::sleepstudy$Subject), # *effective* sample size here
  method = "S" # make sure to get the correct p-values for the fixed effects
)[-1, ] # dropping intercept


bayestestR documentation built on Oct. 16, 2026, 9:06 a.m.