Tutorials › Regression Analysis (Undergraduate) › Contrasts for Comparing Group Effects Across Strata

Interactions Among Groups · Tutorial 358 of 991

Contrasts for Comparing Group Effects Across Strata

Use cell means and their uncertainty to quantify how a group difference changes across levels of a second categorical factor.

Intermediate 12 min read

What You'll Learn

  • Define a contrast that compares group differences across strata.
  • Translate a contrast into coefficients for the cell means.
  • Calculate a contrast’s standard error from cell sizes and residual variation.
  • Construct a confidence interval and test a null hypothesis about the contrast.
  • Distinguish a prespecified weighted comparison from an overall interaction test.

Why Compare Group Differences Across Strata?

A group difference can depend on the level of a second categorical factor. For example, a hypothetical program might be associated with a larger mean score difference in one age stratum than in another. The quantity of interest is not either group difference alone, but the difference between those group differences. A contrast gives a precise way to define that comparison and to quantify its uncertainty.

This tutorial uses cell means: the population mean outcome for each combination of group and stratum. The same calculations can be expressed using coefficients in a regression model. The essential task is to specify which cell means enter the comparison and with what weights.

Definition: Suppose there are two groups, \(A\) and \(B\), and strata \(1,\ldots,S\). Let \(\mu_{As}\) and \(\mu_{Bs}\) be their population mean outcomes in stratum \(s\). The group difference in stratum \(s\) is \(D_s=\mu_{As}-\mu_{Bs}\). A contrast comparing these group differences has the form \(C=\sum_{s=1}^{S}w_sD_s\), where the weights \(w_s\) are specified in advance. For a difference between two strata, the weights are \(1\) and \(-1\), with zero weights for other strata.

For two strata, a common contrast is \(C=D_1-D_2\). Written directly in terms of cell means, this is

$$ C=(\mu_{A1}-\mu_{B1})-(\mu_{A2}-\mu_{B2}) =\mu_{A1}-\mu_{B1}-\mu_{A2}+\mu_{B2}. $$

The signs indicate exactly what is being compared. A positive value means the group \(A\)-minus-\(B\) difference is larger in stratum 1 than in stratum 2. The units are the same as the outcome’s units. A contrast is not automatically an average over strata: its weights determine the comparison.

Estimating a Contrast and Its Standard Error

Replace each population cell mean with its sample estimate, \(\hat{\mu}_{gs}\), to obtain the estimated contrast \(\hat{C}\). To quantify uncertainty, consider a categorical-factor model that estimates a separate mean for every group-by-stratum cell. Assume observations are independent, the cell-mean model is appropriate, and the errors have a common variance \(\sigma^2\). For an exact \(t\)-based interval and test, also assume normally distributed errors. Under these assumptions, the estimated cell means from disjoint cells are independent, and the estimated common error variance is the model’s residual mean square, \(MSE\).

If cell \(gs\) has \(n_{gs}\) observations, then the estimated variance of the cell mean is \(MSE/n_{gs}\); its true variance is \(\sigma^2/n_{gs}\). Write a contrast as \(C=\sum_{g,s}c_{gs}\mu_{gs}\), where the \(c_{gs}\) are its cell-mean coefficients. Its estimated standard error is

$$ SE(\hat{C})= \sqrt{MSE\sum_{g,s}\frac{c_{gs}^{\,2}}{n_{gs}}}. $$

This formula squares each coefficient, so negative signs in the contrast do not cancel variance. It also shows why both residual variability and the cell sizes matter. With unequal variances or dependent observations, this particular formula need not apply; the uncertainty calculation must match the model and sampling structure.

Result: Under the stated normal, independent, common-variance cell-means model, the statistic \(t=\hat{C}/SE(\hat{C})\), when testing \(H_0:C=0\), has a \(t\) distribution with \(df=N-K\). Here \(N\) is the total number of observations and \(K\) is the number of estimated cell means. A confidence interval with confidence level \(1-\alpha\) is \(\hat{C}\pm t^*SE(\hat{C})\), where \(t^*\) is the appropriate positive critical value with \(N-K\) degrees of freedom.

