Why Compare Groups Across Another Category?
A group difference need not be the same in every setting. For example, a program might be associated with a larger change in an outcome in one clinic type than in another. A model with two categorical predictors and their interaction gives a concise way to describe this pattern. The interaction asks whether the difference between the categories of one predictor changes across the categories of the other.
This tutorial focuses on two predictors, each with two categories. The outcome \(Y\) is quantitative. The model describes associations in the data; by itself, it does not establish that either predictor causes a change in the outcome.
The Two-Factor Interaction Model
Represent each predictor with a zero-one indicator. Let \(A=0\) and \(A=1\) denote the two categories of the first factor, and let \(B=0\) and \(B=1\) denote the two categories of the second. The zero category for each factor is its reference category. For observation \(i\), the model is
Here, \(\beta_0,\beta_1,\beta_2,\beta_3\) are model coefficients, and \(\varepsilon_i\) is the error for observation \(i\). The product \(A_iB_i\) is 1 only when both predictors are in their 1 categories; otherwise it is 0. The product term allows the difference between the categories of one factor to depend on the level of the other.
The model’s fitted mean at each combination of categories follows by substituting 0 or 1 for the indicators. These equations also show why the main effects must be interpreted conditionally:
What Each Coefficient Means
The intercept \(\beta_0\) is the model mean for the reference categories \(A=0\) and \(B=0\). The coefficient \(\beta_1\) is the fitted difference between \(A=1\) and \(A=0\) specifically when \(B=0\). Likewise, \(\beta_2\) is the fitted difference between \(B=1\) and \(B=0\) specifically when \(A=0\). Neither main-effect coefficient is automatically an average difference across the other factor’s categories.
To see the role of \(\beta_3\), subtract the fitted outcome for \(A=0\) from that for \(A=1\), holding \(B\) fixed. When \(B=0\), this difference is \(\beta_1\). When \(B=1\), it is \(\beta_1+\beta_3\). Therefore, the change in the \(A\)-category difference as \(B\) moves from 0 to 1 is
This is the key interpretation: a positive \(\beta_3\) means the fitted \(A=1\) versus \(A=0\) difference is more positive (or less negative) when \(B=1\) than when \(B=0\). A negative \(\beta_3\) means it is less positive (or more negative). The sign describes how the difference changes, not whether either group’s outcome is itself positive or negative.
Model Conditions and What They Support
The regression assumptions should be considered before using the model for estimation or inference. The conditional mean is represented by the four category-specific means in the equations above. For standard regression-based inference, the errors should have mean zero conditional on the predictors, be independent across observations, and have a common variance. Normal errors within predictor combinations support the usual exact small-sample \(t\)- and \(F\)-based procedures. Residual plots and knowledge of how observations were collected help assess these conditions; the assumptions cannot be confirmed just by looking at the coefficient estimates.
All four combinations of categories should be represented in the data to estimate their means separately. If a combination is absent, the four cell means are not all independently informed by observations. Independence also depends on the observational units and study design: repeated measurements on one person, for example, are not automatically independent. Finally, an interaction is a statement about the fitted mean pattern, not proof of a causal effect.
Worked Example: Tutoring Differences by Class Schedule
Suppose a hypothetical study relates tutoring status to a quantitative course score, measured in points. Let \(A=1\) denote students receiving tutoring and \(A=0\) students not receiving tutoring. Let \(B=1\) denote an evening class and \(B=0\) a morning class. A fitted model has estimates \(\hat{\beta}_0=62\), \(\hat{\beta}_1=8\), \(\hat{\beta}_2=5\), and \(\hat{\beta}_3=-6\). Interpret the estimates and find the four fitted scores.
The fitted model is
For students who are not tutored in morning classes, \(A=0\) and \(B=0\), so the fitted score is \(62+8(0)+5(0)-6(0)(0)=62\) points.
For tutored students in morning classes, \(A=1\) and \(B=0\), giving \(62+8(1)+5(0)-6(1)(0)=70\) points. Thus, the fitted tutoring difference in morning classes is \(70-62=8\) points, matching \(\hat{\beta}_1\).
For students who are not tutored in evening classes, \(A=0\) and \(B=1\), giving \(62+8(0)+5(1)-6(0)(1)=67\) points. Tutored students in evening classes have fitted score \(62+8(1)+5(1)-6(1)(1)=69\) points. Their fitted tutoring difference is \(69-67=2\) points.
The interaction estimate is \(-6\) points because \(2-8=-6\): the fitted tutoring difference is 6 points smaller in evening classes than in morning classes. The model describes an association, not evidence that tutoring caused these score differences. For this illustration, suppose the four combinations are represented, students’ observations are independent, and residual checks show no substantial variance pattern or severe departures from the model assumptions. The coefficient arithmetic alone would not establish those conditions.
Interpreting the Difference in a Second Setting
The same reasoning can be used whichever factor is treated as the comparison of interest. For \(B=0\), the fitted difference between \(B=1\) and \(B=0\) is \(\beta_2\). For \(A=1\), that difference is \(\beta_2+\beta_3\). The interaction is therefore symmetric in its description: it tells how the \(A\) difference changes across \(B\), and also how the \(B\) difference changes across \(A\).
Worked Example: A Treatment Difference by Ward Type
In a hypothetical analysis, a quantitative recovery measure is recorded for patients in two ward types. Let \(A=1\) indicate a new care plan and \(A=0\) the usual plan. Let \(B=1\) indicate a specialist ward and \(B=0\) a general ward. Suppose the fitted model is \(\widehat{Y}=40-3A+2B+4AB\), with recovery measured in points. What do the coefficients imply?
The fitted difference for the new plan versus the usual plan in general wards is \(\hat{\beta}_1=-3\) points. In specialist wards, it is \(\hat{\beta}_1+\hat{\beta}_3=-3+4=1\) point. Thus, the fitted plan difference changes by \(1-(-3)=4\) points between ward types, equal to the interaction estimate.
The four fitted outcomes make the calculation concrete. For the usual plan in a general ward, \(\widehat{Y}=40-3(0)+2(0)+4(0)(0)=40\) points. For the new plan in a general ward, \(\widehat{Y}=40-3(1)+2(0)+4(1)(0)=37\) points. For the usual plan in a specialist ward, \(\widehat{Y}=40-3(0)+2(1)+4(0)(1)=42\) points. For the new plan in a specialist ward, \(\widehat{Y}=40-3(1)+2(1)+4(1)(1)=43\) points.
The interaction estimate is positive, but that does not mean the plan difference is positive in both ward types: it is \(-3\) points in general wards and \(1\) point in specialist wards. For this hypothetical interpretation, assume each plan-by-ward combination has observations, the observations are independent, and residual diagnostics do not reveal important violations of the regression conditions. These assumptions concern whether the fitted model and any associated inference are appropriate; the arithmetic does not verify them.
Why the Conditional Interpretation Matters
When an interaction is included, the main effects refer to the reference category of the other predictor. In the ward example, \(-3\) is the plan difference for general wards, not a single plan difference that applies to both ward types. Reporting it without its condition would hide an important part of the model. A clear summary gives both conditional differences and then describes how much they change across the second factor.
The interaction estimate is also not a comparison of the overall average outcome for \(A=1\) versus \(A=0\). Such an average depends on how observations are distributed across the levels of \(B\). The regression coefficient instead describes a change between the two conditional differences. Keep the category labels, reference categories, outcome units, and conditions attached to each reported effect.
Common Mistakes
- Calling a main effect an overall difference. The coefficient \(\beta_1\) is the \(A\) difference when \(B=0\), not necessarily an average across \(B\).
- Interpreting the interaction as an outcome level. The coefficient \(\beta_3\) is not a fitted score or a group mean. It measures how a difference changes, in the outcome’s units.
- Ignoring the reference categories. A main effect changes meaning if the zero category changes, so state which category is coded 0.
- Concluding causation from a fitted interaction. The model describes an association unless the study design and assumptions support a causal interpretation.
Check Your Understanding
Use the two-factor model and the interpretations in this tutorial to answer the following.
- In \(\widehat{Y}=20+4A-2B+3AB\), what is the fitted difference for \(A=1\) versus \(A=0\) when \(B=0\)? What is it when \(B=1\)?
- For the same model, interpret the interaction coefficient, including its direction and units if \(Y\) is measured in hours.
- If \(\hat{\beta}_3=0\), what does the model imply about the fitted \(A\)-category difference across the two levels of \(B\)?
- Why should \(\hat{\beta}_1\) not automatically be described as an overall difference between the categories of \(A\)?
- Name two conditions or data features to check before relying on regression-based inference from this model.