# Sample Size for Hypothesis Testing of μ

A common question when setting up a hypothesis test is concerning sample size. An example, might be: How many samples do we need to measure to determine the new process is better than the old one on average?

While this seems like a simple question, we need a bit of information before we can do the calculations. I’ve also found that the initial calculation is nearly always initiated a conversation concerning the balance of sample risks, the ability to detect a change of a certain size and the constraints concerning the number of samples.

## Given Values

To do the sample size calculation for a hypothesis test for the population mean, $-\mu-$, we need the following set of values:

The population variance, $-\sigma^{2}-$. For this type of hypothesis test, we have this value based on prior measurements.

The Type I and Type II errors represented by $-\alpha-$ and $-\beta-$, respectively. These allow us to quantify the desired sampling risk for this particular test.

Finally, we also need to know the difference we desire to detect, $-\Delta-$. This is the amount of shift or change in the mean, $-\mu-$ that we would like to detect if it has indeed occurred. This is similar to the difference we use in the calculation of the z-value in the hypothesis test calculations and for the calculation of the power of the sample or test.

## Sample Size Formulas

If you noticed, n is part of the calculation of the z-value for the test statistic. In that calculation, we use the measured values to estimate the new population mean and compare that to an old, or specification, mean, the null value. Rearranging the formula for the test statistic and including the Type II error, $-\beta-$ we have the formula to calculate the sample size, n, for a single-sided test:

$$ \displaystyle n=\frac{\sigma^{2}\left(z_{\alpha}+z_{\beta}\right)^{2}}{\Delta^{2}} $$

If conducting a two-sided test, the formula accounts for the Type I error that may occur on the upper or lower tail, thus we divide the $-\alpha-$ by 2, resulting in:

$$ \displaystyle n=\frac{\sigma^{2}\left(z_{\alpha/2}+z_{\beta}\right)^{2}}{\Delta^{2}}$$

## When We Don’t Know the Population Variance

Often, we don’t know the variance and instead would use a t-test to accommodate having to estimate the variance term from the data. If n is 30 or more, the t-distribution, used in a t-test, is for intent and purpose the same as a normal distribution. This ability to estimate the variance is only an issue when there are less than 30 samples.

If we do not know the variance term and need to estimate the sample size, use the above formulas using a sample variance, s$-s^{2}-$, instead of the population variance. The implies the need to take measurements prior to conducting the hypothesis test in order to estimate how many samples are necessary for the test. A good practice is to measure at least 30 items, if possible, to reduce the expected difference between the sample and population variance values.

## Leave a Reply