# Power and Sample Size for Two-sample Tests

An often used method in applied statistics is determining the sample size necessary to view statistically significant results. Given the intended power, we can calculate the required sample size. Given the intended sample size, we can calculate the resulting power. Before we go in to how this works, we need to define a few things.
Error Types

Truth
H0 H1
Test Negative
Don’t Reject
True Negative False Negative
β
Positive
Reject
False Positive
α
True Positive
Power = 1 – β

In looking at a two-sample test, what we’re actually focusing on is the difference of the sample means. Let’s say we have 2 samples.

For purposes of this demonstration, we will assume that the data in these two samples follow a normal distribution. Therefore, their sample mean follows a normal distribution. We also assume that and have the same variance. And we also assume that is independent of . Therefore,

Furthermore, with the equivariance assumption, we are assuming that .

We know the difference of population means to be . As we don’t know either population mean, we approximate that difference with sample means. The variance of the difference of sample means is simply the sum of variance of individual sample means.

Since we see the variance of the difference, we can calculate the standard error very simply.

Furthermore, we can declare to be a function of . We might choose to sample more from one group over the other because the cost of sampling from that group is cheaper. In order to get the greatest value for the money, we’re better off sampling more from the cheaper group. We set to be the ratio of , such that . Therefore, the standard error is calculated as:

Now that we have our standard error for the difference, we can proceed with calculating the sample size.

One Sided Test
In the one sided test, we are establishing whether or not a particular population’s mean is greater than the other.

Alternatively, if we were trying to establish the converse,

Two Sided Test

The only thing that changes for the two sided test is we use instead of . Therefore,