proportionZTestPower

fun proportionZTestPower(effectSize: Double, n: Int, alpha: Double = 0.05, alternative: Alternative = Alternative.TWO_SIDED, twoSample: Boolean = true): Double(source)

Computes the statistical power of a proportion z-test using the normal approximation.

Power is the probability of correctly rejecting the null hypothesis when the true effect size equals effectSize. Uses Cohen's h as the effect size metric, which is based on the arcsine transformation of proportions. Conventional thresholds: 0.2 (small), 0.5 (medium), 0.8 (large). Negative effect sizes are treated as their absolute value.

Example:

// Power of a two-sample proportion z-test with 64 per group
proportionZTestPower(effectSize = 0.5, n = 64) // ~0.807
proportionZTestPower(effectSize = 0.5, n = 64, twoSample = false) // ~0.979

Return

the statistical power, a value in [0, 1].

Parameters

effectSize

the expected Cohen's h effect size. The sign is ignored.

n

the sample size. For two-sample tests (twoSample = true), this is the per-group size assuming equal groups. For one-sample tests, this is the total sample size. Must be at least 2.

alpha

the significance level (Type I error rate). Defaults to 0.05 (5%). Must be in (0, 1).

alternative

the direction of the alternative hypothesis. Defaults to Alternative.TWO_SIDED.

twoSample

whether this is a two-sample test. Defaults to true. When false, uses the one-sample noncentrality factor (higher power for the same n).

See also

to find the sample size needed for a target power.

to find the smallest detectable effect at a given sample size.

to compute Cohen's h from two proportions.