01Your objective: estimation or hypothesis testing
If you want to estimate a value, such as a prevalence or a mean, the sample size is set by the precision you need: the confidence level and margin of error. If you want to test a hypothesis, such as a difference between groups or a regression effect, it is set by the significance level, the power and the smallest effect worth detecting.
02Significance level (alpha)
Alpha is the probability of a Type I error: rejecting a null hypothesis that is in fact true (a false positive). It is usually set at 0.05, or lower where many tests are run or the consequences of a false positive are serious.
03Power (1 minus beta)
Beta is the probability of a Type II error: failing to reject a null hypothesis that is false (a false negative). Power, 1 minus beta, is the probability of detecting an effect of the assumed size if it exists; 80% or 90% is common.
04Effect size
The size of the difference or relationship you want to be able to detect, in raw units or as a standardised measure such as Cohen's d, f or f-squared, an odds ratio or a correlation. It should come from previous studies, a pilot study or the smallest difference that is practically or clinically important. Generic "small, medium, large" benchmarks are a last resort and should be justified.
05Variability
The more heterogeneous the population, the larger the sample you need. For means, this is the expected standard deviation; for proportions, the expected proportion, where p = 0.5 gives the largest, most conservative sample.
06Confidence level and margin of error
For estimation studies, the confidence level (often 95%) and the margin of error you will accept (for example plus or minus 5 percentage points) set the precision of your estimate.
07Population size
For large populations, population size has little effect on the required sample. When the sample would be a sizeable fraction of a small, finite population, a finite population correction reduces the number needed.
08Clustering and the design effect
When participants are sampled or randomised in groups, such as schools, hospitals or regions, people in the same cluster tend to be alike. The sample size from a simple formula is multiplied by the design effect, 1 + (m - 1) × ICC, where m is the average cluster size and ICC the intra-cluster correlation coefficient.
09Dropout and non-response
The calculated number is the number you need to analyse. To allow for an expected attrition or non-response rate, divide it by (1 - the expected rate): with 20% expected dropout, recruit n / 0.8.
10Types of power analysis
An a priori power analysis, done before data collection, gives the sample size needed. A sensitivity analysis gives the smallest effect your fixed or available sample can detect, which is useful when the sample size is constrained. Assurance, a Bayesian alternative, averages power over a prior distribution for the effect size. Post-hoc (observed) power calculated from your own results is generally discouraged, because it adds nothing beyond the p-value; report confidence intervals instead.
11Tools and documentation
Calculations use established software such as G*Power, OpenEpi, R (for example the pwr package or simulation), SPSS and Stata, or simulation where no closed formula fits. Every assumption, its source and the software output are documented so your supervisor, ethics committee or reviewers can reproduce the result.