Home
/
Tutorials
/
VEE Mathematical Statistics / ANOVA Contrasts and Comparisons
VEE Mathematical Statistics · ANOVA Contrasts and Comparisons · Tutorial 818 of 880
Sums of Squares for Contrasts
Learn to compute a contrast sum of squares and understand when it represents a distinct component of treatment variation.
Advanced
10 min read
What You'll Learn
Define the contrast estimate and its variance factor for unequal group sizes
Derive the contrast sum of squares from a weighted projection
Calculate contrast sums of squares from group means and sample sizes
Compare a contrast sum of squares with the total treatment sum of squares
Recognize when contrast components do not add to the treatment sum of squares
Why a Contrast Has Its Own Sum of Squares
In a one-way analysis of variance, the treatment sum of squares measures how much the group means vary around the grand mean. A contrast focuses on one particular pattern of differences among those means. Its sum of squares measures how much treatment variation lies in that one direction. This gives a useful interpretation of a contrast as a one-degree-of-freedom component of treatment variation.
The calculation must account for the precision of each group mean. When group sizes differ, the variance of a contrast depends on both its coefficients and the group sizes. Dividing the squared estimated contrast by the appropriate variance factor handles that weighting.
Model and assumptions: There are \(k\) independent treatment groups. In group \(i\), the observations are independent and normally distributed with mean \(\mu_i\) and common variance \(\sigma^2\). Group \(i\) has sample size \(n_i\) and sample mean \(\bar Y_i\). The pooled within-group mean square estimates \(\sigma^2\). The contrast sum-of-squares formula below is an algebraic measure of treatment variation; for its usual exact inferential interpretation, the stated normal, independence, and common-variance assumptions are required.
Definition: A contrast of the treatment means is \(L=\sum_{i=1}^k c_i\mu_i\), where the fixed coefficients satisfy \(\sum_{i=1}^k c_i=0\). Its estimate is \(\hat L=\sum_{i=1}^k c_i\bar Y_i\). Define its variance factor as \(q=\sum_{i=1}^k c_i^2/n_i\). The contrast sum of squares is
$$
SS_L=\frac{\hat L^2}{q}.
$$
The zero-sum condition makes \(L\) a comparison among treatment means rather than a measure of their overall level. For example, coefficients \((-1,0,1)\) compare the third mean with the first. The variance factor \(q\) reflects the fact that a group mean based on a larger sample is more precise. In particular, under the model, \(\operatorname{Var}(\hat L)=\sigma^2q\).
Multiplying every coefficient by the same nonzero constant changes \(\hat L\) and \(q\), but not \(SS_L\): if the coefficients are multiplied by \(a\), then the new estimate is \(a\hat L\) and the new factor is \(a^2q\), so their ratio remains \(\hat L^2/q\). Thus, a contrast’s sum of squares depends on the comparison’s direction, not the arbitrary scale used to write its coefficients.
Why the Formula Gives a One-Degree-of-Freedom Component
Write the vector of group means as \(\bar{\mathbf Y}=(\bar Y_1,\ldots,\bar Y_k)^T\), and let \(W\) be the diagonal matrix with entries \(n_1,\ldots,n_k\). Treatment variation is measured with these weights: a deviation in a group mean contributes more when it is based on a larger group. The treatment sum of squares is
$$
SS_{\text{Tr}}=\sum_{i=1}^k n_i(\bar Y_i-\bar Y_{\cdot\cdot})^2,
\qquad
\bar Y_{\cdot\cdot}=\frac{\sum_{i=1}^k n_i\bar Y_i}{\sum_{i=1}^k n_i}.
$$
To identify the part of this variation in the direction of the contrast, use the weighted inner product \(x^TWy\). The direction associated with coefficient vector \(\mathbf c=(c_1,\ldots,c_k)^T\) is \(d=W^{-1}\mathbf c\). Its weighted squared length is
$$
d^TWd=\mathbf c^TW^{-1}\mathbf c=\sum_{i=1}^k\frac{c_i^2}{n_i}=q.
$$
Because \(\sum_i c_i=0\), this direction is weighted-orthogonal to the constant vector: \(\mathbf 1^TWd=\mathbf 1^T\mathbf c=0\). It is therefore a direction within treatment variation, not an overall shift of every mean.
The weighted projection of the centered group-mean vector onto \(d\) has coefficient \(\hat L/q\). Indeed, \(d^TW(\bar{\mathbf Y}-\bar Y_{\cdot\cdot}\mathbf 1)=\mathbf c^T\bar{\mathbf Y}=\hat L\), since the contrast coefficients sum to zero. The weighted squared length of that projection is therefore \(q(\hat L/q)^2\), which gives the formula.
$$
SS_L=\frac{\hat L^2}{q}.
$$
A single direction has one coordinate, so its projection accounts for one degree of freedom. This does not mean that every contrast exhausts treatment variation. In general, \(SS_L\) is one component of \(SS_{\text{Tr}}\), and it cannot exceed \(SS_{\text{Tr}}\). A collection of components adds to the treatment sum of squares when the corresponding contrast directions are mutually orthogonal under the group-size weights. Without that condition, the components need not add to the total.
Calculating a Contrast Sum of Squares
Worked Example: A Balanced Three-Group Comparison
A hypothetical study compares three treatments, with \(n_1=n_2=n_3=4\), sample means \((\bar Y_1,\bar Y_2,\bar Y_3)=(6,9,12)\), and contrast coefficients \((-1,0,1)\). Calculate \(\hat L\), \(q\), and \(SS_L\), then compare the result with the treatment sum of squares.
Method. Estimate the contrast by applying each coefficient to its corresponding sample mean, then calculate the variance factor from the sample sizes. The coefficient sum is \(-1+0+1=0\), so these coefficients define a contrast.
Estimated contrast.
$$
\hat L=(-1)(6)+(0)(9)+(1)(12)=-6+0+12=6.
$$
The contrast compares the third group mean with the first; the estimated difference is \(12-6=6\).
Contrast sum of squares.
$$
SS_L=\frac{6^2}{0.5}=\frac{36}{0.5}=72.
$$
Check against treatment variation. The grand mean is \((6+9+12)/3=9\), so
$$
SS_{\text{Tr}}=4(6-9)^2+4(9-9)^2+4(12-9)^2
=4(9)+0+4(9)=72.
$$
Here \(SS_L=SS_{\text{Tr}}\): the three group means vary in exactly the direction specified by this contrast. Common mistake avoided: the first term in \(\hat L\) is \((-1)(6)=-6\), but the final estimate is \(-6+12=6\), not \(-6\).
Worked Example: Unequal Group Sizes and a Curvature Contrast
A hypothetical three-treatment study has sample sizes \((5,10,5)\) and sample means \((8,10,15)\). Use coefficients \((-1,2,-1)\) to calculate the contrast sum of squares. The within-group sums of squares are \(16,18,\) and \(20\), respectively. Find the pooled error mean square and the contrast’s one-degree-of-freedom \(F\) ratio.
Method. First check that the coefficients sum to zero: \(-1+2-1=0\). Then calculate the estimate and variance factor using the unequal sample sizes.
Contrast sum of squares.
$$
SS_L=\frac{(-3)^2}{0.8}=\frac9{0.8}=11.25.
$$
The negative sign of \(\hat L\) indicates the direction of the estimated contrast, but the sum of squares is nonnegative because the estimate is squared.
Pooled error mean square. The total sample size is \(N=5+10+5=20\), and the number of groups is \(k=3\). The error degrees of freedom are \(N-k=17\). The pooled within-group sum of squares is \(16+18+20=54\), so
$$
MSE=\frac{54}{17}=3.176470\ldots.
$$
One-degree-of-freedom \(F\) ratio. The contrast mean square is \(SS_L/1=11.25\), giving
$$
F=\frac{11.25}{54/17}
=\frac{11.25(17)}{54}
=\frac{191.25}{54}
=3.541666\ldots\approx3.5417.
$$
The value is rounded to four decimal places. Under the stated model, this ratio is compared with an \(F\) distribution having \(1\) and \(17\) degrees of freedom.
Check. The treatment sum of squares is based on grand mean \((5(8)+10(10)+5(15))/20=10.75\):
$$
SS_{\text{Tr}}=5(8-10.75)^2+10(10-10.75)^2+5(15-10.75)^2
=37.8125+5.625+90.3125=133.75.
$$
Thus the contrast component \(11.25\) is less than the total treatment variation \(133.75\). Common mistake avoided: using \(c_i^2\) without dividing by \(n_i\) would ignore the unequal precision of the group means.
Worked Example: A Contrast Component Need Not Be the Whole Treatment Sum of Squares
A hypothetical study has three groups with sample sizes \((4,6,8)\) and means \((5,9,8)\). For coefficients \((1,-1,0)\), calculate the contrast sum of squares and the treatment sum of squares. Interpret the difference.
Method. This contrast compares the first two means and assigns coefficient zero to the third. Its coefficients sum to \(1-1+0=0\).
Contrast sum of squares.
$$
SS_L=\frac{(-4)^2}{5/12}
=16\left(\frac{12}{5}\right)
=\frac{192}{5}=38.4.
$$
Treatment sum of squares. The grand mean is
$$
\bar Y_{\cdot\cdot}=\frac{4(5)+6(9)+8(8)}{4+6+8}
=\frac{20+54+64}{18}
=\frac{138}{18}=\frac{23}{3}.
$$
The deviations from this mean are \(5-23/3=-8/3\), \(9-23/3=4/3\), and \(8-23/3=1/3\). Therefore,
$$
SS_{\text{Tr}}
=4\left(\frac{-8}{3}\right)^2
+6\left(\frac{4}{3}\right)^2
+8\left(\frac{1}{3}\right)^2
=\frac{256}{9}+\frac{96}{9}+\frac{8}{9}
=\frac{360}{9}=40.
$$
The contrast sum of squares \(38.4\) is less than the treatment sum of squares \(40\), leaving \(40-38.4=1.6\) units of treatment variation in another direction. Common mistake avoided: a contrast sum of squares is not automatically the entire treatment sum of squares; that happens only when the observed treatment-mean variation lies entirely in that contrast direction.
Practical Checks and Common Traps
A reliable calculation follows a short sequence: verify that the coefficients sum to zero, compute the signed estimate, calculate \(q\) using the matching group sizes, and then square the estimate and divide by \(q\). If the pooled error mean square is supplied or can be calculated, the contrast’s one-degree-of-freedom \(F\) ratio is \(SS_L/MSE\). The contrast sum of squares itself does not require an estimate of \(\sigma^2\).
Dropping a minus sign. Keep the signed value of \(\hat L\) through the sum. Square only after all terms have been added.
Using the wrong group size. Pair each \(c_i^2\) with the sample size from the same group in \(q=\sum c_i^2/n_i\).
Forgetting the zero-sum condition. If the coefficients do not sum to zero, the expression is not a contrast of treatment means as defined here.
Assuming all contrast components add. A single component is a projection in one direction. Multiple components sum to the treatment sum of squares only when the directions are mutually orthogonal under the group-size weights.
Confusing \(SS_L\) with its test ratio. The sum of squares is \(\hat L^2/q\); the \(F\) ratio additionally divides that sum of squares by \(MSE\).
Key takeaway: For a contrast with \(\sum_i c_i=0\), compute \(\hat L=\sum_i c_i\bar Y_i\) and \(q=\sum_i c_i^2/n_i\). Then \(SS_L=\hat L^2/q\) is the one-degree-of-freedom treatment component in that contrast direction.
Check Your Understanding
For each problem, calculate the requested contrast sum of squares. Keep track of the coefficient signs and use the sample size attached to each group.
A three-group study has sample sizes \((4,8,4)\), means \((3,6,11)\), and contrast coefficients \((-1,0,1)\). Find \(\hat L\), \(q\), and \(SS_L\). (Answer: \(\hat L=8,\ q=0.5,\ SS_L=128\))
Three groups have sample sizes \((3,6,9)\) and means \((4,7,9)\). For coefficients \((1,-1,0)\), calculate \(q\) and \(SS_L\). (Answer: \(q=0.5,\ SS_L=18\))
For sample sizes \((5,5,10)\), means \((12,15,18)\), and coefficients \((1,1,-2)\), find the contrast estimate, variance factor, and sum of squares. (Answer: \(\hat L=-9,\ q=0.8,\ SS_L=101.25\))
Four observations are taken in each of three groups, whose means are \((2,5,8)\). For coefficients \((-1,0,1)\), calculate \(SS_L\) and \(SS_{\text{Tr}}\). (Answer: \(SS_L=72,\ SS_{\text{Tr}}=72\))
Three groups have sample sizes \((2,4,6)\), means \((5,8,10)\), and contrast coefficients \((1,-2,1)\). Calculate \(\hat L\), \(q\), and \(SS_L\). (Answer: \(\hat L=-1,\ q=5/3,\ SS_L=0.6\))