Tutorials › Biostatistics › Interaction Terms in Regression Models

Regression & Modeling

Interaction Terms in Regression Models

A practical guide to modeling effect modification using interaction terms, including product terms, interpretation of coefficients, continuous and categorical predictors, clinical examples, marginal effects, model visualization, and implementation in R and SAS.

Intermediate 18 min read

What You'll Learn

  • What an interaction term means in a regression model
  • How product terms change the interpretation of regression coefficients
  • How to interpret interactions between continuous and categorical variables
  • How treatment-by-subgroup interactions are used in clinical trials
  • Why main effects cannot be interpreted independently when an interaction is present
  • How to fit and report interaction models in R and SAS

Introduction

Regression models are often used to estimate how an outcome changes as a function of one or more predictors. A standard model assumes that the effect of one predictor is the same regardless of the value of another predictor.

That assumption is not always scientifically reasonable.

For example, suppose a clinical trial evaluates a treatment and investigators suspect that the treatment effect differs between younger and older patients. A model containing only treatment and age assumes that the treatment effect is constant across age.

An interaction term allows the effect of one predictor to depend on another predictor.

Key idea: An interaction means that the association between one predictor and the outcome changes according to the value of another predictor. In regression, this is usually represented by including a product of the two predictors in the model.

What Is an Interaction?

Consider two predictors, \(X_1\) and \(X_2\). Without an interaction, a linear regression model might be written as:

\[ Y=\beta_0+\beta_1X_1+\beta_2X_2+\varepsilon \]

The coefficient \(\beta_1\) represents the change in the expected outcome associated with a one-unit increase in \(X_1\), holding \(X_2\) constant.

This model assumes that the effect of \(X_1\) is the same regardless of the value of \(X_2\).

To allow the effect of \(X_1\) to depend on \(X_2\), add a product term:

\[ Y= \beta_0+ \beta_1X_1+ \beta_2X_2+ \beta_3X_1X_2+ \varepsilon \]

The term

\[ X_1X_2 \]

is the interaction term.

Important: The interaction coefficient \(\beta_3\) tells us how the effect of \(X_1\) changes for a one-unit increase in \(X_2\), or equivalently how the effect of \(X_2\) changes as \(X_1\) increases.

The Mathematical Meaning of the Interaction

The easiest way to understand an interaction is to examine the slope of the outcome with respect to \(X_1\).

For the model:

\[ Y= \beta_0+ \beta_1X_1+ \beta_2X_2+ \beta_3X_1X_2+ \varepsilon \]

the conditional effect of \(X_1\) is:

\[ \frac{\partial E(Y\mid X_1,X_2)}{\partial X_1} = \beta_1+\beta_3X_2 \]

This equation is the central result for interpreting a continuous-by-continuous interaction.

The effect of \(X_1\) is no longer simply \(\beta_1\). Instead, it depends on \(X_2\).

Similarly, the effect of \(X_2\) is:

\[ \frac{\partial E(Y\mid X_1,X_2)}{\partial X_2} = \beta_2+\beta_3X_1 \]

Thus, the interaction is symmetric mathematically: the product term describes how the effect of either variable changes according to the other.

A Simple Numerical Example

Suppose the fitted model is:

\[ Y= 50+ 2X_1+ 3X_2+ 1.5X_1X_2 \]

Here:

  • \(\beta_0=50\)
  • \(\beta_1=2\)
  • \(\beta_2=3\)
  • \(\beta_3=1.5\)

The effect of \(X_1\) is:

\[ \frac{\partial E(Y)}{\partial X_1} = 2+1.5X_2 \]

Therefore:

Value of \(X_2\) Effect of \(X_1\)
0 \(2\)
1 \(3.5\)
2 \(5\)
4 \(8\)

The effect of \(X_1\) becomes increasingly positive as \(X_2\) increases.

Interpretation: Because the interaction coefficient is positive, higher values of \(X_2\) strengthen the positive association between \(X_1\) and the outcome.

