tTestPower

fun tTestPower(effectSize: Double, n: Int, alpha: Double = 0.05, alternative: Alternative = Alternative.TWO_SIDED, type: TTestType = TTestType.TWO_SAMPLE): Double(source)

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

Power is the probability of correctly rejecting the null hypothesis when the true effect size equals effectSize. Higher power means the test is more likely to detect a real effect. A power of 0.8 (80%) is the most common target in study design.

Uses Cohen's d as the effect size metric. Conventional thresholds: 0.2 (small), 0.5 (medium), 0.8 (large). Negative effect sizes are treated as their absolute value. When effectSize is zero, the returned power equals alpha (the Type I error rate).

Example:

// Power of a two-sample t-test with medium effect, 64 per group
tTestPower(effectSize = 0.5, n = 64) // ~0.807
tTestPower(effectSize = 0.5, n = 64, type = TTestType.ONE_SAMPLE) // ~0.979
tTestPower(effectSize = 0.5, n = 64, alternative = Alternative.GREATER) // ~0.882

Return

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

Parameters

effectSize

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

n

the sample size. For TTestType.TWO_SAMPLE, this is the per-group size (assuming equal groups). For TTestType.ONE_SAMPLE and TTestType.PAIRED, this is the total sample size or number of pairs. 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. One-sided tests have higher power for the same parameters.

type

the t-test design. Defaults to TTestType.TWO_SAMPLE.

See also

to find the sample size needed for a target power.

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