Tutorials › VEE Mathematical Statistics › A Three-Group ANOVA From Raw Data

VEE Mathematical Statistics · One-Way Analysis of Variance · Tutorial 810 of 880

A Three-Group ANOVA From Raw Data

Practice a complete three-group one-way ANOVA calculation from raw observations, including its p-value and contextual interpretation.

Intermediate 11 min read

What You'll Learn

  • Calculate group sizes, means, and the grand mean directly from raw observations
  • Find within-group and between-group sums of squares and verify their partition
  • Complete the degrees of freedom, mean squares, and F statistic in an ANOVA table
  • Obtain an F-test p-value and make a conclusion in context
  • Recognize common raw-data calculation errors and their corrections

From Raw Observations to an ANOVA Test

A one-way analysis of variance compares the means of several groups by measuring how much the observations vary between groups relative to how much they vary within groups. When the observations are given individually, the first task is not to reach for an F table: it is to organize the raw data correctly. Group sizes, group means, the grand mean, and within-group variation all contribute to the final test.

This tutorial works through three-group calculations from raw observations, including the ANOVA table and p-value. The method is aligned with the SOA VEE Mathematical Statistics syllabus. Its conclusion concerns whether the group means are all equal; the omnibus test alone does not identify which means differ.

Model and assumptions: For group \(i\), observation \(j\) follows \(Y_{ij}=\mu_i+\varepsilon_{ij}\), where there are \(k=3\) fixed groups. The errors are independent and normally distributed with mean \(0\) and common variance \(\sigma^2\). Thus the observations within each group are independent \(N(\mu_i,\sigma^2)\) variables, and the groups share the same variance. The test is \(H_0:\mu_1=\mu_2=\mu_3\) against the alternative that not all three means are equal. Dependence between observations, substantial departures from normality in small samples, or unequal group variances can make the usual F-test inappropriate.

Organize the Raw Data

Let \(n_i\) be the number of observations in group \(i\), and let \(N=n_1+n_2+n_3\) be the total sample size. Calculate each group’s sample mean, then the grand mean across all observations. The grand mean is a size-weighted average of the group means: a group with more observations contributes more to it.

$$ \bar{Y}_{i\cdot}=\frac{1}{n_i}\sum_{j=1}^{n_i}Y_{ij}, \qquad \bar{Y}_{\cdot\cdot}=\frac{1}{N}\sum_{i=1}^{3}\sum_{j=1}^{n_i}Y_{ij} =\frac{\sum_{i=1}^{3}n_i\bar{Y}_{i\cdot}}{N}. $$

The between-groups sum of squares measures how far the group means are from the grand mean. The within-groups sum of squares measures how far individual observations are from their own group mean. Their sum is the total sum of squares around the grand mean.

$$ SS_{\text{between}}=\sum_{i=1}^{3}n_i(\bar{Y}_{i\cdot}-\bar{Y}_{\cdot\cdot})^2, \qquad SS_{\text{within}}=\sum_{i=1}^{3}\sum_{j=1}^{n_i}(Y_{ij}-\bar{Y}_{i\cdot})^2, \qquad SS_{\text{total}}=\sum_{i=1}^{3}\sum_{j=1}^{n_i}(Y_{ij}-\bar{Y}_{\cdot\cdot})^2. $$

Worked Example: Complete ANOVA From Three Raw Samples

A hypothetical analyst compares the mean processing times, in minutes, for three independent procedures. The observations are:

Procedure A: \(9,9,11,11\). Procedure B: \(11,11,13,13\). Procedure C: \(13,13,15,15\). At significance level \(0.05\), carry out the one-way ANOVA, find its p-value, and state a conclusion. Assume the model conditions stated above hold.

Method and initial summaries. There are \(n_1=n_2=n_3=4\) observations, so \(N=12\). The sums are \(40,48,56\), giving group means \(40/4=10\), \(48/4=12\), and \(56/4=14\). The total is \(40+48+56=144\), so the grand mean is \(144/12=12\).

