Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

One-Way ANOVA

Compare several treatment means by separating between-treatment variation from within-treatment error. This page covers the global test, equivalent model parameterizations, diagnostics, and the alternative framework for binary outcomes. Numerical examples use illustrative practice data.

At a Glance

Global question
Focused question

Are all treatment means equal? ANOVA provides one global test.

One-Way ANOVA

ANOVA compares one factor with mm treatment levels. The standard normal-response model is

Yij=μi+εij,εij∼iidN(0,σ2),N=∑i=1mni.Y_{ij}=\mu_i+\varepsilon_{ij},\qquad \varepsilon_{ij}\overset{\mathrm{iid}}{\sim}N(0,\sigma^2),\qquad N=\sum_{i=1}^m n_i.
H0:μ1=⋯=μm,HA:not all treatment means are equal.H_0:\mu_1=\cdots=\mu_m,\qquad H_A:\text{not all treatment means are equal}.

The alternative does not say that every pair differs.

Decomposing Variation

Define the group means Yˉi⋅\bar Y_{i\cdot} and the observation-weighted grand mean

Yˉ⋅⋅=1N∑iniYˉi⋅.\bar Y_{\cdot\cdot}=\frac1N\sum_i n_i\bar Y_{i\cdot}.
SST=∑i∑j(Yij−Yˉ⋅⋅)2,SSTr=∑ini(Yˉi⋅−Yˉ⋅⋅)2,SSE=∑i∑j(Yij−Yˉi⋅)2.\begin{aligned} SS_T&=\sum_i\sum_j(Y_{ij}-\bar Y_{\cdot\cdot})^2,\\ SS_{\mathrm{Tr}}&=\sum_i n_i(\bar Y_{i\cdot}-\bar Y_{\cdot\cdot})^2,\\ SS_E&=\sum_i\sum_j(Y_{ij}-\bar Y_{i\cdot})^2. \end{aligned}
SST=SSTr+SSE\boxed{SS_T=SS_{\mathrm{Tr}}+SS_E}

Treatment variation measures separation among group means. Error variation measures spread within each group. Some notation calls SSTrSS_{\mathrm{Tr}} “condition SS” or SSCSS_C.

Why the Sums of Squares Add Up

Write each deviation as

Yij−Yˉ⋅⋅=(Yij−Yˉi⋅)+(Yˉi⋅−Yˉ⋅⋅).Y_{ij}-\bar Y_{\cdot\cdot} =(Y_{ij}-\bar Y_{i\cdot})+(\bar Y_{i\cdot}-\bar Y_{\cdot\cdot}).

Square and sum. The cross term vanishes because, in each group,

∑j(Yij−Yˉi⋅)=0.\sum_j(Y_{ij}-\bar Y_{i\cdot})=0.

The remaining terms are exactly SSESS_E and SSTrSS_{\mathrm{Tr}}. The decomposition holds even when group sizes differ.

ANOVA Table

SourceSum of squaresdfMean squareTest
TreatmentSSTrSS_{\mathrm{Tr}}m−1m-1MSTr=SSTr/(m−1)MS_{\mathrm{Tr}}=SS_{\mathrm{Tr}}/(m-1)F=MSTr/MSEF=MS_{\mathrm{Tr}}/MSE
ErrorSSESS_EN−mN-mMSE=SSE/(N−m)MSE=SS_E/(N-m)
TotalSSTSS_TN−1N-1

Under H0H_0 and the model assumptions,

F∼Fm−1,N−m,p=P(Fm−1,N−m≥Fobs).F\sim F_{m-1,N-m},\qquad p=P(F_{m-1,N-m}\geq F_{\mathrm{obs}}).

Both mean squares estimate σ2\sigma^2 under the null. Separated treatment means increase the numerator, so rejection is in the right tail. This is a test about means, unlike the two-sample variance-ratio test.

For m=2m=2, this ANOVA test equals the two-sided pooled tt test, with F=t2F=t^2. It is not generally equivalent to Welch’s test.

Equivalent Model Parameterizations

