Tutorials › Exam PA - Predictive Analytics › Changing the Reference Level in an Interaction Model

Exam PA · Categorical Encoding and Interactions · Tutorial 247 of 966

Changing the Reference Level in an Interaction Model

Learn to re-express factor main effects and interaction coefficients under a new reference category while preserving every group-specific line.

Intermediate 11 min read

What You'll Learn

  • Write group-specific lines from a treatment-coded factor-numeric interaction model
  • Derive new intercept, slope, and interaction coefficients after changing the reference level
  • Verify that re-referencing preserves fitted values for every factor level
  • Distinguish reference-dependent coefficients from reference-invariant group predictions
  • Avoid sign errors when calculating effects relative to a new reference

Why Change the Reference Level?

In a factor-numeric interaction model, each factor category can have its own intercept and its own slope with respect to the numeric predictor. Treatment coding expresses those differences relative to one chosen reference category. Changing that reference changes the coefficient values, but it does not change the group-specific lines represented by the model.

This distinction matters when a model’s original reference category is not the most useful comparison for interpretation. For example, an analyst may want to describe every category relative to a newly selected benchmark. The key is to calculate each new effect as a difference from the new reference, not to copy the old effects or change their signs indiscriminately.

Definition: In a factor-numeric interaction model, the factor main effects describe differences in intercepts relative to the reference category, and the interaction coefficients describe differences in slopes relative to that category. Changing the reference level re-expresses those differences; it does not change the fitted line for any category.

Model and Coefficients Under Treatment Coding

Consider a response \(Y\), a numeric predictor \(x\), and a factor \(G\) with categories \(A\), \(B\), and \(C\). Assume the conditional mean is linear in \(x\) within each category. With \(A\) as the reference category, write the model as

$$ E(Y\mid G,x)=\beta_0+\beta_x x +\beta_B I(G=B)+\beta_{Bx}xI(G=B) +\beta_C I(G=C)+\beta_{Cx}xI(G=C). $$

Here \(I(G=B)\) equals 1 when an observation belongs to category \(B\), and 0 otherwise; \(I(G=C)\) is defined similarly. The conditional-mean lines are therefore

$$ \begin{aligned} A &: \beta_0+\beta_x x,\\ B &: (\beta_0+\beta_B)+(\beta_x+\beta_{Bx})x,\\ C &: (\beta_0+\beta_C)+(\beta_x+\beta_{Cx})x. \end{aligned} $$

The reference category \(A\) has no indicator terms, so its intercept is \(\beta_0\) and its slope is \(\beta_x\). Category \(B\)'s intercept differs from \(A\)'s by \(\beta_B\), and its slope differs by \(\beta_{Bx}\). The same interpretation applies to \(C\). These are comparisons at the chosen coordinate \(x=0\) for intercepts, and comparisons of change per one-unit increase in \(x\) for slopes.

This algebra applies directly to a linear model for the conditional mean. For a generalized linear model, the same reparameterization applies to the linear predictor \(\eta=g(\mu)\), where \(\mu=E(Y\mid G,x)\) and \(g\) is the link function. In that setting, the transformed coefficients are differences on the link scale; the response-scale means are obtained by applying the inverse link. The formulas below do not claim that response-scale differences remain constant for a nonlinear inverse link.

Deriving the New Coefficients

Suppose category \(B\) becomes the reference. Its line under the original parameterization is \((\beta_0+\beta_B)+(\beta_x+\beta_{Bx})x\), so those two quantities become the new baseline intercept and slope. Each other category’s new effects are its old group-line coefficients minus the corresponding coefficients of \(B\).

$$ \begin{aligned} \text{New baseline intercept} &= \beta_0+\beta_B,\\ \text{New baseline slope} &= \beta_x+\beta_{Bx},\\ \text{New effect for } A\text{ (intercept)} &= -\beta_B,\\ \text{New effect for } A\text{ (slope)} &= -\beta_{Bx},\\ \text{New effect for } C\text{ (intercept)} &= \beta_C-\beta_B,\\ \text{New effect for } C\text{ (slope)} &= \beta_{Cx}-\beta_{Bx}. \end{aligned} $$

The signs follow from subtraction: for instance, \(A\)'s intercept relative to \(B\) is \(\beta_0-(\beta_0+\beta_B)=-\beta_B\). Its slope relative to \(B\) is \(\beta_x-(\beta_x+\beta_{Bx})=-\beta_{Bx}\). Likewise, \(C\)'s intercept relative to \(B\) is \((\beta_0+\beta_C)-(\beta_0+\beta_B)=\beta_C-\beta_B\); its slope difference is \((\beta_x+\beta_{Cx})-(\beta_x+\beta_{Bx})=\beta_{Cx}-\beta_{Bx}\). This is why an effect relative to a new reference is generally a difference between two old effects, not merely one old coefficient with a possible sign change.

