Tutorials › Multivariate Statistics (Graduate) › Within-Subject Contrasts in Mixed Group Designs

Contrasts and Repeated Measures · Tutorial 370 of 975

Within-Subject Contrasts in Mixed Group Designs

Transform repeated measurements into contrast responses, then test whether those responses differ across groups, including group-by-occasion interactions.

Advanced 12 min read

What You'll Learn

  • Construct contrast responses from repeated measurements using a within-subject contrast matrix
  • State group-difference hypotheses for one or several contrast responses
  • Interpret a group-by-occasion interaction as a difference in within-subject contrasts
  • Derive the covariance of estimated group contrast responses
  • Choose between a univariate and multivariate group comparison
  • Recognize when a difference-in-differences interpretation is appropriate

Why Compare Groups on Within-Subject Changes?

In a repeated-measures study, the question is often not whether groups have different outcome levels at a particular occasion. Researchers may instead ask whether groups change differently over time. A treatment group, for example, may improve more from baseline to follow-up than a control group. That comparison is a difference between within-subject differences, also called a difference-in-differences.

A within-subject contrast converts each subject’s vector of repeated outcomes into one or more contrast responses. The group comparison is then expressed as a comparison of the means of those responses. This makes the target of inference explicit: the chosen contrast determines which aspect of the repeated profile is compared.

Definition: Suppose subject \(i\) in group \(g\) has outcome vector \(Y_{ig}\in\mathbb{R}^p\), with one component for each of \(p\) occasions. Let \(C\) be a \(q\times p\) matrix of within-subject contrasts, so each row of \(C\) sums to zero. The subject’s contrast-response vector is \(Z_{ig}=CY_{ig}\in\mathbb{R}^q\). If the group’s mean outcome profile is \(\mu_g=E[Y_{ig}]\), its mean contrast response is \(\theta_g=C\mu_g\).

For a single contrast, \(q=1\), each subject contributes one scalar response. For several contrasts, \(q>1\), each subject contributes a vector and the group comparison is multivariate. In either case, the rows of \(C\) specify the occasion comparisons being studied. A row whose entries sum to zero removes a constant shift shared by every occasion.

Formulating a Group-by-Occasion Hypothesis

Let there be \(G\) groups, and write the group mean profiles as the rows of the \(G\times p\) matrix \(M\). The matrix \(MC^\mathsf{T}\) has one row per group and one column per selected within-subject contrast. Thus, each column shows the group means of a particular contrast response.

A group-by-occasion interaction for the selected contrasts means that groups do not all have the same contrast-response means. To express the null precisely, take any full set of \(G-1\) linearly independent group contrasts and place them in the rows of a matrix \(A\), where \(A\) is \((G-1)\times G\) and \(A\mathbf{1}_G=0\). The null hypothesis is \(AMC^\mathsf{T}=0\). Equivalently, every group has the same mean response for each selected within-subject contrast.

Theorem: For a contrast matrix \(C\), equality of group mean contrast responses, \(C\mu_1=\cdots=C\mu_G\), is equivalent to \(AMC^\mathsf{T}=0\) for any full set \(A\) of \(G-1\) independent group contrasts. If \(C\) has rows summing to zero, this hypothesis concerns group differences in the selected within-subject patterns, not a constant profile level.

Proof. The rows of \(MC^\mathsf{T}\) are \((C\mu_g)^\mathsf{T}\). If these rows are equal across groups, every row contrast in \(A\) maps them to zero, so \(AMC^\mathsf{T}=0\). Conversely, because the rows of \(A\) span the space of group contrasts, \(AMC^\mathsf{T}=0\) says that every difference between two rows of \(MC^\mathsf{T}\) is zero. Therefore the group mean contrast responses are equal. Since each row of \(C\) sums to zero, adding the same constant to all occasion means does not change \(C\mu_g\). \(\square\)

This is a targeted hypothesis: it asks whether the groups differ in the particular changes represented by \(C\). It does not, by itself, test whether their overall levels differ. Nor does selecting a single contrast test every possible pattern of group-by-occasion interaction. The conclusion is limited to the contrast responses included in \(C\).

