tTestRequiredN
Computes the minimum sample size needed for a t-test to achieve the desired power.
Given a target power and expected effectSize (Cohen's d), returns the smallest integer sample size that meets or exceeds the requested power at significance level alpha. The result is rounded up to the next whole number, with a minimum of 2.
Example:
// Sample size per group for a two-sample t-test
tTestRequiredN(effectSize = 0.5, power = 0.8) // 63
tTestRequiredN(effectSize = 0.5, power = 0.8, type = TTestType.ONE_SAMPLE) // 32
tTestRequiredN(effectSize = 0.8, power = 0.9, alpha = 0.01) // 47Return
the minimum required sample size (per group for TTestType.TWO_SAMPLE, total for TTestType.ONE_SAMPLE and TTestType.PAIRED). Always at least 2.
Parameters
the expected Cohen's d effect size. Must be non-zero. The sign is ignored.
the target statistical power (probability of detecting the effect). Defaults to 0.8 (80%). Must be in (0, 1).
the significance level (Type I error rate). Defaults to 0.05 (5%). Must be in (0, 1).
the direction of the alternative hypothesis. Defaults to Alternative.TWO_SIDED.
the t-test design. Defaults to TTestType.TWO_SAMPLE.
See also
to compute power at a given sample size.
to find the smallest detectable effect at a given sample size.