---
title: bfpwr R Package for Bayes-Factor Functions
url: https://www.emergentmind.com/topics/bfpwr-r-package
type: topic
---

# bfpwr R Package for Bayes-Factor Functions

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 [2210.00049].

## 1. Theoretical Basis of Bayes-Factor Functions

Traditional Bayes factors are ratios of marginal likelihoods under competing hypotheses: $BF_{10} = m_1(\text{data}) / m_0(\text{data})$, with each $m_i$ reflecting a prior-averaged probability of the data. These factors depend on prior specification, notably the scale parameter $\tau^2$ for the alternative hypothesis. BFFs generalize this by producing $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(\omega)$, a function of design and sample size. This creates a curve of $BF_{10}$ over meaningful $\omega$ values, displaying the full spectrum of evidentiary support for $H_1$ versus $H_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 $H_1$ over a prior for $\lambda$:

- **z-test**: $z \sim N(0,1)$ under $H_0$, $N(\lambda,1)$ under $H_1$; $\lambda \sim J(0,\tau^2)$, normal-moment prior.  
  $$
  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.)**: $t \sim T(\nu,0)$ under $H_0$, $T(\nu,\lambda)$ under $H_1$; $\lambda \sim J(0,\tau^2)$.  
  Let $r = 1 + t^2/\nu$, $s = 1 + t^2/[\nu(1+\tau^2)]$, $q = \tau^2(\nu+1)/[\nu(1+\tau^2)]$.  
  $$
  BF_{10}^{(t)}(t | \tau^2) = (\tau^2+1)^{-3/2} (r/s)^{(\nu+1)/2} [1 + q t^2/s]
  $$

- **$\chi^2$-test ($k$ d.f.)**: $h \sim \chi^2_k$ under $H_0$, $\chi^2_k(\lambda)$ under $H_1$; $\lambda \sim \text{Gamma}(k/2+1,$ rate $= 1/(2\tau^2))$.  
  $$
  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, m$ d.f.)**: $f \sim F(k,m;0)$ under $H_0$, $F(k,m;\lambda)$ under $H_1$; $\lambda \sim \text{Gamma}(k/2+1,$ rate $= 1/(2\tau^2))$. Let $v = m(1+\tau^2)$.  
  $$
  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 $\tau^2$ reflects the scientific context:

- z or one-sample t: $\lambda = \sqrt{n} \omega \implies \tau^2(\omega) = n\omega^2/2$
- two-sample z or t ($n_1$, $n_2$): $\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)]$
- $\chi^2$ on $k$ d.f.: $\lambda^2 = n \omega'\omega \implies \tau^2 = n \omega'\omega / k$
- F in ANOVA ($k$ groups, $n$ total): $\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 [2210.00049].

## 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 $\tau^2_i = \tau^2(\omega_i)$ for each effect size $\omega_i$
2. Plug observed statistic (z, t, h, f) and $\tau^2_i$ into closed-form formula
3. Record pairs $(\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 $H_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 $H_1$
- The crossing at BF=1 demarcates regions favoring $H_1$ (to the left) or $H_0$ (to the right)
- The maximum BF and corresponding $\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 $BF_{10}(\omega)$ over the effect-size grid
- Report the maximum BF and corresponding $\omega_{max}$
- Interpret the curve to exclude unsupported effect sizes (e.g., regions where BF$<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 $\omega=0.30$. Moreover, our BFF curve indicates that any standardized effect larger than $\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 [2210.00049].

Source: https://www.emergentmind.com/topics/bfpwr-r-package