Skip to content
QDA2 Lab

MODULE 08

ANOVA Mathematics Lab

Slow down and calculate: what ANOVA compares, step by step.

Examples on this page use constructed or simulated teaching data, not empirical findings. About the data

  1. Research question
  2. Variables (trained here)
  3. Variable roles
  4. Measurement levels (trained here)
  5. Method choice (trained here)
  6. Statistical logic (trained here)
  7. SPSS workflow (trained here)
  8. Output interpretation (trained here)
  9. Defensible conclusion (trained here)

Understand

One question behind every method

How different is what we observe from what we would expect if the pattern were absent?

Crosstab

Observed counts versus expected counts under independence.

χ² and Cramér’s V

Correlation

Two variables moving together, relative to their own spread.

Pearson r; Spearman ρ

ANOVA

Distance between group means, relative to variation within groups.

F; η²

Understand

First: the math behind last week’s methods

Every number below is calculated step by step, with the reason for each step in words. These are small constructed teaching datasets, not findings from the homework.

Reading the formulas

Every formula below is just a recipe. These six symbols are all you need; each step also says the recipe in words.

Σ\Sigma
“Add up”: do the calculation for every row (person or cell), then sum the results.
xˉ\bar{x}
The mean of x (read “x-bar”): add up the values and divide by how many there are.
n, Nn,\ N
Number of cases: n in a group, N in the whole sample.
(…)2(\ldots)^2
Square: multiply a number by itself. It turns negative distances positive, so distances above and below the mean do not cancel out.
…\sqrt{\ldots}
Square root: undoes a square, bringing the result back to the original scale.
xi, yijx_i,\ y_{ij}
Subscripts name a case: xix_i is person i’s value; yijy_{ij} is person i in group j.

A. From a crosstab to χ² and Cramér’s V

60 students are grouped by how intensively they studied (X) and whether they passed the exam (Y). The question: is passing associated with study intensity?

Observed counts (O)
Study intensityFailedPassedRow total
Low12820
Medium81220
High41620
Column total243660
  1. Step 1: Look at the pattern: row percentages

    X is in the rows, so we compute percentages within each row. That tells us what share of each study group passed.

    pass rate=passedrow totalLow: 820=40%Medium: 1220=60%High: 1620=80%\begin{gathered}\text{pass rate} = \frac{\text{passed}}{\text{row total}} \\[6pt] \text{Low: } \frac{8}{20} = 40\% \qquad \text{Medium: } \frac{12}{20} = 60\% \qquad \text{High: } \frac{16}{20} = 80\%\end{gathered}

    The pass rate rises with study intensity. The rest of the calculation asks two things: could a pattern like this easily arise by chance (χ², p), and how strong is it (V)?

  2. Step 2: Imagine there were no association: expected counts

    Overall, 36 of 60 students passed (60%). If study intensity made no difference, every group would have that same pass rate: 60% of 20 = 12 passed and 8 failed in each group. These are the expected counts (E). The general recipe:

    E=row total×column totalNe.g. ELow, failed=20×2460=8\begin{gathered}E = \frac{\text{row total} \times \text{column total}}{N} \\[6pt] \text{e.g. } E_{\text{Low, failed}} = \frac{20 \times 24}{60} = 8\end{gathered}
    Expected counts (E) if there were no association
    Study intensityFailedPassed
    Low812
    Medium812
    High812
  3. Step 3: Measure the gap in every cell, then add up: χ²

    For each cell: take observed minus expected, square it (so negative gaps do not cancel positive ones), and divide by the expected count (a gap of 4 matters more when we expected 8 than when we expected 800).

    χ2=∑cells(O−E)2E\chi^2 = \sum_{\text{cells}} \frac{(O - E)^2}{E}
    CellOEO − E(O − E)²(O − E)² / E
    Low, failed1284162.000
    Low, passed812−4161.333
    Medium, failed88000.000
    Medium, passed1212000.000
    High, failed48−4162.000
    High, passed16124161.333
    Sum = χ²6.667
  4. Step 4: Is χ² large enough? Degrees of freedom and p

    The degrees of freedom count how many cells can vary freely once the totals are fixed. With 3 rows and 2 columns:

    df=(rows−1)(columns−1)=(3−1)(2−1)=2\begin{aligned} df &= (\text{rows} - 1)(\text{columns} - 1) \\ &= (3 - 1)(2 - 1) = 2 \end{aligned}

    With df = 2, χ² values above 5.991 occur in fewer than 5% of samples when there is no association in the population. Our 6.667 is above that, so p < .05. SPSS gives the exact value (Asymptotic Significance): p = .036.

    Optional: for df = 2 only, there is a shortcut that gives the exact p by hand: p=e−χ2/2=e−6.667/2≈0.036p = e^{-\chi^2/2} = e^{-6.667/2} \approx 0.036.

  5. Step 5: How strong? Cramér’s V

    χ² grows with the sample size: doubling every count doubles χ². Cramér’s V removes the sample size so the result always lies between 0 (no association) and 1 (perfect association). Here k is the smaller of the number of rows and columns (k = 2), so k − 1 = 1.

    V=χ2N (k−1)=6.66760×1=0.1111=0.333\begin{aligned} V &= \sqrt{\frac{\chi^2}{N\,(k - 1)}} \\[4pt] &= \sqrt{\frac{6.667}{60 \times 1}} = \sqrt{0.1111} \\[4pt] &= 0.333 \end{aligned}