Worked Example: Comparing Endpoint Change Between Two Groups

A study measures an outcome at three occasions. The mean profiles are control \((10,12,14)\) and treatment \((10,15,19)\). Use the contrast \(C=(-1,0,1)\) to compare the change from the first to the last occasion.

For the control group, the mean contrast response is \(C\mu_{\text{control}}=-10+14=4\). For the treatment group, it is \(C\mu_{\text{treatment}}=-10+19=9\). The difference between groups is \(9-4=5\).

Thus, the treatment group has a five-unit greater mean endpoint change than the control group. This comparison uses only the first and last occasions. It does not say whether the groups differ in the middle occasion or in a different pattern of change.

Sampling Variation and Group Comparisons

To quantify uncertainty, suppose subjects are independent within and across groups, and within each group the repeated outcome vector has covariance matrix \(\Sigma_g\). The sample mean profile in group \(g\) is \(\bar Y_g\), and its sample mean contrast response is \(C\bar Y_g\). The covariance of that estimated response follows directly from the linear transformation.

Result: If group \(g\) contains \(n_g\) independent subjects with common within-group covariance \(\Sigma_g\), then \(\operatorname{Cov}(C\bar Y_g)=C\Sigma_gC^\mathsf{T}/n_g\). For independent groups \(g\) and \(h\), \(\operatorname{Cov}(C\bar Y_g-C\bar Y_h)=C\Sigma_gC^\mathsf{T}/n_g+C\Sigma_hC^\mathsf{T}/n_h\).

Derivation. Write \(\bar Y_g=n_g^{-1}\sum_{i=1}^{n_g}Y_{ig}\). Independence gives \(\operatorname{Cov}(\bar Y_g)=\Sigma_g/n_g\): the covariance of the sum is \(n_g\Sigma_g\), and scaling the sum by \(1/n_g\) scales its covariance by \(1/n_g^2\). For any fixed matrix \(C\), covariance under a linear transformation is \(\operatorname{Cov}(C\bar Y_g)=C\operatorname{Cov}(\bar Y_g)C^\mathsf{T}\), which gives the first formula. Independent groups have zero cross-covariance, so the covariance of their difference is the sum of their covariances. \(\square\)

For one contrast, this covariance is a scalar variance, and a group comparison can use a univariate method appropriate to the design and variance assumptions. With several contrasts, the covariance matrix describes how the estimated contrast responses vary jointly. Under multivariate normal sampling and a common contrast-response covariance matrix across groups, the standard multivariate linear-model framework gives a joint test of equality of group means. The MANOVA criteria summarize that joint comparison; the choice of contrast matrix determines what the test addresses.

Worked Example: Difference-in-Differences for Two Occasions

A control and a treatment group are measured before and after treatment. Use \(C=(-1,1)\), so each subject’s response is post-treatment minus pre-treatment. The observed subject-level responses are control: \(2,3,4,4,5,6\), and treatment: \(7,8,9,9,10,11\). Calculate the estimated difference-in-differences and, under a common-variance model, its standard error.

The control mean response is \((2+3+4+4+5+6)/6=24/6=4\). The treatment mean response is \((7+8+9+9+10+11)/6=54/6=9\). Therefore, the estimated difference-in-differences is \(9-4=5\) outcome units.

For either group, the deviations from its mean are \(-2,-1,0,0,1,2\). The sum of squared deviations is \(4+1+0+0+1+4=10\), so each sample variance is \(10/(6-1)=2\). The pooled variance is also \(2\), since both groups have the same sample variance and sample size. The standard error of the difference between independent group means is \(\sqrt{2(1/6+1/6)}=\sqrt{2/3}\approx0.816\).

The estimated difference-in-differences is therefore \(5\), with standard error about \(0.816\) under the stated common-variance model. The response is the change for each subject, not the two occasion measurements treated as independent observations.

Several Contrast Responses at Once

