Introduction
A categorical predictor can describe several group means, but a research question often asks for one particular comparison among them. For example, the question might be whether the average fitted outcome in two treatment groups is higher or lower than the fitted outcome in a control group. A custom contrast expresses that planned comparison as weights on the group means.
The weights make the comparison explicit: which groups contribute, in what proportions, and in which direction. Once the group means are fitted, multiplying each mean by its weight and adding the results gives the fitted difference requested by the question.
Model and Definition
Suppose a categorical predictor has \(K\) groups. Let \(\mu_j\) denote the mean outcome for group \(j\), and let \(\hat{\mu}_j\) denote its fitted mean. A group-means model represents the outcome for observation \(i\) in group \(j\) as
Here, \(\varepsilon_{ij}\) is the error for that observation. For the standard linear-model interpretation, assume errors have mean zero, are independent across observational units, and have a common variance. Normality is additionally needed for exact small-sample inference using the usual t procedures, but not to calculate the fitted group means or their contrast. The contrast calculations below concern fitted means, not a test or confidence interval.
The zero-sum condition makes the expression a comparison rather than a weighted overall level: adding the same constant to every group mean does not change the contrast. The weights are chosen to match the question, not automatically to match the number of observations in each group.
Translating a Planned Comparison into Weights
First write the comparison in words or as a difference of averages. Then assign a positive weight to the groups on the first side and a negative weight to those on the second side. Groups not involved receive weight zero. For example, with a control group \(C\) and two treatment groups \(A\) and \(B\), the average treatment mean minus the control mean is
In the order \(C,A,B\), the weights are \((-1,\frac{1}{2},\frac{1}{2})\). They sum to zero, as a contrast’s weights must. This ordering matters: each weight must be attached to the intended category.
State the comparison as one group mean, or an average of means, minus another group mean or average.
Use positive weights for the first part of the difference and negative weights for the second. Give uninvolved groups weight zero.
Add them. A zero sum confirms that the expression compares group means rather than describing an overall level.
Multiply each fitted mean by its weight and add the products. The result has the outcome’s units.
Why the Fitted Group Means Are Used
In a group-means model, the fitted mean for a group is its sample mean. This follows directly from least squares. For group \(j\), the sum of squared residuals as a function of a proposed mean \(m\) is \(\sum_i(Y_{ij}-m)^2\). Differentiating with respect to \(m\) and setting the derivative to zero gives
Thus, the fitted contrast is calculated by applying the planned weights to the fitted group means. A different full-rank coding of the categorical predictor can use different coefficient values, but if it represents the same group means, this contrast of fitted means is unchanged. The contrast weights are weights on the means; they should not be confused with coefficients from an arbitrary coding.
Worked Example: Two Treatment Groups Versus a Control
Imagine a hypothetical experiment recording a symptom score in points. The fitted means are 18 points for control, 24 points for treatment A, and 28 points for treatment B. The planned comparison is the average of the two treatment means minus the control mean. Assume each observation is an independent unit measured on the same score scale. The group means alone cannot establish whether the common-variance assumption is reasonable; that would require examining the data or residuals. The following calculation is a fitted difference, not a claim that treatment caused a change.
In the order control, A, B, the weights are \((-1,\frac{1}{2},\frac{1}{2})\). Their sum is \(-1+\frac{1}{2}+\frac{1}{2}=0\). Applying the weights gives
Equivalently, the treatment average is \((24+28)/2=26\) points, and \(26-18=8\) points. The fitted mean for the two treatments, averaged equally as specified, is 8 points higher than the fitted control mean.
What the Weights Say About the Comparison
For an average of \(r\) groups compared with an average of \(s\) other groups, give each group in the first average weight \(1/r\), and each group in the second average weight \(-1/s\). These weights sum to \(r(1/r)+s(-1/s)=1-1=0\). This rule describes an equal average of group means. If the question instead specifies unequal weights, use those weights as stated and ensure that the positive and negative parts each have the intended total weight.
The scale of a contrast also matters. Multiplying every weight by the same nonzero number produces a rescaled contrast with the same zero-versus-nonzero comparison, but its numerical value changes by that factor. For example, \((-1,\frac{1}{2},\frac{1}{2})\) gives the treatment average minus control; \((-2,1,1)\) gives twice that difference. Use weights whose scale matches the comparison you want to report.
Worked Example: Equal Group Averages With Unequal Sample Sizes
Consider hypothetical outcome measurements in three independent groups: a control group with 40 observations and fitted mean 10 units, treatment A with 8 observations and fitted mean 14 units, and treatment B with 32 observations and fitted mean 18 units. The intended comparison is the equal average of the two treatment group means minus the control mean. Assume the groups used the same outcome measurement and that the observations are independent. The summaries do not show whether group variances are similar; that assumption is not needed for this point-contrast arithmetic.
The comparison assigns equal weight to the two treatment means, regardless of the group sizes. In the order control, A, B, the weights are \((-1,\frac{1}{2},\frac{1}{2})\), which sum to zero. Therefore,
The specified equal average is \((14+18)/2=16\) units, which is 6 units above the control mean of 10 units.
A different question would compare the pooled average across all treatment observations with control. That pooled treatment mean is weighted by sample sizes:
This pooled mean is \(17.2-10=7.2\) units above control, not 6 units. The two calculations differ because they target different averages. The planned comparison determines the weights; unequal sample sizes do not silently change an equal average of group means into a pooled average.
Worked Example: Comparing Two Pairs of Groups
Suppose four hypothetical program groups have fitted outcome means, in units, of 30 for program A, 34 for program B, 25 for program C, and 27 for program D. The planned comparison is the average of A and B minus the average of C and D. Assume independent observational units and the same outcome definition across groups. As with the earlier examples, these means alone do not allow assessment of equal error variance.
In the order A, B, C, D, the contrast weights are \((\frac{1}{2},\frac{1}{2},-\frac{1}{2},-\frac{1}{2})\). The weights sum to \(\frac{1}{2}+\frac{1}{2}-\frac{1}{2}-\frac{1}{2}=0\). The fitted contrast is
The average fitted mean for A and B is 32 units; the average for C and D is 26 units. Their difference is 6 units. Each group receives a nonzero weight because all four are part of the planned comparison. The positive result indicates that the first pair’s average fitted mean is higher.
Common Mistakes
- Forgetting to divide within an average. The weights \((-1,1,1)\) compare the sum of two group means with the control mean. The weights \((-1,\frac{1}{2},\frac{1}{2})\) compare their average with control.
- Using group sizes when the plan calls for equal group means. Sample-size weighting answers a pooled-observation question. It is not automatically the same as averaging the group means equally.
- Failing to check the sum. If weights do not sum to zero, the expression is not a contrast of the group means as defined here. Revisit the comparison and its scale.
- Misplacing a weight. List the category order beside the weights before calculating. A correct set of numbers attached to the wrong groups describes a different comparison.
- Reading the contrast as a causal effect. A fitted difference summarizes modeled group means. By itself it does not show that group membership caused the difference.
Check Your Understanding
For each question, identify the weights or explain the comparison in context.
- In the order control, low dose, high dose, what weights express the average of the two dose-group means minus the control mean? Verify that they sum to zero.
- Three groups have fitted means 12, 15, and 21 units. Calculate the average of the second and third means minus the first mean.
- A planned comparison gives weights \((1,-1,0)\) for groups A, B, and C. What fitted difference does this represent, and why does the third group contribute nothing?
- Two treatment groups have different sample sizes. Explain why an equal average of their fitted group means need not equal the pooled mean across all treatment observations.
- Why does multiplying every contrast weight by 2 change the numerical contrast but not the underlying zero-versus-nonzero comparison?