More generally, let the line for category \(g\) be \(\alpha_g+\gamma_g x\). If category \(r\) becomes the reference, its new baseline is \(\alpha_r+\gamma_r x\), and category \(g\)'s new intercept and slope effects are \(\alpha_g-\alpha_r\) and \(\gamma_g-\gamma_r\), respectively. This form works for any number of factor levels, provided the same linear-in-\(x\) model is being re-expressed.

Justification: A re-reference is a change in how the same category-specific lines are written. For each category \(g\), subtract the reference line \(\alpha_r+\gamma_r x\) from its line \(\alpha_g+\gamma_g x\). The difference is \((\alpha_g-\alpha_r)+(\gamma_g-\gamma_r)x\), which gives exactly the new treatment-coded effects. Adding this difference back to the reference line recovers \(\alpha_g+\gamma_g x\), so the fitted line is preserved.

Worked Example: Changing the Reference from A to B

Problem. A hypothetical linear model has category \(A\) as its reference, with baseline line \(12-3x\). Category \(B\) has an intercept effect of \(-2\) and a slope effect of \(5\); category \(C\) has an intercept effect of \(4\) and a slope effect of \(1\). Re-express the model with \(B\) as the reference, then find \(C\)'s prediction at \(x=2\). Treat the displayed lines as conditional means.

Method. First write each category's complete line. Then use \(B\)'s intercept and slope as the new baseline and subtract \(B\)'s coefficients from the other categories' coefficients.

The original lines are:

$$ \begin{aligned} A &: 12-3x,\\ B &: (12-2)+(-3+5)x=10+2x,\\ C &: (12+4)+(-3+1)x=16-2x. \end{aligned} $$

Thus the new baseline, category \(B\), is \(10+2x\). Category \(A\)'s new intercept effect is \(12-10=2\), and its new slope effect is \(-3-2=-5\). Category \(C\)'s new intercept effect is \(16-10=6\), and its new slope effect is \(-2-2=-4\). The re-expressed lines are \(B:10+2x\), \(A:(10+2)+ (2-5)x=12-3x\), and \(C:(10+6)+(2-4)x=16-2x\).

At \(x=2\), category \(C\)'s prediction is \(10+2(2)+6-4(2)=10+4+6-8=12\). Check against its original line: \(16-2(2)=12\). Both parameterizations give the same result.

Common mistake avoided: Adding \(C\)'s old effects to the new baseline would incorrectly give effects of \(4\) and \(1\). The correct differences are \(4-(-2)=6\) and \(1-5=-4\), because the new reference \(B\) already has nonzero effects relative to \(A\).

Worked Example: Re-referencing to Category C

Problem. A hypothetical model with \(A\) as reference has baseline \(6+0.5x\). Category \(B\)'s effects are \(2\) and \(1.5\) for intercept and slope; category \(C\)'s effects are \(-3\) and \(-2\). Find the model with \(C\) as reference and calculate \(B\)'s prediction at \(x=4\).

Method. Calculate the original group lines, use \(C\)'s line as the new baseline, and subtract \(C\)'s intercept and slope from the corresponding quantities for \(B\).

The original lines are \(A:6+0.5x\), \(B:(6+2)+(0.5+1.5)x=8+2x\), and \(C:(6-3)+(0.5-2)x=3-1.5x\). The new baseline is therefore \(3-1.5x\).

For \(B\), the new intercept effect is \(8-3=5\), and its new slope effect is \(2-(-1.5)=3.5\). For completeness, \(A\)'s new effects are \(6-3=3\) and \(0.5-(-1.5)=2\). The re-referenced lines are \(C:3-1.5x\), \(B:(3+5)+(-1.5+3.5)x=8+2x\), and \(A:(3+3)+(-1.5+2)x=6+0.5x\).

At \(x=4\), \(B\)'s prediction is \(3-1.5(4)+5+3.5(4)=3-6+5+14=16\). The original \(B\) line gives \(8+2(4)=16\), confirming the calculation.

Common mistake avoided: The new slope effect for \(B\) is \(2-(-1.5)=3.5\), not \(2-1.5=0.5\). The reference category's actual slope is \(-1.5\), so that is the value that must be subtracted.

What Changes and What Does Not

Re-referencing changes the numerical values and interpretations of individual treatment-coded coefficients. It does not change the category-specific intercepts and slopes when reconstructed, the fitted conditional means, or (for an otherwise identical fitted model) its residuals and overall fit. In estimation, changing the reference is a reparameterization of the same model space: the columns used to describe that space may differ, but the represented group lines do not.

