Papers
Topics
Authors
Recent
2000 character limit reached

bfpwr R Package for Bayes-Factor Functions

Updated 13 January 2026
  • The bfpwr R package is a tool that computes Bayes-factor functions, offering a parameterized, graphical alternative to fixed-threshold p-value methods.
  • It implements closed-form formulas for common test statistics (z, t, χ², F), eliminating arbitrary prior scaling and the need for numerical integrations.
  • The package maps standardized effect sizes to prior parameters, enabling reproducible evidence curves and facilitating meta-analytic aggregation in hypothesis testing.

Bayes-factor functions (BFFs) provide a parameterized, graphical approach for reporting the results of hypothesis tests, supplanting fixed-threshold p-value procedures. The bfpwr R package implements BFF methodology for the four most common inferential test statistics (z, t, χ², F), enabling closed-form computation of Bayes factors as a function of standardized effect size. This systematic approach eliminates the arbitrariness of prior scaling in classical Bayes-factor analyses and delivers interpretable evidence curves without numerical integration. The bfpwr package thus operationalizes the rigorous reporting of statistical evidence across scientific domains, as detailed by the BFF framework (Johnson et al., 2022).

1. Theoretical Basis of Bayes-Factor Functions

Traditional Bayes factors are ratios of marginal likelihoods under competing hypotheses: BF10=m1(data)/m0(data)BF_{10} = m_1(\text{data}) / m_0(\text{data}), with each mim_i reflecting a prior-averaged probability of the data. These factors depend on prior specification, notably the scale parameter τ2\tau^2 for the alternative hypothesis. BFFs generalize this by producing BF10(δ)BF_{10}(\delta)—a function of a single scalar δ\delta (typically standardized effect size ω\omega)—by setting the prior's mode on the noncentrality parameter λ\lambda to coincide with r(ω)r(\omega), a function of design and sample size. This creates a curve of BF10BF_{10} over meaningful ω\omega values, displaying the full spectrum of evidentiary support for H1H_1 versus H0H_0 and circumventing arbitrary prior choices.

2. Closed-Form Formulas for Common Test Statistics

For each test statistic, the BFF method assigns the null-model density as the central distribution and averages the corresponding noncentral distribution under H1H_1 over a prior for λ\lambda:

  • z-test: zN(0,1)z \sim N(0,1) under H0H_0, N(λ,1)N(\lambda,1) under H1H_1; λJ(0,τ2)\lambda \sim J(0,\tau^2), normal-moment prior.

BF10(z)(zτ2)=(τ2+1)3/2[1+τ2z2τ2+1]exp[τ2z22(τ2+1)]BF_{10}^{(z)}(z | \tau^2) = (\tau^2+1)^{-3/2} \left[1 + \frac{\tau^2 z^2}{\tau^2+1}\right] \exp\left[\frac{\tau^2 z^2}{2(\tau^2+1)}\right]

  • t-test (ν\nu d.f.): tT(ν,0)t \sim T(\nu,0) under H0H_0, T(ν,λ)T(\nu,\lambda) under H1H_1; λJ(0,τ2)\lambda \sim J(0,\tau^2). Let r=1+t2/νr = 1 + t^2/\nu, s=1+t2/[ν(1+τ2)]s = 1 + t^2/[\nu(1+\tau^2)], q=τ2(ν+1)/[ν(1+τ2)]q = \tau^2(\nu+1)/[\nu(1+\tau^2)].

BF10(t)(tτ2)=(τ2+1)3/2(r/s)(ν+1)/2[1+qt2/s]BF_{10}^{(t)}(t | \tau^2) = (\tau^2+1)^{-3/2} (r/s)^{(\nu+1)/2} [1 + q t^2/s]

  • χ2\chi^2-test (kk d.f.): hχk2h \sim \chi^2_k under H0H_0, χk2(λ)\chi^2_k(\lambda) under H1H_1; λGamma(k/2+1,\lambda \sim \text{Gamma}(k/2+1, rate =1/(2τ2))= 1/(2\tau^2)).

BF10(χ2)(hτ2)=(τ2+1)k/21[1+τ2hk(τ2+1)]exp[τ2h2(τ2+1)]BF_{10}^{(\chi^2)}(h | \tau^2) = (\tau^2+1)^{-k/2-1} \left[1 + \frac{\tau^2 h}{k(\tau^2+1)}\right] \exp\left[\frac{\tau^2 h}{2(\tau^2+1)}\right]

  • F-test (k,mk, m d.f.): fF(k,m;0)f \sim F(k,m;0) under H0H_0, F(k,m;λ)F(k,m;\lambda) under H1H_1; λGamma(k/2+1,\lambda \sim \text{Gamma}(k/2+1, rate =1/(2τ2))= 1/(2\tau^2)). Let v=m(1+τ2)v = m(1+\tau^2).