What we can say

Study intensity and passing are associated (χ²(2) = 6.67, p = .036, V = .33). The p-value tests independence; V describes the strength; the row percentages show the direction. None of these shows that studying more causes passing.

B. Pearson and Spearman, one row at a time

Six students: weekly study hours (x) and exam score (y). Pearson’s r uses the original numbers; Spearman’s ρ uses only their ranks.

  1. Step 1: Find the two means

    xˉ=1+2+3+4+5+66=216=3.5yˉ=50+52+61+59+68+756=3656=60.833\begin{gathered} \bar{x} = \frac{1 + 2 + 3 + 4 + 5 + 6}{6} = \frac{21}{6} = 3.5 \\[8pt] \bar{y} = \frac{50 + 52 + 61 + 59 + 68 + 75}{6} = \frac{365}{6} = 60.833 \end{gathered}
  2. Step 2: How far is each student from the means, and do the distances point the same way?

    For each student, subtract the mean from both values. Then multiply the two distances. If a student is above average on both (or below on both), the product is positive; if above on one and below on the other, it is negative. Mostly positive products mean a positive association.

    Studentxxyyx−xˉx - \bar{x}y−yˉy - \bar{y}(x−xˉ)(y−yˉ)(x - \bar{x})(y - \bar{y})(x−xˉ)2(x - \bar{x})^2(y−yˉ)2(y - \bar{y})^2
    1150−2.5−10.833+27.0836.25117.361
    2252−1.5−8.833+13.2502.2578.028
    3361−0.5+0.167−0.0830.250.028
    4459+0.5−1.833−0.9170.253.361
    5568+1.5+7.167+10.7502.2551.361
    6675+2.5+14.167+35.4176.25200.694
    Sum0085.517.5450.833

    The distances themselves always add up to 0; that is why we need products and squares.

  3. Step 3: Put the sums into the formula

    The top of the fraction is the shared movement of x and y. The bottom rescales it by how much each variable varies on its own, which forces r between −1 and +1.

    r=∑(xi−xˉ)(yi−yˉ)∑(xi−xˉ)2⋅∑(yi−yˉ)2=85.517.5×450.833=85.57,889.583=85.588.823=0.963\begin{aligned} r &= \frac{\sum (x_i - \bar{x})(y_i - \bar{y})}{\sqrt{\sum (x_i - \bar{x})^2 \cdot \sum (y_i - \bar{y})^2}} \\[6pt] &= \frac{85.5}{\sqrt{17.5 \times 450.833}} = \frac{85.5}{\sqrt{7{,}889.583}} \\[6pt] &= \frac{85.5}{88.823} = 0.963 \end{aligned}
  4. Step 4: Spearman: replace values with ranks

    Rank each variable separately (smallest = 1). Then take the difference between the two ranks for each student (d) and square it.

    Studentxrank of xyrank of ydd²
    11150100
    22252200
    333614−11
    44459311
    55568500
    66675600
    Sum2

    Only students 3 and 4 swap places in the ranking. With no tied values, the recipe is:

    ρ=1−6∑di2n (n2−1)=1−6×26×(36−1)=1−12210=1−0.057=0.943\begin{aligned} \rho &= 1 - \frac{6 \sum d_i^2}{n\,(n^2 - 1)} \\[6pt] &= 1 - \frac{6 \times 2}{6 \times (36 - 1)} = 1 - \frac{12}{210} \\[6pt] &= 1 - 0.057 = 0.943 \end{aligned}

    With tied values, SPSS gives the tied cases the average of their ranks and computes Pearson’s r on the ranks; the result is then slightly different from this shortcut.

What we can say

Both coefficients show a strong positive association (r = .96, ρ = .94): students who studied more tended to score higher. Correlation is not proof of causation; always look at the scatterplot and the variable coding.

Try

Now derive ANOVA from eleven observations

Eleven people in three groups, as in the calculation video. Follow the nine steps with pen and paper: each one says what we calculate and why.

Group 1

45, 61, 53, 73

n = 4

Group 2

20, 14, 17

n = 3

Group 3

22, 32, 26, 21

n = 4