When the scientific question involves more than one within-subject pattern, retain several rows in \(C\). For example, with three occasions, \(C\) can contain the adjacent differences \((-1,1,0)\) and \((0,-1,1)\). The resulting two-dimensional response records both the first-to-second and second-to-third occasion changes. A joint group test then asks whether the groups have the same mean vector of changes.

Worked Example: A Joint Test of Two Occasion Changes

For three occasions, take \(C=\begin{pmatrix}-1&1&0\\0&-1&1\end{pmatrix}\). Four subjects in each of two groups have the following contrast responses: control: \((1,1),(1,3),(3,1),(3,3)\); treatment: \((3,2),(3,4),(5,2),(5,4)\). Find the group mean contrast vectors and calculate the two-sample Hotelling statistic under the common-covariance model.

The control mean is \(\bar Z_1=(2,2)^\mathsf{T}\), and the treatment mean is \(\bar Z_2=(4,3)^\mathsf{T}\). Their difference is \(d=\bar Z_2-\bar Z_1=(2,1)^\mathsf{T}\). In each group, the deviations in the first coordinate are \(-1,-1,1,1\), and those in the second coordinate are \(-1,1,-1,1\). Each coordinate has sum of squares \(4\), and the cross-product sum is \(0\). Dividing by \(n-1=3\), the sample covariance in each group is \(S_1=S_2=\begin{pmatrix}4/3&0\\0&4/3\end{pmatrix}\).

The pooled covariance is \(S_p=(3S_1+3S_2)/6=S_1\), so \(S_p^{-1}=\begin{pmatrix}3/4&0\\0&3/4\end{pmatrix}\). With \(n_1=n_2=4\), the two-sample Hotelling statistic is \(T^2=\frac{n_1n_2}{n_1+n_2}d^\mathsf{T}S_p^{-1}d\). Here \(d^\mathsf{T}S_p^{-1}d=(2,1)\begin{pmatrix}3/4&0\\0&3/4\end{pmatrix}(2,1)^\mathsf{T}=3+3/4=15/4\), hence \(T^2=2(15/4)=7.5\).

For \(q=2\) responses and \(N=8\) subjects, the equivalent \(F\) statistic is \(F=\frac{N-q-1}{q(N-2)}T^2=\frac{5}{12}(7.5)=3.125\), with \(2\) and \(5\) degrees of freedom under the multivariate normal, common-covariance model. The tested group difference is joint: it concerns both adjacent occasion changes, not either one in isolation.

Interpretation and a Common Pitfall

A contrast comparison is useful when a study’s question is naturally about change, shape, or a specified combination of occasions. It can remove a shared profile level and focus inference on a scientifically meaningful pattern. The contrast weights should be selected for that question before interpreting a test; changing the weights changes the target.

  • Pitfall: calling any group difference an interaction. A difference in outcome levels at one occasion is not automatically a group-by-occasion interaction.
  • Correction: State the within-subject contrast first, compute or define each group’s mean response on that contrast, and compare those responses. For two groups and two occasions, the interaction is the treatment group’s mean post-minus-pre change minus the control group’s mean post-minus-pre change.
  • Pitfall: treating repeated measurements as independent subjects. This ignores the within-subject dependence that is present when the response is constructed from repeated outcomes.
  • Correction: Form one contrast response per subject, then use a group-comparison method whose assumptions match the sampling design and covariance structure.
Key takeaway: A within-subject contrast turns a repeated profile into a response with a defined interpretation. Comparing those responses across groups tests group differences in the selected within-subject patterns; a difference-in-differences is the special case with two groups, two occasions, and one change contrast.

Check Your Understanding

Use the contrast-response definition and the study question to guide each answer.

  1. For three occasions, what pattern does \(C=(-1,0,1)\) measure, and which occasion does it leave out?
  2. For two groups measured before and after treatment, write the contrast response for each subject and the difference-in-differences hypothesis in words.
  3. Why does equality of group mean contrast responses not necessarily imply equality of the groups’ full mean profiles?
  4. If \(C\) has two rows, what additional feature of the group comparison must a joint multivariate test account for?
  5. Under independent sampling, how does the covariance of a group’s estimated contrast response depend on its sample size?
Clinical Biostats