Worked Comparisons

Worked Example: Comparing Two Strata

Suppose a hypothetical assessment records scores, in points, for two groups in two strata. Each of the four cells contains 10 observations. The cell sample means are 12 and 8 points for groups \(A\) and \(B\) in stratum 1, and 9 and 7 points in stratum 2. The within-cell residual sum of squares is 72 points squared. Estimate the difference between the group differences and construct a 95% confidence interval.

The stratum-specific estimated differences are \(\hat{D}_1=12-8=4\) points and \(\hat{D}_2=9-7=2\) points. Thus the contrast estimate is

$$ \hat{C}=(12-8)-(9-7)=4-2=2\text{ points}. $$

There are \(N=40\) observations and \(K=4\) cells, so \(df=40-4=36\). The residual mean square is \(MSE=72/36=2\). Each of the four cell-mean coefficients is \(1\) or \(-1\), and each cell has \(n=10\). Therefore,

$$ SE(\hat{C})= \sqrt{2\left(\frac{1}{10}+\frac{1}{10}+\frac{1}{10}+\frac{1}{10}\right)} =\sqrt{0.8} \approx 0.8944\text{ points}. $$

For 36 degrees of freedom, \(t^*\approx2.028\) for a 95% interval. Using the displayed values, the margin is \(2.028(0.8944)\approx1.814\) points, so the interval is \(2\pm1.814\), or approximately \((0.186,3.814)\) points. In repeated samples under the model, intervals constructed this way would cover the true difference between the group differences 95% of the time. This interval excludes zero, indicating evidence of a difference in the group effects between the two strata at the two-sided 5% level.

Worked Example: A Contrast That Is Not Statistically Significant

In another hypothetical dataset, there are two groups and three strata, with 10 observations in every cell. The group differences in strata 1 and 2 are estimated as 4 and 2 points, respectively. The third stratum is not part of the contrast. Suppose the model residual mean square is \(3.041\) points squared. Compare the first two strata.

The contrast is \(C=D_1-D_2\), so its estimate is \(4-2=2\) points. In cell-mean terms the coefficients are \(+1,-1,-1,+1\) for groups \(A,B\) in strata 1 and 2, and zero for both cells in stratum 3. There are \(N=60\) observations and \(K=6\) cells, giving \(df=54\). Its standard error is

$$ SE(\hat{C})= \sqrt{3.041\left(\frac{1}{10}+\frac{1}{10}+\frac{1}{10}+\frac{1}{10}\right)} =\sqrt{1.2164} \approx1.103\text{ points}. $$

For \(H_0:C=0\), the test statistic is \(t=2/1.103\approx1.813\), using the unrounded standard error for the calculation. With 54 degrees of freedom, the two-sided \(p\)-value is approximately \(0.075\). At \(\alpha=0.05\), the result is not statistically significant: the data do not provide sufficient evidence at that level that the group difference varies between strata 1 and 2. This does not establish that the population contrast is zero.

Worked Example: A Weighted Comparison Across Three Strata

Suppose a hypothetical study has 8 observations per group in stratum 1, 12 per group in stratum 2, and 10 per group in stratum 3. The estimated group differences are 2, 0, and 0 points, respectively. Let \(MSE=2.25\) points squared. Compare the average of the first two group differences with the third group difference.

The specified contrast is \(C=(D_1+D_2)/2-D_3\), so its stratum weights are \(1/2,1/2,-1\). The estimate is

$$ \hat{C}=\frac{2+0}{2}-0=1\text{ point}. $$

The cell-mean coefficients are \(+1/2,-1/2\) in each of strata 1 and 2, and \(+1,-1\) in stratum 3. The total sample size is \(N=60\), with \(K=6\) cells and \(df=54\). Thus,