Why the Main Effect Can Be Misleading

One of the most common mistakes is interpreting \(\beta_1\) as the overall effect of \(X_1\) after an interaction has been included.

In the model:

\[ Y= \beta_0+ \beta_1X_1+ \beta_2X_2+ \beta_3X_1X_2+ \varepsilon \]

the coefficient \(\beta_1\) is the effect of \(X_1\) specifically when:

\[ X_2=0 \]

It is therefore a conditional effect, not necessarily an overall effect.

Practical rule: When an interaction is present, do not interpret the main-effect coefficient without considering the value at which the interacting variable is evaluated.

Centering Continuous Variables

Suppose age is measured in years and is used in an interaction with treatment. If age is entered directly, the treatment main effect corresponds to the treatment effect when:

\[ \text{Age}=0 \]

That may be scientifically meaningless.

A common solution is to center age around a meaningful reference value, such as the sample mean or a clinically meaningful age.

\[ \text{Age}_c=\text{Age}-\overline{\text{Age}} \]

The model then becomes:

\[ Y= \beta_0+ \beta_1\text{Treatment}+ \beta_2\text{Age}_c+ \beta_3(\text{Treatment}\times\text{Age}_c) +\varepsilon \]

Now \(\beta_1\) represents the treatment effect at the mean age.

Centering does not remove the interaction. It changes the reference point at which the main effects are interpreted.

Categorical-by-Categorical Interactions

Interactions are especially common when both predictors are categorical. Suppose:

  • Treatment = placebo or active treatment
  • Sex = female or male

A model can include:

\[ Y= \beta_0+ \beta_1T+ \beta_2S+ \beta_3(T\times S) +\varepsilon \]

where \(T\) and \(S\) are indicator variables.

The interaction coefficient describes how the treatment effect differs between the two sex categories.

Group Expected Treatment Effect
Reference sex \(\beta_1\)
Other sex \(\beta_1+\beta_3\)

Thus, \(\beta_3\) represents the difference in treatment effects between the two groups.

Clinical Trial Example: Treatment × Age

Suppose a randomized clinical trial compares an experimental treatment with placebo and the investigator believes that treatment efficacy may depend on baseline age. Let:

  • \(T=1\) for active treatment and \(T=0\) for placebo
  • \(A\) = centered baseline age
  • \(Y\) = change from baseline in a continuous efficacy endpoint

The model is:

\[ Y= \beta_0+ \beta_1T+ \beta_2A+ \beta_3(T\times A) +\varepsilon \]

The treatment effect at age \(A\) is:

\[ \text{Treatment Effect}(A) = \beta_1+\beta_3A \]

Suppose the estimates are:

Parameter Estimate
\(\beta_1\) -5.0
\(\beta_2\) 0.10
\(\beta_3\) -0.08

At the mean age, where \(A=0\), the treatment effect is:

\[ -5.0 \]

At a patient who is 10 years above the mean:

\[ -5.0+(-0.08)(10) = -5.8 \]

At a patient who is 10 years below the mean:

\[ -5.0+(-0.08)(-10) = -4.2 \]

The negative interaction coefficient indicates that the treatment effect becomes more negative as age increases.

Interaction With a Binary Predictor

The interpretation becomes particularly intuitive when one predictor is binary. Consider:

\[ Y= \beta_0+ \beta_1T+ \beta_2X+ \beta_3(TX) +\varepsilon \]

where \(T=0\) represents placebo and \(T=1\) represents treatment.

For placebo:

\[ E(Y\mid T=0,X) = \beta_0+\beta_2X \]

For treatment:

\[ E(Y\mid T=1,X) = \beta_0+\beta_1+\beta_2X+\beta_3X \]

which can be rearranged to:

\[ E(Y\mid T=1,X) = \beta_0+\beta_1+(\beta_2+\beta_3)X \]

Therefore:

