Tutorials › Exam PA - Predictive Analytics › Centering a Numeric Predictor for Interaction Interpretation

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

Centering a Numeric Predictor for Interaction Interpretation

See how centering makes a factor effect interpretable at a chosen predictor value without changing model predictions or group-specific slopes.

Intermediate 12 min read

What You'll Learn

  • Interpret a factor main effect at the numeric predictor’s centering point
  • Transform interaction-model coefficients after subtracting a constant
  • Verify that fitted values and category-specific slopes are unchanged
  • Apply centering to a logistic interaction model’s linear predictor
  • Avoid confusing a centered main effect with the effect at the original zero

Why Center a Predictor in an Interaction Model?

In an interaction model, the difference between categories can depend on the value of a numeric predictor. Under treatment coding, the factor’s main-effect coefficient gives the category difference when the numeric predictor equals zero. If zero is outside the useful range, or has no practical meaning, that coefficient may be difficult to interpret. Centering changes the point at which the difference is described.

Centering does not remove the interaction. It also does not change fitted values or the slope for any category. It changes the model’s coefficient interpretation by choosing a different reference value for the numeric predictor. This tutorial focuses on that change and on checking the resulting algebra.

Definition: To center a numeric predictor \(x\) at a constant \(c\), define \(x_c=x-c\). Thus \(x=x_c+c\), and \(x_c=0\) corresponds to the original predictor value \(x=c\). In a factor-by-numeric interaction model, the factor main-effect coefficient after centering is the category difference at \(x=c\).

Coefficient Transformation for a Binary Factor

Consider a linear regression with two factor categories. Let \(B=0\) denote the reference category and \(B=1\) the comparison category. Suppose the fitted conditional mean is

$$ \widehat{Y}=\hat{\beta}_0+\hat{\beta}_1x+\hat{\beta}_2B+\hat{\beta}_3xB. $$

Here \(\hat{\beta}_1\) is the reference category’s slope, \(\hat{\beta}_2\) is the difference between categories at \(x=0\), and \(\hat{\beta}_3\) is the difference in their slopes. For the comparison category, the fitted slope is \(\hat{\beta}_1+\hat{\beta}_3\).

Center at \(c\), so that \(x=x_c+c\). Substitution and collection of terms gives

$$ \begin{aligned} \widehat{Y} &=\hat{\beta}_0+\hat{\beta}_1(x_c+c)+\hat{\beta}_2B +\hat{\beta}_3(x_c+c)B\\ &=(\hat{\beta}_0+c\hat{\beta}_1) +\hat{\beta}_1x_c +(\hat{\beta}_2+c\hat{\beta}_3)B +\hat{\beta}_3x_cB. \end{aligned} $$

This derivation explains the key result: centering adds \(c\hat{\beta}_1\) to the intercept and \(c\hat{\beta}_3\) to the factor main effect. The coefficient of \(x_c\) remains \(\hat{\beta}_1\), and the interaction coefficient remains \(\hat{\beta}_3\). When \(x_c=0\), the original predictor is \(x=c\), so the new factor coefficient \(\hat{\beta}_2+c\hat{\beta}_3\) is exactly the category difference at that value.

Result: In a treatment-coded binary factor interaction, centering \(x\) at \(c\) leaves the category-specific slopes unchanged. It changes the intercept to the reference category’s fitted value at \(x=c\), and changes the factor main effect to the category difference at \(x=c\).

Worked Example: Reinterpreting a Category Difference at a Chosen Value

A hypothetical fitted linear regression for two policy-service groups is \(\widehat{Y}=80+3x+12B+2xB\), where \(B=0\) is Standard service and \(B=1\) is Priority service. Center \(x\) at 10, then calculate each group’s fitted value at \(x=14\). Assume the conditional mean is correctly represented by this linear interaction model. The algebraic transformation itself does not require an error-distribution assumption.

Method. Set \(x_c=x-10\), so \(x=x_c+10\). Substitute:

$$ \begin{aligned} \widehat{Y} &=80+3(x_c+10)+12B+2(x_c+10)B\\ &=80+3x_c+30+12B+2x_cB+20B\\ &=110+3x_c+32B+2x_cB. \end{aligned} $$

