Tutorials › Introduction to Statistics › The F Statistic for Comparing Means

One-Way ANOVA · Tutorial 857 of 996

The F Statistic for Comparing Means

Learn to calculate the one-way ANOVA F statistic and understand why a large between-to-within variation ratio weighs against equal population means.

Intermediate 10 min read

What You'll Learn

  • Define the between-group and within-group mean squares used in the F statistic.
  • Calculate an F statistic from sums of squares and degrees of freedom.
  • Compute the statistic from raw observations for balanced and unequal group sizes.
  • Explain how unequal population means can increase between-group variation.
  • Distinguish a large F statistic from a conclusion about significance or causation.

Why ANOVA Uses a Ratio

When several groups have different sample means, that difference alone does not tell us whether their population means differ. Sample means vary from sample to sample, even when all groups come from populations with the same mean. One-way analysis of variance (ANOVA) therefore compares the variation between the observed group means with the variation within the groups. The F statistic expresses that comparison as a ratio.

A large ratio means the group means are separated more than would be expected from the amount of variation among observations within the groups. It therefore weighs against the null hypothesis that all population means are equal. The statistic is not itself a probability, and a large value is not a guarantee that the null hypothesis is false.

Definition: For \(k\) groups with total sample size \(N\), let \(SS_B\) be the between-group sum of squares and \(SS_W\) the within-group sum of squares. The between-group and within-group mean squares are \(MS_B=SS_B/(k-1)\) and \(MS_W=SS_W/(N-k)\). The one-way ANOVA F statistic is $$ F=\frac{MS_B}{MS_W}. $$ Both mean squares estimate variation on a squared-data scale, so their ratio is unitless.

Here \(k-1\) and \(N-k\) are the respective degrees of freedom: there are \(k-1\) degrees of freedom for differences among the \(k\) group means, and \(N-k\) for variation remaining within groups after estimating those means. Thus the statistic compares mean squares, not the raw sums of squares. Dividing by degrees of freedom puts the two sums of squares on comparable per-degree-of-freedom scales.

The Model Behind the Comparison

The usual one-way ANOVA model represents observation \(j\) in group \(i\) as \(Y_{ij}=\mu_i+\varepsilon_{ij}\), where \(\mu_i\) is that group’s population mean and \(\varepsilon_{ij}\) is its random error. For the standard F-test interpretation, errors are independent, normally distributed with mean zero, and have a common variance \(\sigma^2\) across groups. The hypotheses are \(H_0:\mu_1=\mu_2=\cdots=\mu_k\) and \(H_a:\) not all group population means are equal. The calculation of F can be made whenever the group data and sums of squares are available, but the model assumptions matter when using it to make a formal inference.

The between-group sum of squares measures how far each sample mean is from the grand mean, weighting each squared distance by its group size. The within-group sum of squares adds up the squared distances of individual observations from their own group mean. These measure different sources of variation: separation among groups, and variation among observations inside groups.

Worked Example: Calculating F From Sums of Squares

Suppose a hypothetical study compares a quantitative outcome, measured in points, across three groups. Its ANOVA calculations give \(SS_B=48\) points squared and \(SS_W=72\) points squared, with 12 observations in total. Find the F statistic.

There are \(k=3\) groups and \(N=12\) observations, so the degrees of freedom are \(k-1=2\) between groups and \(N-k=9\) within groups. The mean squares are $$ MS_B=\frac{48}{2}=24,\qquad MS_W=\frac{72}{9}=8. $$

Therefore, $$ F=\frac{24}{8}=3.00. $$

The between-group mean square is three times the within-group mean square. This describes the variation in these data; by itself it does not supply a p-value or determine whether the result is statistically significant.

Why Large Values Count Against Equal Means

If \(H_0\) is true, all group means are equal. Under the stated model, both \(MS_B\) and \(MS_W\) then estimate the common error variance \(\sigma^2\). A ratio much larger than one can occur by chance, but it indicates that the between-group variation is large relative to the within-group variation. If population means are unequal, their separation adds a systematic component to the between-group variation, while within-group variation still reflects the common error variance.

This idea can be made precise. Write \(n_i\) for the size of group \(i\), \(\bar{x}_i\) for its sample mean, and \(\bar{x}_{..}\) for the weighted grand mean. The between-group sum of squares is \(SS_B=\sum_{i=1}^k n_i(\bar{x}_i-\bar{x}_{..})^2\). Let \(\mu_w=\sum_i n_i\mu_i/N\) be the weighted mean of the population means for this allocation of group sizes. Under the model above, $$ E(MS_B)=\sigma^2+\frac{\sum_{i=1}^k n_i(\mu_i-\mu_w)^2}{k-1}, \qquad E(MS_W)=\sigma^2. $$

The extra term in \(E(MS_B)\) is nonnegative because it is a sum of weighted squared deviations. It is zero when all \(\mu_i\) are equal, and positive when they are not all equal. This explains why unequal means tend to make the F ratio larger: they can raise its numerator, while the expected within-group mean square remains \(\sigma^2\).

A Short Justification of the Mean-Square Result

To see where the between-group expectation comes from, express each sample mean as \(\bar{Y}_i=\mu_i+\bar{\varepsilon}_i\), where \(\bar{\varepsilon}_i\) has mean zero and variance \(\sigma^2/n_i\). The grand sample mean is the weighted mean of the group sample means. The weighted squared deviations therefore have a part from the population means and a part from the errors; their cross-product has expectation zero because the errors have mean zero.