BF10(F)(fτ2)=(τ2+1)k/21[1+kfm1+kfv]k+m2[1+(k+m)τ2fv(1+kfv)]BF_{10}^{(F)}(f | \tau^2) = (\tau^2+1)^{-k/2-1} \left[\frac{1+\frac{k f}{m}}{1+\frac{k f}{v}}\right]^{\frac{k+m}{2}} \left[1 + \frac{(k+m) \tau^2 f}{v(1+\frac{k f}{v})} \right]

3. Mapping Effect Size to Prior Parameters

Prior modes are aligned with standardized effect size ω\omega via design-specific formulas, ensuring that the calculation of τ2\tau^2 reflects the scientific context:

  • z or one-sample t: λ=nω    τ2(ω)=nω2/2\lambda = \sqrt{n} \omega \implies \tau^2(\omega) = n\omega^2/2
  • two-sample z or t (n1n_1, n2n_2): λ=n1n2/(n1+n2)ω    τ2(ω)=(n1n2ω2)/[2(n1+n2)]\lambda = \sqrt{n_1 n_2/(n_1+n_2)}\omega \implies \tau^2(\omega) = (n_1 n_2 \omega^2)/[2(n_1+n_2)]
  • χ2\chi^2 on kk d.f.: λ2=nωω    τ2=nωω/k\lambda^2 = n \omega'\omega \implies \tau^2 = n \omega'\omega / k
  • F in ANOVA (kk groups, nn total): λ=nωω/2    τ2=nωω/(2k)\lambda = n \omega'\omega / 2 \implies \tau^2 = n \omega'\omega /(2k)

This systematic mapping, detailed in Table 1 of the source paper, standardizes prior settings across hypothesis tests, facilitating meta-analytic aggregation and cross-study comparison (Johnson et al., 2022).

4. Computational Workflow and Package Usage

The bfpwr package operationalizes BFF calculation through distinct functions for each test statistic:

Test Statistic Function Name Key Arguments
z bff_z z, n, omega
t bff_t t, nu, n, omega
χ² bff_chisq h, df, n, omega
F bff_f f, k, m, n, omega

Workflow:

  1. Compute τi2=τ2(ωi)\tau^2_i = \tau^2(\omega_i) for each effect size ωi\omega_i
  2. Plug observed statistic (z, t, h, f) and τi2\tau^2_i into closed-form formula
  3. Record pairs (ωi,BF10(x;τi2))(\omega_i, BF_{10}(x;\tau^2_i))
  4. Plot BF versus ω\omega (typically log-scale), visualizing regions by effect magnitude

No numerical integration is required; all formulas are algebraic. Plotting functions provide color-coded regions for effect magnitude and user-adjustable BF threshold lines (e.g., BF=1, 3, 10).

5. Interpretation, Reporting, and Meta-Analysis

BFF curves allow immediate visualization of support for H1H_1 across effect sizes, avoiding reliance on binary p-value thresholds. Key interpretive features include:

  • The peak of the BFF curve indicates the effect size most compatible with H1H_1
  • The crossing at BF=1 demarcates regions favoring H1H_1 (to the left) or H0H_0 (to the right)
  • The maximum BF and corresponding ωmax\omega_{max} succinctly summarize evidentiary strength

For meta-analysis, BFFs from multiple studies can be multiplied at common ω\omega grid points to form a "meta-BFF". This aggregation transparently displays collective evidence consistency and effect-size ranges supported across studies.

6. Practical Implementation and Guidance

The bfpwr R package recommends eschewing "p<0.05" as the sole summary. Instead, users are directed to:

  • Compute and plot BF10(ω)BF_{10}(\omega) over the effect-size grid
  • Report the maximum BF and corresponding ωmax\omega_{max}
  • Interpret the curve to exclude unsupported effect sizes (e.g., regions where BF<1<1)
  • Aggregate BFFs for meta-analytic inference using multiplicative combination

Example reporting language: “We observed t(28)=2.5. The maximum Bayes factor in favor of the alternative was 4.2 at ω=0.30\omega=0.30. Moreover, our BFF curve indicates that any standardized effect larger than ω0.65\omega\approx 0.65 is disfavored (BF<<1). Hence, we can exclude large effects while acknowledging evidence for a moderate effect.”

BFF methodology as implemented by bfpwr delivers transparent, replicable, and scientifically interpretable visual evidence for hypothesis testing results, advancing beyond conventional significance paradigms (Johnson et al., 2022).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Whiteboard

Topic to Video (Beta)

Follow Topic

Get notified by email when new papers are published related to bfpwr R Package.