1
Placebo slope: \(\beta_2\)
2
Treatment slope: \(\beta_2+\beta_3\)
3
Difference in slopes: \(\beta_3\)

Interaction in Logistic Regression

Interaction terms are not restricted to ordinary linear regression. They can also be used in logistic regression.

For a binary outcome, consider:

\[ \operatorname{logit}\{P(Y=1)\} = \beta_0+ \beta_1X_1+ \beta_2X_2+ \beta_3X_1X_2 \]

The interaction coefficient operates on the log-odds scale.

For a one-unit increase in \(X_1\), the conditional change in log odds is:

\[ \beta_1+\beta_3X_2 \]

The corresponding conditional odds ratio is:

\[ \operatorname{OR}(X_2) = \exp(\beta_1+\beta_3X_2) \]
Important: In logistic regression, the interaction coefficient itself is not generally an odds ratio. Exponentiating \(\beta_3\) gives the multiplicative change in the conditional odds ratio associated with a one-unit increase in the interacting variable.

Worked Logistic Regression Example

Suppose a clinical study models the probability of treatment response as a function of treatment and baseline biomarker level. The model is:

\[ \operatorname{logit}(P) = -1.20+ 0.80T+ 0.30B+ (-0.20)(T\times B) \]

For placebo (\(T=0\)), the biomarker coefficient is:

\[ 0.30 \]

For treatment (\(T=1\)), the biomarker coefficient becomes:

\[ 0.30-0.20 = 0.10 \]

Thus, the biomarker-response relationship differs between treatment groups.

The treatment effect on the log-odds scale is:

\[ 0.80-0.20B \]

At \(B=0\), the treatment odds ratio is:

\[ \exp(0.80)\approx2.23 \]

At \(B=2\), it becomes:

\[ \exp(0.80-0.40) = \exp(0.40) \approx1.49 \]

The treatment effect therefore becomes weaker as the biomarker increases.

Interaction in Cox Regression

Interactions can also be incorporated into proportional hazards models. For example:

\[ h(t\mid X_1,X_2) = h_0(t) \exp \left( \beta_1X_1+ \beta_2X_2+ \beta_3X_1X_2 \right) \]

The hazard ratio associated with a one-unit increase in \(X_1\), conditional on \(X_2\), is:

\[ HR(X_2) = \exp(\beta_1+\beta_3X_2) \]

Thus, the treatment hazard ratio can vary according to the value of the interacting covariate.

Three Important Types of Interactions

Interaction Example Typical Interpretation
Continuous × Continuous Age × Biomarker Effect of age changes with biomarker level
Binary × Continuous Treatment × Age Treatment effect changes with age
Categorical × Categorical Treatment × Sex Treatment effect differs between groups

Interaction vs. Confounding

Interaction and confounding are related concepts but are not the same.

Confounding occurs when an extraneous variable distorts the estimated association between an exposure and outcome.

Interaction, or effect modification, occurs when the magnitude or direction of an effect genuinely differs according to another variable.

Key distinction: A confounder is something we generally want to control for. An effect modifier is scientifically important because the effect itself differs across levels of the modifier.

For example, if treatment appears to work differently in younger and older patients, age may be an effect modifier rather than simply a confounder.

Do You Always Need a Significant Interaction P-Value?

Not necessarily.

A common strategy is to test:

\[ H_0:\beta_3=0 \]

versus:

\[ H_A:\beta_3\ne0 \]

A small p-value provides evidence that the effect varies according to the interacting variable.

However, interaction tests often have relatively low statistical power, especially when subgroup sample sizes are small.

Therefore, interpretation should consider:

  • the estimated interaction effect
  • the confidence interval
  • the clinical plausibility of effect modification
  • the prespecified analysis plan
  • the number of interactions examined
  • the precision of subgroup-specific estimates
Clinical interpretation matters. A statistically nonsignificant interaction does not prove that the treatment effect is identical across all subgroups.

Why Interaction Tests Often Have Low Power

