Sample Size & Power Calculator (t-test, log-rank)

Sample size and power calculator for t-tests, ANOVA, proportions and log-rank. Solve for n or power; formulas, worked example and grant text.

How it works

Sample size is derived from the standardised effect size (Cohen’s d), the desired significance level, and the target power. The tool reports the n per group required, and inverts the calculation to report the power achieved by a sample size you already have — which is the useful direction when reviewing a completed experiment.

The formulas this calculator implements

Each test type uses its own closed-form formula. In every case z_a is the standard normal quantile for 1 - alpha/2 (the test is two-sided) and z_b is the quantile for the target power.

The repo’s tests pin the t-test function to 394, 64, 26 and 17 per group for d = 0.2, 0.5, 0.8 and 1.0 at alpha 0.05 and 80% power, to 93 per group for the Fleiss, Levin and Paik reference case (p1 = 0.5, p2 = 0.3), and to the Schoenfeld closed form.

What each input means

Worked example, computed by the tool’s own function

Inputs: two-sample t-test, Cohen’s d = 0.5, alpha = 0.05, target power 80%, Calculate N.

The same function run in the other direction (Calculate Power, d = 0.5, alpha = 0.05): n = 10 per group gives 19.2% power and n = 20 per group gives 34.5%. At d = 0.8, n = 10 per group gives 41.5%.

Other inputs, same function: d = 0.8 needs 26 per group; d = 1.0 needs 17; d = 0.5 at 90% power needs 86; d = 0.5 at alpha 0.01 and 90% power needs 121.

Proportions, p1 = 50% and p2 = 30%, alpha 0.05, 80% power: 93 per group. With 30 per group the achieved power is 34.9%.

Survival, hazard ratio 0.5, alpha 0.05, 80% power: 66 events. If 70% of enrolled subjects are expected to have the event, that is 95 enrolled subjects in total.

Common mistakes

Frequently asked questions

How do I calculate sample size for a t-test?

Choose the smallest difference between group means that would change your conclusion, divide it by the pooled standard deviation from pilot or published data to get Cohen’s d, then set your significance level (usually 0.05) and target power (usually 80%). The calculator returns n per group. For a two-sample t-test at 80% power and alpha 0.05 the requirement is roughly 16/d² per group, so a d of 0.5 needs about 64 per group.

Can I calculate power after the experiment is finished?

You can, but observed or post-hoc power — power recomputed from the effect you happened to measure — tells you nothing the p-value has not already told you, because the two are mathematically tied: a non-significant result always yields low observed power. It is not evidence that a study was underpowered. What is legitimate after the fact is asking what effect size your sample size could have detected, which this tool reports, and which reviewers do accept.

What effect size should I assume if I have no pilot data?

Use the smallest effect that would be scientifically meaningful rather than the one you hope to see — the question is what size of difference would change what anyone does next. If you must fall back on convention, Cohen’s benchmarks are d = 0.2 small, 0.5 medium, 0.8 large, but they were never intended as substitutes for domain judgement and reviewers increasingly say so. Assuming a large effect because it yields a comfortable n is the most common way a power calculation becomes fiction.

Does sample size mean biological or technical replicates?

Biological replicates. n is the number of independent experimental units — separate animals, separate cultures, separate preparations. Technical replicates measure the same unit more than once; they reduce measurement noise and should be averaged before analysis, not counted towards n. Treating them as independent is pseudoreplication, and it inflates significance rather than power.

How many replicates do I need for my experiment?

It depends on the size of the effect you need to detect and the variability of your measurement. Sample size is driven by the standardised effect size — the difference between group means divided by the pooled standard deviation. As a rough guide at 80% power and a 0.05 significance level, detecting a large effect (d = 0.8) takes about 26 per group, a medium effect (d = 0.5) about 64, and a small effect (d = 0.2) about 394.

What is statistical power and why does 80% matter?

Power is the probability that a study will detect an effect that genuinely exists. At 80% power, one in five real effects will be missed. The 80% convention is a pragmatic balance between the cost of larger experiments and the risk of false negatives, not a statistical law — safety-critical work often targets 90% or higher.

Which formula does the sample size calculator use for a t-test?

n per group = ceil(2 × ((z_a + z_b) / d)² + z_a² / 4), where z_a is the normal quantile for 1 − alpha/2, z_b the quantile for the target power and d is Cohen’s d. The last term is Guenther’s (1981) correction for the t distribution. For d = 0.5, alpha 0.05 and 80% power it returns 64 per group.

Why does the calculator say 64 per group when the simple formula gives 63?

The plain normal approximation, 2 × ((1.96 + 0.8416) / 0.5)², is 62.8. The tool adds Guenther’s z_a² / 4 correction for the heavier tails of the t distribution (about 0.96) and rounds up, giving 64. Rounding down would leave the study slightly underpowered.

Is the ANOVA sample size a different calculation?

In this tool, no. The per-group n is the same two-sample t-test figure, and the total is that n multiplied by the number of groups you enter. It is not a noncentral-F calculation and it does not adjust for multiple comparisons, so treat it as a planning estimate.

Does the survival result tell me how many animals to enrol?

No. It gives the number of events needed for a log-rank test (Schoenfeld, 1983). The tool divides that by the probability that an enrolled subject has the event before the study ends, which you must estimate from pilot or published follow-up. For a hazard ratio of 0.5, alpha 0.05 and 80% power it returns 66 events, or 95 enrolled subjects at a 70% event probability.

Method reference

Cohen J. (1988) Statistical Power Analysis for the Behavioral Sciences, 2nd ed.

Reference standards & software

Related tools

SciKeepLoading SciKeep…