The following models have the same fitted group means, residuals, and overall ANOVA test.

ModelFormInterpretation
MeansYij=μi+εijY_{ij}=\mu_i+\varepsilon_{ij}A parameter for each group mean.
EffectsYij=μ+τi+εijY_{ij}=\mu+\tau_i+\varepsilon_{ij}, ∑iτi=0\sum_i\tau_i=0Mean of treatment means plus deviations.
Reference-group regressionY=β0+∑k=2mβk−1I(group=k)+εY=\beta_0+\sum_{k=2}^m\beta_{k-1}I(\text{group}=k)+\varepsilonReference mean plus differences from it.

In the effects model with an unweighted sum-to-zero constraint,

μ=1m∑iμi,μ^=1m∑iYˉi⋅,τ^i=Yˉi⋅−μ^.\mu=\frac1m\sum_i\mu_i,\qquad \widehat\mu=\frac1m\sum_i\bar Y_{i\cdot},\qquad \widehat\tau_i=\bar Y_{i\cdot}-\widehat\mu.

For unequal group sizes, this average of group means is not necessarily the observation-weighted grand mean used in the ANOVA decomposition. With balanced groups, they coincide.

For A, B, C with A as the reference,

Y=β0+β1I(B)+β2I(C)+ε.Y=\beta_0+\beta_1I(B)+\beta_2I(C)+\varepsilon.

The worked example gives β^0=6\widehat\beta_0=6, β^1=2\widehat\beta_1=2, and β^2=5\widehat\beta_2=5. The global null is β1=β2=0\beta_1=\beta_2=0, with no requirement that the intercept be zero.

Avoid the dummy-variable trap: with an intercept, include only m−1m-1 group indicators. Alternatively, use all mm indicators without an intercept.

Residual Diagnostics & Other Response Types

For one-way ANOVA, fitted values are group means and residuals are

Y^ij=Yˉi⋅,eij=Yij−Yˉi⋅.\widehat Y_{ij}=\bar Y_{i\cdot},\qquad e_{ij}=Y_{ij}-\bar Y_{i\cdot}.
CheckWhat to look forImplication
Assignment and measurement designRepeated units, clusters, or matched observations.Independence must come from the design, not a normality plot.
Residual Q-Q plotStrong curvature or extreme tails.Normal-theory inference may be unreliable, especially with small samples.
Residuals vs. fitted valuesChanging spread across fitted groups.Common variance may be unsuitable.
Residuals vs. collection orderDrift, cycles, long runs.Time structure or omitted nuisance effects.
Unusual observationsRecording mistakes or exceptional conditions.Investigate context; do not remove points just to improve significance.

Normality tests can supplement plots but do not certify a model. With unequal variances, consider a heteroscedastic analysis such as Welch’s ANOVA. For strongly skewed outcomes, a meaningful transformation or a suitable response model may be preferable. Count outcomes may need a count model; binary outcomes need a proportions or binary-response analysis.

Binary Outcomes: Comparing Several Proportions

For treatment ii, let O1iO_{1i} be failures and O2iO_{2i} successes, with ni=O1i+O2in_i=O_{1i}+O_{2i}. Test

H0:π1=⋯=πm.H_0:\pi_1=\cdots=\pi_m.

Estimate the common success probability under the null:

π^=∑iO2iN,E1i=ni(1−π^),E2i=niπ^.\widehat\pi=\frac{\sum_iO_{2i}}N,\qquad E_{1i}=n_i(1-\widehat\pi),\quad E_{2i}=n_i\widehat\pi.
X2=∑i=1m∑r=12(Ori−Eri)2Eri ∼approx χm−12.X^2=\sum_{i=1}^m\sum_{r=1}^2\frac{(O_{ri}-E_{ri})^2}{E_{ri}} \ \overset{\mathrm{approx}}{\sim}\ \chi^2_{m-1}.

Use the right tail. This approximation requires independent observations and sufficiently large expected counts; sparse tables call for an appropriate exact or simulation-based method. The global test does not identify which proportions differ.