A coefficient test tied to one particular treatment-coded coefficient also changes its comparison when the reference changes. For example, a main-effect coefficient compares intercepts at \(x=0\), and an interaction coefficient compares slopes, each against the current reference. A test of whether all category-specific slopes are equal, however, concerns the same substantive restriction regardless of which category is chosen as reference. Do not confuse a changed coefficient interpretation with a changed fitted model.

The interpretation of an intercept difference depends on the origin of \(x\). If \(x=0\) is outside the range of practical interest, the intercept comparison may be an extrapolation. Centering \(x\) can make that comparison more useful, but centering and changing a factor reference are distinct transformations: centering changes the point at which intercepts are compared, while re-referencing changes the category used for comparison. This tutorial focuses on the latter.

In R, changing a factor's reference with a function such as relevel changes treatment contrasts when the model is fitted again. Provided the model terms and data are otherwise unchanged, the re-expressed model should give the same fitted values. It is good practice to verify a transformed coefficient set by reconstructing the line for each category, rather than relying only on coefficient labels. This topic is aligned with the SOA Exam PA (Predictive Analytics) syllabus.

A Reliable Re-referencing Procedure

1
Write each complete group line.
Combine the reference intercept and slope with the relevant factor main effect and interaction coefficient. Keep intercept terms separate from slope terms.
2
Select the new reference line.
Its complete intercept and slope become the new baseline coefficients.
3
Subtract to obtain every other effect.
For each non-reference category, subtract the new reference intercept from its intercept and the new reference slope from its slope.
4
Check reconstructed lines and predictions.
Combine the new baseline and effects to recover each original line. Evaluate at least one requested predictor value under both parameterizations.

Common Exam Traps

  • Changing signs without calculating differences. Only a former reference category gets effects that are the negatives of the old reference's effects. For a third category, subtract the new reference's effects from its own.
  • Mixing intercept and slope effects. A new main effect is an intercept difference; a new interaction coefficient is a slope difference. Keep their units and calculations distinct.
  • Adding the new effects twice. The new baseline already represents the new reference line. To obtain another category's effects, calculate differences from that line, then add those differences to the new baseline once.
  • Assuming the coefficients themselves are invariant. Their values depend on the reference coding. The reconstructed category-specific lines and fitted predictions are the invariant quantities.
  • Forgetting the scale in a GLM. With a non-identity link, these coefficient differences describe the linear predictor, not generally additive differences in the response mean.
Key takeaway: Write the full line for every factor category. The new reference's line becomes the baseline, and every other category's new intercept and slope effects are found by subtracting the new reference's corresponding coefficients. Reconstructing the lines is the most direct check.

Check Your Understanding

For each problem, identify the new baseline and effects, then check a line or prediction against the original parameterization.

  1. A model uses \(A\) as reference with baseline \(9-2x\); \(B\)'s effects are \(3\) and \(1\), and \(C\)'s are \(-1\) and \(4\). Change the reference to \(B\), then find \(C\)'s prediction at \(x=1\). (Answer: New baseline \(12-x\); \(C\)'s effects \(-4,3\); prediction \(10\).)
  2. A model has \(A\)-reference baseline \(4+3x\), \(B\)'s effects \(-2,-1\), and \(C\)'s effects \(5,-2\). Change the reference to \(C\), and calculate \(B\)'s prediction at \(x=2\). (Answer: New baseline \(9+x\); \(B\)'s effects \(-7,1\); prediction \(6\).)
  3. An \(A\)-reference model has baseline \(30+0.25x\), \(B\)'s effects \(6,-0.5\), and \(C\)'s effects \(-2,1.5\). Re-reference to \(B\) and find \(C\)'s prediction at \(x=4\). (Answer: New baseline \(36-0.25x\); \(C\)'s effects \(-8,2\); prediction \(35\).)
  4. The three category lines in a hypothetical model are \(A:100+4x\), \(B:90+7x\), and \(C:105+2x\). With \(C\) as reference, find the new effects for \(A\) and \(B\), then verify \(B\)'s prediction at \(x=3\). (Answer: \(A\)'s effects \(-5,2\); \(B\)'s effects \(-15,5\); \(B\)'s prediction \(111\).)
  5. With \(A\) as reference, a model has baseline \(5+2x\), \(B\)'s effects \(3,-2\), and \(C\)'s effects \(-4,0\). Change the reference to \(B\). What are \(A\)'s and \(C\)'s slope effects, and do the three category slopes become equal? (Answer: New baseline slope \(0\); \(A\)'s slope effect \(2\), \(C\)'s slope effect \(2\); no, the slopes are \(2,0,2\).)
Clinical Biostats