$$ SE(\hat{C})= \sqrt{2.25\left[ \frac{(1/2)^2+(-1/2)^2}{8} +\frac{(1/2)^2+(-1/2)^2}{12} +\frac{1^2+(-1)^2}{10} \right]} \approx0.8273\text{ points}. $$

The bracketed sum is \(0.0625+0.04167+0.2=0.30417\), so the variance estimate is \(2.25(0.30417)=0.6844\) points squared. The test statistic for \(H_0:C=0\) is \(1/0.8273\approx1.209\), with a two-sided \(p\)-value of about \(0.232\). A 95% interval uses \(t^*\approx2.005\) for 54 degrees of freedom: \(1\pm2.005(0.8273)\), or approximately \((-0.659,2.659)\) points. The interval includes zero, so this comparison does not provide strong evidence that the average of the first two group differences differs from the third. The weights are part of the question: this contrast is not the same as comparing stratum 1 with stratum 3 alone.

How the Uncertainty Formula Follows

The standard-error calculation follows from the variance of a weighted sum. For independent cell-mean estimates, the variance of \(\hat{C}=\sum_{g,s}c_{gs}\hat{\mu}_{gs}\) is the sum of their variances multiplied by squared coefficients. Each cell mean has estimated variance \(MSE/n_{gs}\). Substitution gives

$$ \widehat{\operatorname{Var}}(\hat{C}) =\sum_{g,s}c_{gs}^{\,2}\frac{MSE}{n_{gs}} =MSE\sum_{g,s}\frac{c_{gs}^{\,2}}{n_{gs}}. $$

Taking the square root gives \(SE(\hat{C})\). Under the model assumptions, the contrast estimate is normally distributed around \(C\), and the pooled residual variance is estimated independently using \(N-K\) residual degrees of freedom. Dividing the centered estimate by its estimated standard error therefore gives the stated \(t\) statistic. This is why the same standard error supports both a test and a confidence interval.

Choosing and Interpreting the Contrast

A contrast should reflect the comparison of interest, not be selected only because it produces a convenient calculation. For two groups and two strata, \(D_1-D_2\) has a direct interpretation as the change in the group difference from one stratum to the other. With more strata, several scientifically meaningful contrasts may be possible: comparing two particular strata, comparing one stratum with an average of others, or comparing two weighted averages. State the weights explicitly so the reader can see what is being compared.

A contrast test addresses the particular linear combination specified in its null hypothesis. It does not automatically test every possible difference among group effects. A single contrast can be nonzero even if another contrast is zero, and a nonsignificant result does not prove exact equality. Conclusions should name the groups, strata, outcome, units, and uncertainty in context.

Common Pitfall

A frequent error is to compare two separate \(p\)-values and infer that the group effects differ because one is significant and the other is not. That reasoning does not test the difference between the effects. The correct procedure estimates a contrast such as \(D_1-D_2\), calculates its standard error using all four relevant cell means and their covariance structure, and tests or forms an interval for that contrast directly. Also take care not to omit coefficients from a weighted comparison: halving two stratum differences and subtracting a third defines a different quantity from simply subtracting one difference from another.

Key takeaway: To compare group effects across strata, define the contrast in terms of cell means, preserve its weights, and calculate uncertainty for that complete linear combination. Interpret the result as a comparison of group differences—not as a causal effect unless the study design supports causal conclusions.

Check Your Understanding

Use the definitions and methods above to answer these questions.

  1. Write the cell-mean coefficients for the contrast \(D_1-D_3\) when there are two groups and three strata.
  2. If each of the four cells in a two-group, two-stratum comparison has 20 observations and \(MSE=4\), calculate the standard error for \(D_1-D_2\).
  3. Explain why the standard error uses squared contrast coefficients, even when some coefficients are negative.
  4. In a three-stratum setting, what comparison is defined by \(C=(D_1+D_2)/2-D_3\)?
  5. A test of a contrast has \(p=0.08\) and \(\alpha=0.05\). State a correct conclusion without claiming that the contrast is zero.