Suppose a treatment effect is estimated precisely, but the difference between two treatment effects must also be estimated. The interaction is effectively testing that difference.

For example:

\[ H_0: \text{Treatment Effect}_{A} = \text{Treatment Effect}_{B} \]

This comparison can require considerably more information than estimating the overall treatment effect.

Consequently, subgroup interaction analyses should generally be interpreted with appropriate caution, especially in trials that were not powered for effect modification.

Reference Categories Matter

For categorical predictors, the coding scheme determines the interpretation of the coefficients. Suppose treatment is coded:

  • Placebo = 0
  • Active treatment = 1

Then the treatment coefficient represents the treatment-versus-placebo contrast at the reference value of the interacting variable.

Changing the reference category changes the individual coefficient values, but it does not change the fitted model or its predicted values.

Practical lesson: When reporting an interaction, always state the reference categories and the reference value used for continuous interacting variables.

Visualizing Interactions

Interaction models are often much easier to understand graphically than from a coefficient table alone.

A useful visualization displays predicted outcomes across values of one predictor separately for levels of the other predictor.

For example, a treatment-by-age interaction can be displayed as predicted outcome versus age, with separate curves for treatment and placebo.

1
Fit the regression model containing the interaction.
2
Choose clinically meaningful values of the interacting variable.
3
Calculate model-based predicted outcomes.
4
Plot predicted outcomes separately by treatment or subgroup.
5
Add confidence intervals to communicate uncertainty.

R Implementation

In R, an interaction can be specified using the * operator.

fit <- lm(
  outcome ~ treatment * age,
  data = trial
)

summary(fit)

The expression:

treatment * age

expands to:

treatment + age + treatment:age

Thus, the * operator includes both main effects and the interaction.

If only the interaction term is requested, the : operator can be used:

outcome ~ treatment + age + treatment:age

R: Logistic Regression With an Interaction

fit <- glm(
  response ~ treatment * biomarker,
  data = trial,
  family = binomial()
)

summary(fit)

For model interpretation, it is often useful to calculate predicted probabilities at clinically meaningful biomarker values.

newdat <- expand.grid(
  treatment = c("Placebo", "Active"),
  biomarker = c(0, 1, 2, 3)
)

newdat$predicted <- predict(
  fit,
  newdata = newdat,
  type = "response"
)

R: Visualizing the Interaction

library(ggplot2)

ggplot(newdat,
       aes(x = biomarker,
           y = predicted,
           group = treatment,
           linetype = treatment)) +
  geom_line(linewidth = 1) +
  geom_point(size = 2) +
  labs(
    x = "Biomarker",
    y = "Predicted probability",
    linetype = "Treatment"
  ) +
  theme_minimal()

For clinical reporting, model-based plots are often more interpretable than simply presenting the interaction coefficient.

SAS Implementation

In SAS PROC GLM or PROC GENMOD, the interaction can be specified using an asterisk.

proc glm data=trial;
    class treatment;
    model outcome =
        treatment
        age
        treatment*age;
run;

For logistic regression:

proc genmod data=trial;
    class treatment;
    model response(event='1') =
        treatment
        biomarker
        treatment*biomarker
        / dist=binomial link=logit;
run;

The product term is represented explicitly as:

treatment*biomarker

Using LS-Means and Contrasts in SAS

When categorical variables and interactions are involved, estimated marginal means and contrasts can be useful for communicating clinically relevant comparisons.

proc genmod data=trial;
    class treatment sex;
    model response(event='1') =
        treatment
        sex
        treatment*sex
        / dist=binomial link=logit;

    lsmeans treatment*sex
        / ilink diff oddsratio;
run;

The exact options appropriate for a particular analysis depend on the model, endpoint, estimand, and reporting objective.

Interaction Terms in Clinical Trial Subgroup Analysis

A treatment-by-subgroup interaction is one of the most common applications of interaction modeling in clinical research.

Suppose the primary treatment comparison is:

\[ H_0:\theta_T=0 \]

