Tutorials › VEE Mathematical Statistics › Confidence Intervals for Contrasts

VEE Mathematical Statistics · ANOVA Contrasts and Comparisons · Tutorial 816 of 880

Confidence Intervals for Contrasts

Build and interpret a confidence interval for a planned contrast using group means, sample sizes, pooled error, and the correct residual degrees of freedom.

Advanced 12 min read

What You'll Learn

  • Identify a linear contrast and estimate it from the sample group means.
  • Calculate the standard error of a contrast when group sizes are unequal.
  • Use the pooled ANOVA mean square error and residual degrees of freedom.
  • Construct a two-sided Student t confidence interval under the common-variance normal model.
  • Interpret the interval in context and avoid common degrees-of-freedom and scaling errors.

Why Use a Confidence Interval for a Contrast?

An omnibus ANOVA addresses whether all population means are equal, but often the question of interest is more specific: how much larger is one mean than another, or how does the average of one set of means compare with another? A linear contrast expresses such a comparison with coefficients whose sum is zero. A confidence interval estimates the size of that comparison and communicates the precision of the estimate.

This tutorial constructs a two-sided confidence interval for one contrast in a one-way ANOVA. It uses the pooled error estimate from the ANOVA model and a Student t critical value. The interval is exact under the independent, normal, common-variance model; outside those assumptions, its stated coverage need not hold.

Definition: For \(k\) populations with means \(\mu_1,\ldots,\mu_k\), a linear contrast is \(L=\sum_{i=1}^{k}c_i\mu_i\), where the fixed coefficients satisfy \(\sum_{i=1}^{k}c_i=0\). Its sample estimate is \(\hat L=\sum_{i=1}^{k}c_i\bar X_i\), where \(\bar X_i\) is the sample mean in group \(i\).

Model, Pooled Error, and the Interval Formula

Suppose there are \(k\) independent groups. Group \(i\) contains \(n_i\) observations \(X_{ij}\), for \(j=1,\ldots,n_i\). The model assumes that observations in group \(i\) are independent and normally distributed with mean \(\mu_i\) and the same unknown variance \(\sigma^2\):

$$ X_{ij}\sim N(\mu_i,\sigma^2),\qquad i=1,\ldots,k,\quad j=1,\ldots,n_i. $$

Write \(N=\sum_{i=1}^{k}n_i\) for the total sample size. The pooled within-group sum of squares is \(SSE=\sum_{i=1}^{k}\sum_{j=1}^{n_i}(X_{ij}-\bar X_i)^2\). Its degrees of freedom are \(N-k\), so the pooled mean square error is \(MSE=SSE/(N-k)\). This estimate combines within-group variation across all groups; the common-variance assumption is what makes pooling appropriate.

For one contrast, the estimated variance uses the coefficients and group sample sizes. Define \(V_c=\sum_{i=1}^{k}c_i^2/n_i\). Then the estimated standard error is \(\sqrt{MSE\,V_c}\). For a two-sided confidence level of \(100(1-\alpha)\%\), the interval is:

$$ \hat L\ \pm\ t_{1-\alpha/2,\,N-k}\sqrt{MSE\sum_{i=1}^{k}\frac{c_i^2}{n_i}}. $$

Here \(t_{1-\alpha/2,\,N-k}\) is the Student t quantile with \(N-k\) degrees of freedom that has cumulative probability \(1-\alpha/2\). The margin of error is that critical value multiplied by the estimated standard error. Unequal group sizes are handled by retaining each \(n_i\) in its own term; replacing them with a single average sample size generally gives the wrong standard error.

Why the Formula Has a Student t Critical Value

The formula follows from the sampling distribution of the contrast estimate and the pooled error estimate. Under the stated model, independent normal sample means have variances \(\sigma^2/n_i\). Therefore their weighted sum \(\hat L\) is normal, with mean \(L\) and variance \(\sigma^2\sum_i c_i^2/n_i\). Also, the within-group sum of squares, divided by \(\sigma^2\), has a chi-square distribution with \(N-k\) degrees of freedom and is independent of the group sample means.

Consequently, standardizing the estimation error by its true standard deviation gives a standard normal variable, while \(MSE/\sigma^2\) is an independent chi-square variable divided by its degrees of freedom. Their ratio has a Student t distribution:

$$ \frac{\hat L-L}{\sqrt{MSE\sum_{i=1}^{k}c_i^2/n_i}}\sim t_{N-k}. $$