At \(x_c=0\), which means \(x=10\), the Priority-minus-Standard difference is 32. The original factor coefficient 12 described the difference at \(x=0\); the centered coefficient 32 describes it at \(x=10\). The Standard slope is 3, and the Priority slope is \(3+2=5\), both before and after centering.

At \(x=14\), \(x_c=14-10=4\). For Standard service, \(\widehat{Y}=110+3(4)=110+12=122\). For Priority service, \(\widehat{Y}=110+3(4)+32+2(4)=110+12+32+8=162\).

Check against the original model: Standard gives \(80+3(14)=122\). Priority gives \(80+3(14)+12+2(14)=80+42+12+28=162\). The fitted values agree. The common mistake this method avoids is reporting 12 as the difference at \(x=10\); that coefficient referred to \(x=0\).

More Than Two Categories

With several factor levels under treatment coding, the same transformation applies separately to each non-reference level. Suppose \(B\) and \(C\) indicate two categories relative to a reference category. Write the fitted model as

$$ \widehat{Y}=\hat{\beta}_0+\hat{\beta}_1x +\hat{\beta}_2B+\hat{\beta}_3C +\hat{\beta}_4xB+\hat{\beta}_5xC. $$

After setting \(x=x_c+c\), the new intercept is \(\hat{\beta}_0+c\hat{\beta}_1\). The new main effects are \(\hat{\beta}_2+c\hat{\beta}_4\) for \(B\) and \(\hat{\beta}_3+c\hat{\beta}_5\) for \(C\). The numeric slope and both interaction coefficients are unchanged. Each new main effect describes that category’s difference from the reference category at \(x=c\).

Worked Example: Centering a Three-Level Factor Interaction

A hypothetical fitted model compares service tiers A, B, and C, with A as the reference: \(\widehat{Y}=200+5x-20B+15C+1.5xB-2xC\). Center at \(x=40\), then find the fitted values for all tiers at \(x=44\). Assume this is a linear conditional-mean model; no probability model is needed for the coefficient transformation.

Method. Define \(x_c=x-40\), so \(x=x_c+40\). Substituting and collecting terms gives

$$ \begin{aligned} \widehat{Y} &=200+5(x_c+40)-20B+15C\\ &\quad+1.5(x_c+40)B-2(x_c+40)C\\ &=400+5x_c+40B-65C+1.5x_cB-2x_cC. \end{aligned} $$

For example, the B main effect becomes \(-20+1.5(40)=40\), and the C main effect becomes \(15-2(40)=-65\). At \(x=40\), B is estimated to be 40 units above A, while C is estimated to be 65 units below A. The slopes are A: 5, B: \(5+1.5=6.5\), and C: \(5-2=3\), unchanged by centering.

At \(x=44\), \(x_c=4\). The centered model gives A: \(400+5(4)=420\); B: \(400+5(4)+40+1.5(4)=466\); and C: \(400+5(4)-65-2(4)=347\). Check using the original model: A is \(200+5(44)=420\); B is \(200+220-20+1.5(44)=466\); and C is \(200+220+15-2(44)=347\). All three fitted values agree.

The trap is to change the main effects but forget the intercept. The intercept must also change, from 200 to \(200+5(40)=400\); otherwise the reference category’s fitted value at the centering point would be wrong.

Centering in a Generalized Linear Model

The same coefficient transformation holds for a generalized linear model when the interaction is written in its linear predictor. For a logistic model, this is the logit of the conditional event probability. Centering preserves the linear predictor at every observation, and therefore preserves fitted probabilities, provided the intercept and main-effect coefficients are transformed along with the predictor. The interpretation of a factor main effect is then a difference on the log-odds scale at \(x=c\), not a difference in probabilities.

Worked Example: Centering a Logistic Interaction

Suppose a hypothetical fitted logistic model for event probability \(p\) is \(\operatorname{logit}(p)=-2+0.04x+0.6B+0.01xB\), with \(B=0\) as the reference category. Center at \(x=50\), and calculate the fitted probabilities for both categories at \(x=60\). Assume the observations are modeled with a binomial response and this specified logit linear predictor.

