ab: Test and Power Calculation for Mediating Effect

View source: R/ab.R

abR Documentation

Test and Power Calculation for Mediating Effect

Description

This function computes the indirect (mediated) effect in a mediation model and either tests its significance or calculates statistical power. It uses regression coefficients from an independent variable to a mediator (a) and from the mediator to an outcome (b) with their standard errors. Variance can be estimated using Sobel, Aroian, or Goodman formulas.

Usage

ab(
  type = c("power", "test"),
  n = 25000,
  a = 0.15,
  sa = 0.01,
  b = log(1.19),
  sb = 0.01,
  alpha = 0.05,
  fold = 1,
  method = c("sobel", "aroian", "goodman")
)

Arguments

type

Character; "test" to perform a significance test, "power" to estimate power.

n

Numeric; baseline sample size for power calculation (default 25000).

a

Numeric; regression coefficient from independent variable to mediator.

sa

Numeric; standard error of a.

b

Numeric; regression coefficient from mediator to outcome.

sb

Numeric; standard error of b.

alpha

Numeric; significance level (default 0.05) for power calculation.

fold

Numeric; multiplicative factor for sample size in power calculation.

method

Character; one of "sobel", "aroian", "goodman" specifying the variance formula.

Details

The indirect effect is ab, representing the portion of the effect of X on Y transmitted through mediator M.

Standard errors of the indirect effect are approximated using the delta method:

  • Sobel: SE = \sqrt{b^2 s_a^2 + a^2 s_b^2}

  • Aroian: SE = \sqrt{b^2 s_a^2 + a^2 s_b^2 + s_a^2 s_b^2}

  • Goodman: SE = \sqrt{b^2 s_a^2 + a^2 s_b^2 - s_a^2 s_b^2}

The z-statistic is z = ab / SE(ab), assumed to follow a standard normal distribution under H_0: ab = 0.

Two-sided p-value: p = 2 \Phi(-|z|) 95% confidence interval: ab \pm 1.96 \cdot SE(ab)

Power is based on a non-central chi-square approximation: \lambda = z^2 \cdot \text{fold} Power = P(\chi^2_1(\lambda) > \chi^2_{1,1-\alpha}), where \chi^2_{1,1-\alpha} is the critical value at significance level \alpha.

These tests assume large samples. For small samples, bootstrap confidence intervals are recommended.

Value

If type = "test", a named numeric vector with:

  • effect: indirect effect estimate (ab)

  • se: standard error

  • z: z-statistic

  • p: two-sided p-value

  • lcl: lower 95% confidence limit

  • ucl: upper 95% confidence limit

If type = "power", a named numeric vector with:

  • sample_size: effective sample size (fold * n)

  • power: estimated statistical power

References

\insertRef

freathy08gap

\insertRef

kline05gap

\insertRef

mackinnon08gap

\insertRef

preacher01gap

Examples

## Not run: 
# Test mediation effect
ab(a = 0.15, sa = 0.01,
   b = log(1.19), sb = 0.01,
   method = "aroian")

# Power calculation for 10% increase in sample size
ab(type = "power", n = 25000,
   a = 0.15, sa = 0.01,
   b = log(1.19), sb = 0.01,
   fold = 1.1)

## End(Not run)


gap documentation built on Oct. 27, 2026, 1:07 a.m.