and investigators want to determine whether the treatment effect differs by subgroup \(S\).

An interaction model is:

\[ Y= \beta_0+ \beta_1T+ \beta_2S+ \beta_3(T\times S) +\varepsilon \]

The null hypothesis for effect modification is:

\[ H_0:\beta_3=0 \]

The alternative is:

\[ H_A:\beta_3\ne0 \]

This directly asks whether the treatment effect differs between subgroup levels.

Do Not Test Each Subgroup Separately

A common but misleading approach is to calculate a p-value for treatment within each subgroup and then conclude that an interaction exists if one subgroup is statistically significant and the other is not.

Classic mistake: “Significant in subgroup A but not significant in subgroup B” does not imply that the treatment effects differ significantly between A and B.

The appropriate statistical question is whether the difference between the treatment effects is itself supported by the data.

\[ H_0: \theta_A-\theta_B=0 \]

The interaction term provides a direct way to evaluate this difference.

Continuous Interactions: Choosing Meaningful Values

For continuous modifiers such as age, weight, renal function, or biomarker level, the interaction coefficient describes a continuous relationship.

However, readers often want interpretable treatment effects at specific values. Useful values might include:

  • the mean
  • the median
  • clinically meaningful thresholds
  • selected percentiles
  • predefined clinical categories

For example, if age is the modifier, treatment effects might be reported at 50, 60, 70, and 80 years.

Do not arbitrarily categorize a continuous variable just to make an interaction easier to display. Categorization can discard information and create artificial thresholds. When scientifically appropriate, retaining the continuous variable and reporting model-based effects at meaningful values is often preferable.

Interaction and Nonlinearity

An interaction term should not be used as a substitute for modeling nonlinearity.

For example, suppose the relationship between age and outcome is curved. A linear age term may be inadequate even if age interacts with treatment.

A more appropriate model might contain both nonlinear terms and an interaction, such as:

\[ Y= \beta_0+ \beta_1T+ f(A)+ Tg(A)+ \varepsilon \]

where \(f(A)\) represents the baseline relationship between age and outcome and \(g(A)\) represents how that relationship changes with treatment.

In practice, splines or other flexible functions can sometimes provide a better representation than forcing a linear interaction.

Three Ways to Interpret an Interaction

Approach Question Answered
Interaction coefficient Does the effect change as the modifier changes?
Conditional effect What is the treatment effect at a specific modifier value?
Predicted outcome plot How does the model behave across the observed range?

For clinical interpretation, it is often best to use all three.

Confidence Intervals Are Essential

A point estimate alone does not communicate how precisely an interaction has been estimated.

Suppose the interaction estimate is:

\[ \hat{\beta}_3=-0.20 \]

A confidence interval such as:

\[ 95\%\ CI=(-0.35,-0.05) \]

suggests substantially different evidence from a much wider interval such as:

\[ 95\%\ CI=(-0.80,0.40) \]

Even though both estimates are negative, the second result is considerably less precise.

Common Mistakes

  1. Interpreting the main effect as the overall effect. With an interaction present, the main effect is conditional on the reference value of the interacting variable.
  2. Including an interaction without its main effects. In most conventional regression models, if an interaction is included, its component main effects should also be included unless there is a specific reason not to do so.
  3. Concluding interaction from separate subgroup p-values. The correct test compares the effects directly through the interaction or an equivalent contrast.
  4. Ignoring the coding of categorical variables. Reference categories determine how coefficients are interpreted.
  5. Ignoring the scale of a continuous modifier. A one-unit change in age is very different from a one-unit change in a standardized biomarker.
  6. Reporting only the interaction p-value. The estimated effects, confidence intervals, and clinically meaningful conditional estimates should also be considered.
  7. Overinterpreting exploratory subgroup interactions. A large number of subgroup analyses increases the opportunity for apparently interesting findings to arise by chance.
  8. Assuming a nonsignificant interaction proves identical effects. A nonsignificant result may reflect limited precision or low power.
  9. Ignoring nonlinear relationships. A linear interaction can be inadequate if the underlying predictor-outcome relationship is nonlinear.