The step-by-step derivation

  1. Step 1: Mean of each group

    Add up the values in each group and divide by the number of people in that group.

    yˉ1=45+61+53+734=2324=58yˉ2=20+14+173=513=17yˉ3=22+32+26+214=1014=25.25\begin{gathered}\bar{y}_1 = \frac{45 + 61 + 53 + 73}{4} = \frac{232}{4} = 58 \\[4pt] \bar{y}_2 = \frac{20 + 14 + 17}{3} = \frac{51}{3} = 17 \\[4pt] \bar{y}_3 = \frac{22 + 32 + 26 + 21}{4} = \frac{101}{4} = 25.25\end{gathered}
  2. Step 2: Grand mean: the mean of all eleven people

    Add up every observation and divide by N = 11. Note this is not the average of the three group means (33.417), because the groups have different sizes.

    yˉ=∑yN=232+51+10111=38411=34.909\begin{aligned} \bar{y} &= \frac{\sum y}{N} = \frac{232 + 51 + 101}{11} \\[6pt] &= \frac{384}{11} = 34.909 \end{aligned}
  3. Step 3: Two distances for every person

    For each person we measure two distances and square them: from their own group mean (how far they are from people in the same group) and from the grand mean (how far they are from everyone). Adding up a squared column gives a sum of squares (SS): the first is SS Within, the second SS Total.

    Groupyyyˉj\bar{y}_jy−yˉjy - \bar{y}_j(y−yˉj)2(y - \bar{y}_j)^2y−yˉy - \bar{y}(y−yˉ)2(y - \bar{y})^2
    14558.00−13.00169+10.091101.826
    16158.00+3.009+26.091680.736
    15358.00−5.0025+18.091327.281
    17358.00+15.00225+38.0911,450.917
    22017.00+3.009−14.909222.281
    21417.00−3.009−20.909437.190
    21717.000.000−17.909320.736
    32225.25−3.2510.5625−12.909166.645
    33225.25+6.7545.5625−2.9098.463
    32625.25+0.750.5625−8.90979.372
    32125.25−4.2518.0625−13.909193.463
    Sum0520.7503,988.909
    SSWithin=∑j∑i(yij−yˉj)2=520.75SSTotal=∑j∑i(yij−yˉ)2=3,988.909\begin{gathered} SS_{\text{Within}} = \sum_j \sum_i (y_{ij} - \bar{y}_j)^2 = 520.75 \\[8pt] SS_{\text{Total}} = \sum_j \sum_i (y_{ij} - \bar{y})^2 = 3{,}988.909 \end{gathered}

    SS Within is the variation that group membership cannot explain: people differ even inside their own group. SS Total is all the variation in the data.

  4. Step 4: Between-group variation: how far are the group means from the grand mean?

    Every person in a group “carries” their group’s distance from the grand mean, so we multiply each squared distance by the group size nj.

    Groupnjn_jyˉj\bar{y}_jyˉj−yˉ\bar{y}_j - \bar{y}(yˉj−yˉ)2(\bar{y}_j - \bar{y})^2nj(yˉj−yˉ)2n_j(\bar{y}_j - \bar{y})^2
    1458.00+23.091533.1902,132.760
    2317.00−17.909320.736962.207
    3425.25−9.65993.298373.192
    Sum3,468.159
    SSBetween=∑jnj(yˉj−yˉ)2=2,132.760+962.207+373.192=3,468.159\begin{aligned} SS_{\text{Between}} &= \sum_j n_j (\bar{y}_j - \bar{y})^2 \\ &= 2{,}132.760 + 962.207 + 373.192 \\ &= 3{,}468.159 \end{aligned}
  5. Step 5: Check: the two parts add up to the total

    This is the core idea of ANOVA: all variation splits into a part between the groups and a part within them.

    SSTotal=SSBetween+SSWithin3,988.909=3,468.159+520.750\begin{gathered} SS_{\text{Total}} = SS_{\text{Between}} + SS_{\text{Within}} \\[4pt] 3{,}988.909 = 3{,}468.159 + 520.750 \end{gathered}
  6. Step 6: Degrees of freedom

    Sums of squares grow simply because more numbers are added up. To compare them fairly, we divide by their degrees of freedom: the number of independent pieces of information in each part. With k = 3 groups and N = 11 people:

    dfBetween=k−1=3−1=2dfWithin=N−k=11−3=8dfTotal=N−1=10\begin{aligned} df_{\text{Between}} &= k - 1 = 3 - 1 = 2 \\ df_{\text{Within}} &= N - k = 11 - 3 = 8 \\ df_{\text{Total}} &= N - 1 = 10 \end{aligned}
  7. Step 7: Mean squares and the F ratio

    A mean square (MS) is a sum of squares divided by its degrees of freedom: an average squared distance. F compares the two averages. If the groups did not differ in the population, the group means would scatter only about as much as individual noise allows, and F would be close to 1. A large F means the group means are much further apart than the within-group scatter would suggest.

    MSBetween=SSBetweendfBetween=3,468.1592=1,734.080MSWithin=SSWithindfWithin=520.758=65.094F=MSBetweenMSWithin=1,734.08065.094=26.64\begin{aligned} MS_{\text{Between}} &= \frac{SS_{\text{Between}}}{df_{\text{Between}}} = \frac{3{,}468.159}{2} = 1{,}734.080 \\[8pt] MS_{\text{Within}} &= \frac{SS_{\text{Within}}}{df_{\text{Within}}} = \frac{520.75}{8} = 65.094 \\[8pt] F &= \frac{MS_{\text{Between}}}{MS_{\text{Within}}} = \frac{1{,}734.080}{65.094} = 26.64 \end{aligned}
  8. Step 8: Is F large enough? The p-value

    For F with df = (2, 8), values above 4.459 occur in fewer than 5% of samples if the population means are equal; values above 18.49 occur in fewer than 0.1%. Our F = 26.64 is above both, so p < .001. The exact value is p = .00029; SPSS rounds it and prints Sig. = .000, which you report as p < .001.

  9. Step 9: Effect size: eta squared

    What share of all the variation lies between the groups?

    η2=SSBetweenSSTotal=3,468.1593,988.909=0.869\eta^2 = \frac{SS_{\text{Between}}}{SS_{\text{Total}}} = \frac{3{,}468.159}{3{,}988.909} = 0.869

    About 87% of the variation in this sample is associated with group membership. That is a description of the sample, not proof that the groups cause the differences.

