Suppose that we have measured a response variable on a sample from our population. Now also suppose that the population can be split into three or more groups according to a second variable. These groups might be contrived e.g. from an experiment run under a number of different conditions, or natural e.g. comparing family income across a number of regions. Before we attempt to answer a question of this type, it is useful to view the data graphically. A sensible way to compare a response variable across groups is to use a boxplot. Boxplots consist of a box (representing the upper and lower quartiles of the sample), with a midline (sample median) and two tails (sample minimum and maximum).
The aim of a one-way ANOVA is to compare the means of the groups. Let represent the population mean for group . If there are groups, then we test
vs.
The mean mass (grams) of 10 starlings from each of four different roost situations were recorded. Does the mean mass differ between the roosting groups?
The resulting plot can be found in Figure 5.1. There does appear to be a clear difference in the distribution of the weights across the four groups.
Note that we cannot test for ordering in the group means e.g. , nor can we test whether the mean of group 1 alone differs from the means of all the other groups. The basis of the test is to compare two sums of squares. If the null hypothesis is true, these two sums should both provide an estimate of the population variance. If the null hypothesis is false, then only one of them is an estimate of the population variance. Therefore the ratio of the two sums should be close to 1 only if the null hypothesis holds.
In more detail, let represent the response variable for the -th individual in group . Suppose that there are groups and that each group contains observations. In practice, we can deal with groups which have different numbers of observations, but it makes the presentation slightly more messy.
The basic assumption of any ANOVA is that the random variables are an i.i.d sample with
(5.1) |
so that each group can have a distinct mean, but the variance is the same across groups.
Let denote the overall mean and denote the mean of the -th group, and consider the overall sum of squares ()
If we consider the summand, then this can be expanded as
Thus the total sum of squares can be written as
Now
by the definition of , so .
And so the total sum of squares can be split into
The two terms on the right are referred to respectively as the within group () and the between group () sums of squares. When calculating these terms, it is usual to compute and directly from the data, and then to calculate as
From the sums of squares, we calculate the mean sums of squares,
and
Under the null hypothesis, both of these quantities can be used to estimate the residual variance . Therefore to carry out the test, we calculate the ratio of these estimators
If the null hypothesis is true, this ratio will be close to 1. The question is, how far away from 1 does the ratio need to be in order for us to conclude that there is evidence against the null hypothesis? To answer this, we require the sampling distribution of the ratio, under the assumption that is true. We can then obtain the critical region, which will contain all values of the ratio which are sufficiently unusual under to allow us to reject .
Under assumption (5.1) both and are the sum of squares of independent Normal random variables. Consequently they each have a distribution (see results from Math230). In each case, the degrees of freedom of the distribution is given by the denominator of the estimator, which is the value required to give an unbiased estimator of . This is for and for . Since the ratio of two random variables is a random variable with an -distribution, the required sampling distribution is
By comparing the test statistic to this sampling distribution, we can decide whether or not to reject the null hypothesis, usually based on either a critical region or a -value.
Recall the starling masses that we saw in Example 5.2.1. Ten starlings were sampled from four different roosts. The data can be found in the file starlings.Rdata. Carry out a one-way ANOVA to test whether the mean weight of starlings varies between roosts. You should state clearly your hypotheses and conclusions.
The hypotheses are
vs.
Next we need to calculate the three sums of squares. First we need the overall and group means. The overall mean is
and the within group means are 83.6, 79.4, 78.6 and 75.4. To calculate sums of squares,
Next calculate the mean sums of squares
,
.
Finally we calculate the test statistic
The degrees of freedom for the sampling distribution are given by the denominators in the between and within mean sums of squares: in this case, 3 and 36. So the critical region at the 5% level of significance is given by
This gives us a critical value of 2.87 (see Figure 5.1). Since we would reject and conclude that there is evidence of a difference between the mean masses at the four different roosts.
Alternatively, we could calculate the -value,
This gives a -value of 0.000139, which is clearly less that 0.05, so again we would reject the null hypothesis.
Finally, note an alternative way to write the ANOVA assumptions is that the are i.i.d with
, .
Here is the ‘base’ mean level that is common to all groups and is the effect on the mean of being in the -th group. ANOVA gives us a way to test whether or not these means are the same. In the coming sections on linear regression modelling, we will see how we can estimate the size of these effects.