For the error part, use the identity \(\sum_i n_i(\bar{\varepsilon}_i-\bar{\varepsilon}_{..})^2=\sum_i n_i\bar{\varepsilon}_i^2-N\bar{\varepsilon}_{..}^2\), where \(\bar{\varepsilon}_{..}=\sum_i n_i\bar{\varepsilon}_i/N\). Taking expectations gives $$ \sum_{i=1}^k n_i\frac{\sigma^2}{n_i}-N\frac{\sigma^2}{N} =k\sigma^2-\sigma^2 =(k-1)\sigma^2. $$

Consequently, \(E(SS_B)=\sum_i n_i(\mu_i-\mu_w)^2+(k-1)\sigma^2\). Dividing by \(k-1\) gives the displayed expectation for \(MS_B\). Within group \(i\), the expected sum of squared deviations from its sample mean is \((n_i-1)\sigma^2\). Adding over groups gives \(E(SS_W)=\sum_i(n_i-1)\sigma^2=(N-k)\sigma^2\); dividing by \(N-k\) gives \(E(MS_W)=\sigma^2\).

Equal expected mean squares under \(H_0\) do not mean that the observed ratio must equal one, or that the expected value of the ratio is necessarily one. Each mean square varies from sample to sample, and F is a ratio of those random quantities. The F distribution and its degrees of freedom are used to calibrate how unusual an observed ratio is under \(H_0\); the statistic alone is not that calibration.

Worked Example: Computing F From Balanced Group Data

Consider hypothetical point scores from three groups, with three observations per group:

Group A: 4, 5, 6; Group B: 6, 7, 8; Group C: 8, 9, 10.

The group means are 5, 7, and 9 points, and the grand mean is \((4+5+6+6+7+8+8+9+10)/9=7\) points. The between-group sum of squares is $$ SS_B=3(5-7)^2+3(7-7)^2+3(9-7)^2 =12+0+12=24\text{ points}^2. $$

For each group, the observations lie one point below, at, and one point above that group’s mean, giving a within-group sum of squares of \(1+0+1=2\) points squared. Across the three groups, \(SS_W=2+2+2=6\) points squared. Here \(k=3\) and \(N=9\), so the degrees of freedom are 2 between groups and 6 within groups. Thus $$ MS_B=\frac{24}{2}=12,\qquad MS_W=\frac{6}{6}=1,\qquad F=\frac{12}{1}=12. $$

The between-group mean square is 12 times the within-group mean square. This substantial ratio reflects the separation of these group means relative to the modest spread of observations within each group. A formal significance conclusion still requires calibrating F under the null model.

Unequal Group Sizes and the Same Ratio

The formula does not require groups to have equal sizes. When their sizes differ, the grand mean is weighted: a group with more observations contributes more to it, and its squared deviation from the grand mean contributes more to \(SS_B\). The degrees of freedom still depend on the number of groups and the total sample size: \(k-1\) and \(N-k\), respectively.

Worked Example: Unequal Group Sizes

Suppose three hypothetical groups have point scores A: 2, 4; B: 4, 5, 6; and C: 6, 7, 8, 9. Their sizes are 2, 3, and 4, and their means are 3, 5, and 7.5 points. The grand mean is the weighted mean $$ \bar{x}_{..}=\frac{2(3)+3(5)+4(7.5)}{9}=\frac{51}{9}=5.667\text{ points}. $$

Using the group sizes as weights, $$ SS_B=2(3-5.667)^2+3(5-5.667)^2+4(7.5-5.667)^2 \approx14.222+1.333+13.444=29.000\text{ points}^2. $$

The within-group sums of squares are 2 for A, 2 for B, and 5 for C, so \(SS_W=9\) points squared. Since \(k=3\) and \(N=9\), the degrees of freedom are 2 between groups and 6 within groups. Then $$ MS_B=\frac{29}{2}=14.50,\qquad MS_W=\frac{9}{6}=1.50,\qquad F=\frac{14.50}{1.50}=9.667. $$

The unequal group sizes change the weighted grand mean and the between-group sum of squares, but not the definition of F. The resulting statistic compares the two mean squares on the same scale.

Reading the Statistic Carefully

A larger F means that \(MS_B\) is larger relative to \(MS_W\). This is the direction of evidence relevant to the alternative hypothesis that not all population means are equal. A value near or below one does not prove that all means are equal: random sampling can produce different ratios, and a small ratio can occur even when population means differ. Conversely, a large ratio is not a measure of how many means differ or which groups differ. F is an omnibus comparison of the overall between-group variation with the within-group variation.

The numerical size of F also has no measurement units. If the outcome were recorded in a different unit, both mean squares would be multiplied by the square of the unit-conversion factor, and their ratio would be unchanged. This makes F a scale-free comparison, though it does not remove the need to interpret the data in their original context.

Common mistake: “The between-group sum of squares is large, so F must be large.” This is incomplete because F uses \(MS_B\), not \(SS_B\) alone, and divides it by \(MS_W\). A large \(SS_B\) can yield a modest ratio if within-group variation is also large; group sizes and degrees of freedom also affect the mean squares. Calculate both mean squares before taking their ratio.

The central role of the denominator is easy to overlook. If observations within each group are highly variable, differences among sample means may be unsurprising even when the means are visibly separated. If observations within groups are tightly clustered, the same degree of separation can yield a larger F. The ratio puts these two sources of variation in direct comparison.

Check Your Understanding

Use the definitions and reasoning in this tutorial to answer the following questions.

  1. In one-way ANOVA with four groups and 20 observations total, what are the between-group and within-group degrees of freedom?
  2. If \(MS_B=18\) and \(MS_W=6\), calculate F and describe what the ratio compares.
  3. Under equal population means and the standard model, what variance does each mean square estimate in expectation?
  4. Why can unequal population means increase the expected between-group mean square without increasing the expected within-group mean square?
  5. Does an observed F of 12, by itself, give a p-value or prove that at least one population mean differs? Explain.