Within-groups variation. In Procedure A, each observation differs from its mean, \(10\), by either \(-1\) or \(1\). Its sum of squared deviations is \(1+1+1+1=4\). For Procedure B, the deviations from \(12\) are also \(-1,-1,1,1\), giving \(SS_2=4\). Procedure C has the same pattern around \(14\), giving \(SS_3=4\). Therefore \(SS_{\text{within}}=4+4+4=12\).

Between-groups and total variation. The group means \(10,12,14\) differ from the grand mean \(12\) by \(-2,0,2\). Thus

$$ SS_{\text{between}}=4(-2)^2+4(0)^2+4(2)^2=16+0+16=32. $$

The total sum of squares is \(SS_{\text{total}}=32+12=44\). As a direct check, the observations differ from \(12\) by \(-3,-3,-1,-1\) in A, \(-1,-1,1,1\) in B, and \(1,1,3,3\) in C. Their squared deviations sum to \(9+9+1+1+1+1+1+1+1+1+9+9=44\).

Degrees of freedom, mean squares, and F statistic. The between-groups degrees of freedom are \(3-1=2\); the within-groups degrees of freedom are \(12-3=9\); and the total degrees of freedom are \(12-1=11\). The mean squares are \(MS_{\text{between}}=32/2=16\) and \(MS_{\text{within}}=12/9=4/3\). Therefore \(F=16/(4/3)=12\).

SourceSum of squaresDegrees of freedomMean squareF
Between groups3221612
Within groups (error)1294/3—
Total4411——

P-value and conclusion. Under \(H_0\), the test statistic has an \(F\) distribution with 2 and 9 degrees of freedom. For an \(F(2,\nu)\) variable and observed value \(f\), the upper-tail probability is \(\left(\nu/(\nu+2f)\right)^{\nu/2}\). Here the p-value is \(\left(9/(9+2(12))\right)^{9/2}=(3/11)^{4.5}\approx0.0029\). Since \(0.0029<0.05\), reject \(H_0\). There is evidence that the mean processing times are not all equal. This test does not establish which procedure means differ.

Mistake avoided. Using \(SS_{\text{between}}/SS_{\text{within}}=32/12\) as the F statistic gives \(2.667\), which is not the ANOVA F ratio. Each sum of squares must first be divided by its own degrees of freedom: the correct ratio is \((32/2)/(12/9)=12\).

Why the Sums of Squares Add

The partition is not merely a convenient arithmetic check. For any observation, write its deviation from the grand mean as its deviation from its group mean plus the group mean’s deviation from the grand mean. When these squared deviations are summed, the cross-products vanish because deviations from each group mean sum to zero within that group.

$$ Y_{ij}-\bar{Y}_{\cdot\cdot} =(Y_{ij}-\bar{Y}_{i\cdot})+(\bar{Y}_{i\cdot}-\bar{Y}_{\cdot\cdot}). $$

Squaring and summing gives the within sum of squares, the between sum of squares, and a cross-product term. For group \(i\), that cross-product is proportional to \(\sum_j(Y_{ij}-\bar{Y}_{i\cdot})\), which equals zero by the definition of the group mean. The remaining between-groups term is repeated \(n_i\) times for group \(i\), producing its weight \(n_i\).

$$ \begin{aligned} SS_{\text{total}} &=SS_{\text{within}}+SS_{\text{between}} +2\sum_{i=1}^{3}(\bar{Y}_{i\cdot}-\bar{Y}_{\cdot\cdot}) \sum_{j=1}^{n_i}(Y_{ij}-\bar{Y}_{i\cdot})\\ &=SS_{\text{within}}+SS_{\text{between}}. \end{aligned} $$

The same structure explains the degrees of freedom. The total has \(N-1\); estimating three group means uses three degrees of freedom for within-group error, leaving \(N-3\). The between-groups component has \(3-1=2\). Thus the table should satisfy \(2+(N-3)=N-1\), as well as \(SS_{\text{total}}=SS_{\text{between}}+SS_{\text{within}}\).

Unequal Group Sizes Still Use the Same Recipe