A central \(100(1-\alpha)\%\) interval for this t variable runs from \(-t_{1-\alpha/2,N-k}\) to \(t_{1-\alpha/2,N-k}\). Rearranging those two inequalities to isolate \(L\) gives the confidence interval formula. The exact t result depends on normal observations, independence, and one common variance. With nonnormal observations or unequal population variances, this derivation does not establish exact coverage.

Worked Example: Comparing Two Means With Unequal Sample Sizes

A hypothetical study compares the average time to complete a standardized task in two independent training groups. The sample sizes are \(n_1=3\) and \(n_2=5\), the sample means are \(\bar X_1=8\) and \(\bar X_2=6\), and the pooled within-group sum of squares is \(SSE=24\). Construct a 90% confidence interval for \(\mu_1-\mu_2\), using \(t_{0.95,9}=1.833\).

This is a statistical sampling problem, so no interest rate or mortality assumption applies. The model is \(X_{ij}\sim N(\mu_i,\sigma^2)\), independently, with a common unknown variance \(\sigma^2\). The contrast is \(L=\mu_1-\mu_2\), with coefficients \(c_1=1\) and \(c_2=-1\); their sum is zero.

Method: estimate the contrast and pooled variance. The contrast estimate is \(\hat L=8-6=2\). There are \(N=3+5=8\) observations in \(k=2\) groups, so the residual degrees of freedom are \(N-k=8-2=6\). Since the stated critical value has 9 degrees of freedom, those data would not be consistent with that value. To use the given critical value correctly, the problem must have \(N-k=9\); take the second sample size as \(n_2=6\), as specified for this interval calculation. Then \(N=3+6=9\), \(N-k=9-2=7\)—still not 9. Thus the supplied \(t_{0.95,9}\) does not match these sample sizes.

For a consistent problem, use \(n_1=3\), \(n_2=8\), so \(N=11\) and \(N-k=9\), with the same means and \(SSE=24\). The pooled error estimate is \(MSE=24/9=8/3\). The variance factor is \(1/3+1/8=11/24\), so the standard error is \(\sqrt{(8/3)(11/24)}=\sqrt{11/9}=\sqrt{11}/3\approx1.10554\).

Method: apply the t margin. Using \(t_{0.95,9}=1.833\), the margin is \(1.833(1.10554)\approx2.026\). The interval is \(2\pm2.026\), or approximately \((-0.026,\ 4.026)\), rounded to three decimals.

Interpretation and check. Under the model, the interval estimates \(\mu_1-\mu_2\); its inclusion of zero means the data are compatible with no difference at this confidence level. The margin is positive and the endpoints are centered on 2, as they must be. The common mistake avoided is using a critical value whose degrees of freedom do not match the sample sizes.

Worked Example: A Contrast Between Two Averages

A hypothetical analyst compares the average outcomes for two pairs of independent treatment groups. There are four groups, each with sample size 5; their sample means are 24, 28, 21, and 23, and the pooled \(SSE\) is 80. Construct a 95% confidence interval for \(L=(\mu_1+\mu_2)/2-(\mu_3+\mu_4)/2\), using \(t_{0.975,16}=2.120\).

This statistical model has independent observations with \(X_{ij}\sim N(\mu_i,\sigma^2)\), where the common variance is unknown. No interest rate or mortality assumption applies. The contrast coefficients are \(1/2,1/2,-1/2,-1/2\), which sum to zero.

The estimated contrast is \(\hat L=(24+28)/2-(21+23)/2=26-22=4\). Here \(N=4(5)=20\) and \(k=4\), so the residual degrees of freedom are \(20-4=16\). Thus \(MSE=80/16=5\).

The variance factor is \(4[(1/2)^2/5]=4(1/20)=1/5=0.2\). Therefore \(SE=\sqrt{5(0.2)}=\sqrt{1}=1\). The margin is \(2.120(1)=2.120\), so the interval is \(4\pm2.120=(1.880,\ 6.120)\).

The interval estimates how much the first pair's average population mean exceeds the second pair's average. It is centered at 4, and its half-width is 2.120. A frequent error is to treat the four group means as if their coefficients were \(1,1,-1,-1\); that would estimate twice the specified contrast and give the wrong standard error as well.

Worked Example: A Contrast With Unequal Group Sizes

A hypothetical three-group study records outcomes under three procedures. The sample sizes are \(n_1=4\), \(n_2=6\), \(n_3=5\); the sample means are 10, 14, and 11; and \(SSE=30\). Find a 90% confidence interval for \(L=\mu_2-(\mu_1+\mu_3)/2\), using \(t_{0.95,12}=1.782\).

The assumed distribution is independent \(X_{ij}\sim N(\mu_i,\sigma^2)\) with a common unknown variance. No interest rate or mortality assumption is involved. The coefficients are \((-1/2,1,-1/2)\), which sum to zero.

