Skip to contents

Compute sample size, power, or minimum detectable effect (MDE) for a two-sample test of means. Leave exactly one of n, power, or effect as NULL to solve for that quantity.

Usage

power_mean(effect, ...)

# Default S3 method
power_mean(
  effect = NULL,
  var,
  n = NULL,
  power = 0.8,
  alpha = 0.05,
  N = Inf,
  deff = 1,
  resp_rate = 1,
  alternative = c("two.sided", "one.sided"),
  ratio = 1,
  overlap = 0,
  rho = 0,
  plan = NULL,
  ...
)

Arguments

effect

Absolute difference in means (effect-size magnitude, positive). Leave NULL to solve for MDE.

...

Additional arguments passed to methods.

var

Within-group variance. Scalar (equal variances in both groups) or length-2 vector c(var1, var2) for unequal group variances.

n

Per-group sample size. Scalar (equal groups) or length-2 vector c(n1, n2) for unequal groups. Leave NULL to solve for sample size.

power

Target power, in (0, 1). Leave NULL to solve for power.

alpha

Significance level, default 0.05.

N

Population size for finite-population correction. A scalar applies to both groups; a length-2 vector c(N1, N2) sets group-specific population sizes. Inf disables FPC for the corresponding group.

deff

Design effect multiplier (> 0). Values < 1 are valid for efficient designs (e.g., stratified sampling with Neyman allocation).

resp_rate

Expected response rate, in (0, 1]. Default 1 (no adjustment). The sample size is inflated by 1 / resp_rate.

alternative

Character: "two.sided" (default) or "one.sided".

ratio

Allocation ratio n1/n2 (default 1). Only used when solving for n (n = NULL). For example, ratio = 2 means group 1 gets twice the sample of group 2.

overlap

Panel overlap fraction in [0, 1], for repeated surveys. Defined as the fraction of group 1 that also appears in group 2 (overlap = n12 / n1).

rho

Correlation between occasions in [0, 1].

plan

Optional svyplan() object providing design defaults.

Value

A svyplan_power object with components:

n

Per-group sample size (scalar or length-2 for unequal groups).

power

Achieved power.

effect

Effect size (difference in means).

solved

Which quantity was solved for ("n", "power", or "mde").

params

List of input parameters.

Details

To specify the effect in terms of Cohen's d (standardized effect size), convert via effect = d * sqrt(mean(var)), where d follows Cohen's conventions: 0.2 (small), 0.5 (medium), 0.8 (large).

When var is a length-2 vector, the variance of the difference is:

$$V = \sigma^2_1 / r + \sigma^2_2 - 2 \cdot \text{overlap} \cdot \rho \cdot \sigma_1 \sigma_2$$

where r is the allocation ratio n1/n2 (default 1). When var is scalar and ratio = 1, this simplifies to the familiar V = 2 * var * (1 - overlap * rho).

References

Valliant, R., Dever, J. A., & Kreuter, F. (2018). Practical Tools for Designing and Weighting Survey Samples (2nd ed.). Springer. Chapter 4.

Cochran, W. G. (1977). Sampling Techniques (3rd ed.). Wiley.

See also

power_prop() for proportions, n_mean() for estimation precision.

Examples

# Sample size to detect a difference of 5 with variance 100
power_mean(effect = 5, var = 100)
#> Power analysis for means (solved for sample size)
#> n = 63 (per group), power = 0.800, effect = 5.0000
#> (alpha = 0.05)

# Power given n = 200
power_mean(effect = 5, var = 100, n = 200, power = NULL)
#> Power analysis for means (solved for power)
#> n = 200 (per group), power = 0.999, effect = 5.0000
#> (alpha = 0.05)

# MDE with n = 500
power_mean(var = 100, n = 500)
#> Power analysis for means (solved for minimum detectable effect)
#> n = 500 (per group), power = 0.800, effect = 1.7719
#> (alpha = 0.05)

# With design effect
power_mean(effect = 5, var = 100, deff = 1.5)
#> Power analysis for means (solved for sample size)
#> n = 95 (per group), power = 0.800, effect = 5.0000
#> (alpha = 0.05, deff = 1.50)

# Unequal group variances
power_mean(effect = 5, var = c(80, 120))
#> Power analysis for means (solved for sample size)
#> n = 63 (per group), power = 0.800, effect = 5.0000
#> (alpha = 0.05)

# Allocation ratio 2:1
power_mean(effect = 5, var = 100, ratio = 2)
#> Power analysis for means (solved for sample size)
#> n_treat = 95, n_control = 48 (total = 143), power = 0.800, effect = 5.0000
#> (alpha = 0.05, ratio = 2)