Method. Let \(x_c=x-50\). Substitution gives

$$ \begin{aligned} \operatorname{logit}(p) &=-2+0.04(x_c+50)+0.6B+0.01(x_c+50)B\\ &=0+0.04x_c+1.1B+0.01x_cB. \end{aligned} $$

At \(x=60\), \(x_c=10\). For the reference category, the logit is \(0.04(10)=0.4\), so \(p=1/(1+e^{-0.4})\approx0.5987\). For \(B=1\), the logit is \(0.04(10)+1.1+0.01(10)=0.4+1.1+0.1=1.6\), so \(p=1/(1+e^{-1.6})\approx0.8320\). Probabilities are rounded to four decimal places.

Checking the original model gives reference logit \(-2+0.04(60)=0.4\) and comparison logit \(-2+0.04(60)+0.6+0.01(60)=1.6\). Thus the probabilities are unchanged. The centered main effect 1.1 is the log-odds difference at \(x=50\); it is not a probability difference.

Choosing and Applying the Centering Point

Choose \(c\) to make the factor comparison useful and supported by the data. It could be a meaningful operational value, such as a specified exposure amount, or a representative value such as the training-sample mean. The centering point does not have to be the mean. If a mean is used, calculate it on the training data and use that same constant when transforming new observations; recomputing a different center changes the coefficient interpretation.

Centering is a change of coordinates, not a new feature-selection decision. In a model that includes the intercept, the numeric predictor, the factor indicators, and their interactions, the transformed model spans the same set of fitted values. Keep the lower-order terms when including an interaction so that the model retains the standard hierarchical specification. In R, for a chosen constant \(c\), a centered variable can be created as x_c <- x - c and used in the same factor-by-numeric interaction structure.

The estimated main-effect coefficient and its standard error can change because the coefficient now represents a different contrast. That does not mean the fitted model has changed. Interpretation and inference should match the exact contrast being tested: a test of the factor main effect in the centered model concerns the category difference at \(x=c\). If \(c\) is far from the observed range, that interpretation may rely on extrapolation, even though the algebra remains valid.

Key takeaway: Centering \(x\) at \(c\) makes the factor main effect describe the category difference at \(x=c\). Transform the intercept and every factor main effect using the corresponding slope and interaction coefficient; leave numeric slopes and interactions unchanged. Then verify that predictions are identical.

Check Your Understanding

For each problem, identify what the centered factor effect means and check any requested prediction by substituting into the original model.

  1. A fitted model is \(\widehat{Y}=50+2x+8G-0.5xG\), where \(G=0\) is the reference group. Center at 10. Give the centered model and predict the \(G=1\) outcome at \(x=14\). (Answer: \(\widehat{Y}=70+2x_c+3G-0.5x_cG\); prediction \(79\).)
  2. A fitted model is \(\widehat{Y}=30+4x-6G+1.2xG\). Center at \(x=5\). What is the new factor main effect, and what category difference does it represent? (Answer: \(0\); the \(G=1\) minus \(G=0\) difference at \(x=5\).)
  3. A three-level factor model is \(\widehat{Y}=10+2x+3B-4C+0.5xB-0.2xC\), with A as reference. Center at \(x=10\). Give the new intercept and factor main effects, and state the three slopes. (Answer: intercept \(30\); B effect \(8\); C effect \(-6\); slopes A \(2\), B \(2.5\), C \(1.8\).)
  4. A logistic model has linear predictor \(-1+0.02x+0.3G+0.01xG\). Center at \(x=20\). Give the centered factor main effect and explain its scale. (Answer: \(0.5\), the log-odds difference between \(G=1\) and \(G=0\) at \(x=20\).)
  5. A colleague centers a model \(\widehat{Y}=12+3x+5G+2xG\) at \(x=4\), reports the new factor effect as 5, and leaves the intercept at 12. Identify both errors and give the correct centered model. (Answer: the factor effect should be \(5+2(4)=13\), and the intercept should be \(12+3(4)=24\); correct model: \(\widehat{Y}=24+3x_c+13G+2x_cG\).)
Clinical Biostats