ANOVA (the same numbers as SPSS prints them)
Sum of SquaresdfMean SquareFSig.
Between Groups3,468.15921,734.08026.640.000
Within Groups520.750865.094
Total3,988.90910

Now change the data

Move the groups. Watch the sums of squares.

The starting values reproduce the 11 observations of the ANOVA calculation video. Moving the sliders creates a teaching simulation, not new survey data.

0

Moves Group 1 up and Group 2 down (negative values move them towards each other).

1.0×

Moves individuals towards or away from their own group mean.

020406080100Group 1Group 2Group 3

Dots = observations; thick lines = group means; dashed line = grand mean (34.91).

Between SS 3,468.16, within SS 520.75, total SS 3,988.91, F 26.64 with df 2 and 8, eta squared 0.869.

Within SS

520.75

Between SS

3,468.16

F (df 2, 8)

26.64

Eta squared

0.869

SourceSSdfMS
Between groups3,468.1621,734.08
Within groups520.75865.09
Total3,988.9110—

Check the identity: 3,468.16 + 520.75 = 3,988.91. Separating the group means increases the between-group SS; spreading individuals around their own group mean increases the within-group SS, and F falls. This simulation does not compute p-values; the classical F test also relies on its assumptions.

Live recalculation of the original data: F = 26.640, η² = 0.869.

SPSS

Translate the calculation into an SPSS decision

Before pressing Analyze, identify the outcome, factor, observational unit and relevant assumptions.
  1. Scale outcome (Y) and one categorical group variable (X): one-way ANOVA.
  2. SPSS: Analyze → Compare Means → One-Way ANOVA. Request Descriptives, homogeneity of variance, and Welch.
  3. Check sample sizes, missing-value codes, outliers, independence and the within-group distribution.
  4. Use Levene as a diagnostic, not as proof of equal variances. If group variances differ materially, Welch’s ANOVA is a useful alternative.
  5. An omnibus significant result says at least one group mean differs; use suitable post-hoc comparisons to locate differences (e.g. Tukey for the standard setting, Games–Howell under unequal variances).
  6. Report the means, N, F or Welch test, degrees of freedom, p, and an appropriate effect size.

Do not mix up these four designs

Independent t-test: two independent groups, one outcome.

Paired t-test: two measurements of the same people (or matched pairs).

One-way ANOVA: one grouping factor, typically three or more independent groups (two also works).

Two-way ANOVA: two grouping factors; evaluates main effects and potentially their interaction.

Full sample vs subsamples: a stratified/control-variable analysis, not the definition of one-way versus two-way ANOVA.

A non-significant Levene test does not prove homoscedasticity. Overlapping separate 95% group-mean confidence intervals are not a reliable substitute for an adjusted pairwise comparison. Keep inference separate from effect size and causal claims.

Test yourself

Exit ticket: explain, don’t just calculate

Mastery check

0/0 correct on first attempt

Explain the calculation

The three groups have n = 4, 3, 4 and means 58, 17 and 25.25. Why is the grand mean 34.909 and not (58 + 17 + 25.25) / 3 = 33.417?

1 / 6

For extra interactive exercises, revisit crosstabs, correlation, or t-tests.