A Practical Interaction Modeling Workflow

1
Define the scientific question: whose or what effect might differ?
2
Identify the exposure or treatment and the potential effect modifier.
3
Choose appropriate reference categories or centering values.
4
Fit the model containing both main effects and the interaction.
5
Examine the interaction estimate and confidence interval.
6
Calculate conditional treatment effects at clinically meaningful values.
7
Visualize predicted outcomes or effects across the modifier.
8
Assess whether the interaction was prespecified or exploratory.
9
Interpret statistical evidence alongside clinical plausibility.
10
Report the interaction, conditional effects, confidence intervals, and reference values clearly.

How to Report an Interaction

A good clinical report should make the interaction interpretable without requiring the reader to reconstruct the regression coding.

For example:

Example reporting language: The treatment-by-age interaction estimate was \(-0.08\) units per year (95% CI: \(-0.15\) to \(-0.01\)), indicating that the estimated treatment effect became more favorable with increasing age. At the mean age, the estimated treatment effect was \(-5.0\) units (95% CI: ...), compared with \(-5.8\) units at 10 years above the mean.

The exact reporting language should reflect the endpoint scale and the prespecified estimand.

Interaction Terms and Model Interpretation

The most useful way to think about an interaction is not as a mysterious additional coefficient, but as a statement about different slopes or different treatment effects.

For a continuous-by-continuous interaction:

\[ \text{Effect of }X_1 = \beta_1+\beta_3X_2 \]

For a binary treatment-by-continuous modifier:

\[ \text{Treatment Effect}(X) = \beta_1+\beta_3X \]

For a binary treatment-by-binary subgroup interaction, \(\beta_3\) represents the difference between the treatment effects in the two subgroup categories, subject to the model's coding.

Worked Example Summary

Consider a randomized trial with treatment \(T\) and centered age \(A\). The model is:

\[ Y= \beta_0+ \beta_1T+ \beta_2A+ \beta_3(T\times A) +\varepsilon \]

The key interpretations are:

Quantity Interpretation
\(\beta_0\) Expected outcome for placebo at mean age
\(\beta_1\) Treatment effect at mean age
\(\beta_2\) Age effect among placebo patients
\(\beta_3\) Change in treatment effect per one-unit increase in centered age
\(\beta_1+\beta_3A\) Treatment effect at age value \(A\)

The Most Important Concept

The most important conceptual point is that an interaction changes the question being answered by the regression model.

Without an interaction, the model asks: What is the effect of \(X_1\), holding \(X_2\) constant?

With an interaction, the model asks: How does the effect of \(X_1\) change as \(X_2\) changes?

Bottom line: An interaction term is used when the effect of one predictor is expected to depend on another predictor. In a regression model, the interaction is represented by a product term such as \(X_1X_2\). Its coefficient describes how the effect changes across the interacting variable. In clinical research, interaction terms are particularly important for treatment-by-subgroup and treatment-by-biomarker analyses. The clearest interpretation usually combines the interaction coefficient with conditional treatment effects, confidence intervals, and model-based plots.

References

Aiken, L.S. & West, S.G. (1991). Multiple Regression: Testing and Interpreting Interactions. Sage Publications.

Kaufman, R.L. (2019). Interaction Effects in Linear and Generalized Linear Models. SAGE Publications.

Harrell, F.E. (2015). Regression Modeling Strategies. Springer.

Hosmer, D.W., Lemeshow, S. & Sturdivant, R.X. (2013). Applied Logistic Regression. Wiley.

Klein, J.P. & Moeschberger, M.L. (2003). Survival Analysis: Techniques for Censored and Truncated Data. Springer.

VanderWeele, T.J. (2015). Explanation in Causal Inference: Methods for Mediation and Interaction. Oxford University Press.