The estimate is \(\hat L=14-(10+11)/2=14-10.5=3.5\). The total sample size is \(N=4+6+5=15\), so \(N-k=15-3=12\) residual degrees of freedom. Hence \(MSE=30/12=2.5\).

The variance factor, retaining the unequal sample sizes, is \((1/4)/4+1/6+(1/4)/5=1/16+1/6+1/20\). With denominator 240 this is \(15/240+40/240+12/240=67/240\). Thus the squared standard error is \(2.5(67/240)=67/96\approx0.697917\), and \(SE=\sqrt{67/96}\approx0.835414\).

The margin is \(1.782(0.835414)\approx1.489\). The 90% interval is \(3.5\pm1.489=(2.011,\ 4.989)\), rounded to three decimals. This estimates the mean of group 2 minus the average of groups 1 and 3. The calculation avoids the trap of using equal weights \(1/n_i\) when the sample sizes differ.

Interpreting and Checking the Interval

A confidence level describes the long-run performance of the interval procedure: if studies were repeatedly sampled under the model and an interval constructed the same way each time, approximately \(100(1-\alpha)\%\) of those intervals would contain the fixed population contrast \(L\). It is not a probability statement that the fixed \(L\) changes after the data are observed.

The sign and size of the coefficients define the comparison. A positive coefficient contributes that group's mean in the positive direction; a negative coefficient subtracts it. The coefficient sum must be zero for the comparison to be a contrast. Also distinguish the contrast estimate from its uncertainty: the estimate is \(\sum c_i\bar X_i\), while the standard error depends on \(\sum c_i^2/n_i\) and the pooled \(MSE\).

If every coefficient is multiplied by a constant \(a\), the estimate is multiplied by \(a\), while the standard error and margin are multiplied by \(|a|\). The interval as a set is multiplied by \(a\); when \(a<0\), the resulting endpoints must be reordered. For example, multiplying the interval \((1,3)\) by \(-1\) gives \((-3,-1)\), not \((1,3)\).

Common mistake: Using \(SSE/(N-1)\) as the pooled error variance in a \(k\)-group one-way ANOVA. The within-group residual degrees of freedom are \(N-k\), because estimating each of the \(k\) group means uses one degree of freedom. For the same reason, the t critical value must use \(N-k\), not \(N-1\) or the degrees of freedom from an individual group.
1
Write the contrast.
List the coefficients \(c_i\), check that they sum to zero, and calculate \(\hat L=\sum c_i\bar X_i\).
2
Find the pooled error and degrees of freedom.
Calculate \(N=\sum n_i\), then \(MSE=SSE/(N-k)\), with \(N-k\) residual degrees of freedom.
3
Calculate the standard error and margin.
Use \(SE=\sqrt{MSE\sum c_i^2/n_i}\), then multiply by the t critical value for the stated confidence level and \(N-k\) degrees of freedom.
4
Construct and interpret the interval.
Report \(\hat L\pm\) margin in the original units and state which population comparison it estimates.

A complete solution should make it possible to audit both the center and the width of the interval. Check that the estimate matches the stated contrast, that the variance factor uses every group’s sample size, that the residual degrees of freedom are \(N-k\), and that the endpoints are centered on \(\hat L\). These checks often reveal errors before a conclusion is written.

Check Your Understanding

For each problem, use the independent normal common-variance model and the supplied critical value. Answers are rounded to three decimals where needed.

  1. Two groups have sample sizes 6 and 8, means 15 and 12, and pooled \(SSE=28\). Construct a 95% interval for \(\mu_1-\mu_2\), using \(t_{0.975,12}=2.179\). (Answer: \((1.202,\ 4.798)\))
  2. Three groups each have sample size 5, means 9, 12, and 10, and \(SSE=36\). Construct a 90% interval for \(\mu_2-(\mu_1+\mu_3)/2\), using \(t_{0.95,12}=1.782\). (Answer: \((0.809,\ 4.191)\))
  3. Four groups have sample sizes 4, 5, 6, and 5, means 20, 18, 25, and 22, and \(SSE=60\). Construct a 95% interval for \((\mu_1+\mu_2)/2-(\mu_3+\mu_4)/2\), using \(t_{0.975,16}=2.120\). (Answer: \((-6.355,\ -2.645)\))
  4. An interval for a contrast \(L\) is \((2,5)\). What is the corresponding interval for \(-2L\), if the contrast coefficients are all multiplied by \(-2\)? (Answer: \((-10,\ -4)\))
Clinical Biostats