# Confidence Interval Based Sample Size for Two Means

A colleague recently inquired about computing sample size when comparing two group means. My initial response was to compute sample size based on the two sample t-test. After a few probing questions it became clear the colleague did not expect the means to differ and demonstrating they were similar was the aim of the study.

There are two primary methods for computing sample size — one is based on hypothesis testing and the other on confidence intervals. The goal of hypothesis testing is to demonstrate differences in means (or proportions, variances, etc) which is the antithesis of what the colleague wanted. Sample size based on a confidence interval is a much better option here.

The large sample confidence for the difference in two population means $\mu_1$ and $\mu_2$ is $\bar{x}_1-\bar{x}_2{\pm}z_{1-\alpha/2}\sqrt{\dfrac{s^2_1}{n_1}+\dfrac{s^2_2}{n_2}}$

where $z_{1-\alpha/2}$ is the quantile of a normal distribution corresponding to confidence level $(1-\alpha)100\%$ and $\bar{x}_i$, $s^2_i$ and $n_i$ are the sample mean, sample variance and sample size respectively for group $i=1,2$.

The right side part of this equation is often termed the margin of error $E$, i.e., $E=z_{1-\alpha/2}\sqrt{\dfrac{s^2_1}{n_1}+\dfrac{s^2_2}{n_2}}$

This formula can be simplified if it’s reasonable to assume a common variance, i.e., $s^2=s^2_1=s^2_2$, and equal sample sizes, i.e., $n=n_1=n_2$. The equation simplifies to $E=z_{1-\alpha/2}\sqrt{\dfrac{2s^2}{n}}$

We can then solve for $n$ to get $n=2\left(\dfrac{z_{1-\alpha/2}s}{E}\right)^2$

As an example, the sample size (per group) for a 95% confidence interval with a $E=20$ unit margin of error and standard deviation $s=100$ is $n=2\left(\dfrac{1.96\times{100}}{20}\right)^2=192.08$

In practice, this would be rounded up to $n=193$ per group. It is common to choose 95% confidence (i.e., $z_{0.975}=1.96$) whereas the margin of error and standard deviation are context specific. One strategy for the margin of error is to choose the smallest value that represents a meaningful difference, so that any smaller value would be considered inconsequential. The choice of standard deviation can be informed by previous research.

Another consideration would be loss to follow up (if perhaps the outcome was the difference pre- and post-measurements). So, that with say a 20% attrition rate, the sample size per group would be increased to $n=\dfrac{192.08}{1-0.2}\approx241$

Of course, the computation gets far more complex, and possibly intractable, when the equal variance and sample size assumptions are not reasonable.