With unequal group sizes, do not average the group means without weights. Compute the grand mean from the total of all observations divided by \(N\), or equivalently weight each group mean by its sample size. The between-groups sum of squares also retains the factor \(n_i\); omitting it incorrectly treats a small group and a large group as equally influential.

Worked Example: Unequal Raw Sample Sizes

Three hypothetical calibration settings produce readings: Setting A: \(7,8,9\); Setting B: \(9,9,11,11\); Setting C: \(11,13\). Test whether the mean readings are equal at the \(0.05\) level, assuming independent normal observations with a common variance.

Method and summaries. The sample sizes are \(3,4,2\), so \(N=9\). The group sums are \(24,40,24\), and the means are \(8,10,12\). The overall sum is \(88\), giving the weighted grand mean \(88/9\), not the unweighted average \((8+10+12)/3=10\).

Within-groups sum of squares. Setting A has deviations \(-1,0,1\), so its squared deviations sum to \(2\). Setting B has deviations \(-1,-1,1,1\), so its contribution is \(4\). Setting C has deviations \(-1,1\), so its contribution is \(2\). Hence \(SS_{\text{within}}=2+4+2=8\).

Between-groups sum of squares. The deviations of the means from \(88/9\) are \(-16/9,-8/9,20/9\). Weight each squared deviation by its group size:

$$ SS_{\text{between}} =3\left(\frac{-16}{9}\right)^2 +4\left(\frac{-8}{9}\right)^2 +2\left(\frac{20}{9}\right)^2 =\frac{768+256+800}{81} =\frac{1824}{81} =\frac{608}{27}. $$

Check the arithmetic: \(768+256+800=1824\), and \(1824/81=608/27\approx22.5185\). The total sum of squares is \(608/27+8=824/27\approx30.5185\).

ANOVA quantities and conclusion. The degrees of freedom are \(2\) between groups, \(9-3=6\) within groups, and \(8\) total. Thus \(MS_{\text{between}}=(608/27)/2=304/27\), \(MS_{\text{within}}=8/6=4/3\), and \(F=(304/27)/(4/3)=76/9\approx8.4444\). For \(F(2,6)\), the p-value is \(\left(6/(6+2(76/9))\right)^3=(27/95)^3\approx0.0229\). Since this is below \(0.05\), reject equality of all three means. The result is evidence that at least one setting has a different mean reading.

Mistake avoided. The unweighted grand mean of \(10\) is incorrect because the groups have different sizes. Weighting is also required in the between-groups sum of squares; using \(\sum_i(\bar{Y}_{i\cdot}-\bar{Y}_{\cdot\cdot})^2\) without \(n_i\) does not give the ANOVA partition.

Interpret the F Statistic and the Conclusion Carefully

The mean square between groups estimates variation associated with differences among the group means, together with random error. The within-groups mean square estimates the common error variance under the model. A large ratio means the between-group variation is large relative to the within-group variation. Under the null hypothesis and the stated assumptions, that ratio follows the \(F\) distribution with \(k-1\) numerator degrees of freedom and \(N-k\) denominator degrees of freedom.

The p-value is the probability, assuming equal population means and the model, of obtaining an F statistic at least as large as the observed statistic. It is not the probability that the null hypothesis is true. A small p-value supports rejecting equal means, but it does not say which groups differ or how large a practically meaningful difference is. Those questions require additional inference.

Before reporting a result, check that the raw observations were assigned to the correct independent units and groups. Repeated measurements on one unit do not automatically count as independent observations. Also verify both arithmetic identities: the sums of squares add to the total, and the degrees of freedom add to \(N-1\). These checks catch many transcription and calculation errors before they affect the conclusion.

Worked Example: A Non-Significant Result With Unequal Sizes

A hypothetical environmental team records concentration measurements under three sampling protocols: A: \(7,8,9\); B: \(9,10,11,10\); C: \(11,12\). Assume the observations meet the one-way ANOVA assumptions. Complete the test at significance level \(0.05\).

Method and summaries. The group sizes are \(3,4,2\), with sums \(24,40,23\) and means \(8,10,11.5\). The total is \(87\), so \(N=9\) and the grand mean is \(87/9=29/3\).

Within-groups variation. Group A contributes \((7-8)^2+(8-8)^2+(9-8)^2=2\). Group B contributes \((9-10)^2+(10-10)^2+(11-10)^2+(10-10)^2=2\). Group C contributes \((11-11.5)^2+(12-11.5)^2=0.25+0.25=0.5\). Therefore \(SS_{\text{within}}=4.5\).

Between-groups variation. The means differ from \(29/3\) by \(-5/3,1/3,5/6\). Therefore \(SS_{\text{between}}=3(25/9)+4(1/9)+2(25/36)=25/3+4/9+25/18=77/6\). The total is \(77/6+4.5=52/3\).

Test and decision. The degrees of freedom are \(2,6,8\). The mean squares are \(MS_{\text{between}}=(77/6)/2=77/12\) and \(MS_{\text{within}}=4.5/6=3/4\). Thus \(F=(77/12)/(3/4)=77/9\approx8.5556\). The upper-tail probability for \(F(2,6)\) is \(\left(6/(6+2(77/9))\right)^3=(27/104)^3\approx0.0175\). Since \(0.0175<0.05\), reject equality of the three means; the data provide evidence that not all protocol means are equal.

Mistake avoided. A non-significant decision should not be substituted automatically just because the group means look close. Here the F statistic and its p-value determine the decision. The observations and computed quantities show that this particular result is statistically significant at \(0.05\).

Common Calculation Traps

  • Using the wrong grand mean. For unequal sample sizes, average all observations or use the size-weighted group means.
  • Forgetting the group-size weight. Each group contributes \(n_i(\bar{Y}_{i\cdot}-\bar{Y}_{\cdot\cdot})^2\) to between-groups variation.
  • Confusing sums of squares and mean squares. Divide between and within sums of squares by their respective degrees of freedom before forming F.
  • Using the wrong F degrees of freedom. With three groups and \(N\) observations, use numerator degrees of freedom \(2\) and denominator degrees of freedom \(N-3\).
  • Overstating the conclusion. Rejection means the group means are not all equal; the omnibus test does not identify a particular pair or prove practical importance.

Check Your Understanding

For each problem, use the raw observations to calculate the requested ANOVA quantities. Unless stated otherwise, assume independent normal observations with equal group variances.

  1. Three independent training formats produce scores: A: \(2,3,4\); B: \(3,4,5\); C: \(4,5,6\). Find the group means, sums of squares, F statistic, and p-value. (Answer: Means \(3,4,5\); \(SS_{\text{between}}=6\), \(SS_{\text{within}}=6\), \(F=3\) with degrees of freedom \(2,6\), p-value \(0.1250\).)
  2. Three hypothetical device designs have measurements A: \(1,3\); B: \(3,5\); C: \(5,7\). Find the grand mean, ANOVA F statistic, and p-value. (Answer: Grand mean \(4\); \(SS_{\text{between}}=16\), \(SS_{\text{within}}=6\); \(F=4\) with degrees of freedom \(2,3\), p-value \((3/11)^{3/2}\approx0.1424\).)
  3. Three groups of unequal sizes have observations A: \(2,4\); B: \(3,4,5\); C: \(5,7\). Calculate the weighted grand mean, both sums of squares, F statistic, and p-value. (Answer: Grand mean \(30/7\); \(SS_{\text{between}}=66/7\), \(SS_{\text{within}}=6\); \(F=22/7\) with degrees of freedom \(2,4\), p-value \(49/324\approx0.1512\).)
  4. Three independent batches give readings A: \(4,5,6\); B: \(5,6,7\); C: \(6,7,8\). At level \(0.05\), calculate the ANOVA test and state the conclusion in context. (Answer: Group means \(5,6,7\); \(SS_{\text{between}}=6\), \(SS_{\text{within}}=6\); \(F=3\) with degrees of freedom \(2,6\), p-value \(0.1250\); do not reject equality of the three batch means.)
Clinical Biostats