Why Interact a Factor With a Numeric Predictor?
A model with a factor and a numeric predictor can represent different patterns across categories. If the model includes only additive main effects, the factor can shift the fitted response up or down, but every category has the same slope with respect to the numeric predictor. An interaction allows the slope itself to vary by category. This matters when, for example, a hypothetical insurer finds that the relationship between policy tenure and predicted annual cost differs across policy types.
The aim here is to read the model coefficients as category-specific lines. The formulas below use treatment coding: one factor category is the reference, and each other category has an indicator equal to 1 for that category and 0 otherwise. The category-specific fitted lines follow by substituting those indicator values into the model.
The Model and Its Category-Specific Lines
First consider a factor with two categories. Let \(D=0\) identify the reference category and \(D=1\) identify the other category. Let \(x\) be numeric and \(Y\) the response. A linear model with the interaction is
Here, \(\varepsilon\) is the model error, with conditional mean zero given \(x\) and \(D\). Thus the model’s conditional mean is the part of the expression not involving \(\varepsilon\). The fitted coefficients, written with hats, give the estimated conditional mean. The algebraic interpretation of those fitted coefficients does not require a normal error distribution. Inference procedures may require additional assumptions, but they are not needed to derive the lines.
For the reference category, \(D=0\), so both terms containing \(D\) are zero. For the other category, \(D=1\), so the \(D\) term contributes \(\beta_2\) and the \(Dx\) term contributes \(\beta_3x\). Therefore:
The reference-category intercept and slope are \(\hat{\beta}_0\) and \(\hat{\beta}_1\). For the other category, the intercept is \(\hat{\beta}_0+\hat{\beta}_2\), and the slope is \(\hat{\beta}_1+\hat{\beta}_3\). The factor main effect does not by itself alter the slope; the interaction coefficient does.
For a factor with \(K\) categories, use one reference category and an indicator \(D_j\) for each of the other \(K-1\) categories. A model including the numeric main effect, factor main effects, and factor-by-numeric interactions is
The reference category has every \(D_j=0\), giving fitted line \(\hat{\beta}_0+\hat{\beta}_1x\). In category \(j\), its indicator is 1 and all the other indicators are 0. Substitution gives the fitted line \((\hat{\beta}_0+\hat{\gamma}_j)+(\hat{\beta}_1+\hat{\delta}_j)x\). Thus, for every non-reference category, add its factor main-effect coefficient to the intercept and its interaction coefficient to the numeric slope.
Worked Lines From a Binary Factor
Worked Example: Predicted Cost by Service Channel
A hypothetical service study models predicted cost \(Y\), in dollars, using \(x\), the number of service units. The factor is channel, with standard as the reference and priority as the other category. The fitted model is \(\widehat{Y}=120+8x-15D+3.5Dx\), where \(D=1\) for priority and \(D=0\) for standard. Derive both fitted lines, calculate the predictions at \(x=4\), and check the priority prediction by direct substitution.
Method and model. Treat the stated equation as the fitted conditional-mean model. The units of \(x\) are service units and the units of \(\widehat{Y}\) are dollars. No error distribution is needed for these fitted-value calculations.
Standard channel. Set \(D=0\). The terms \(-15D\) and \(3.5Dx\) vanish:
Its fitted intercept is \(120\) dollars and its slope is \(8\) dollars per service unit.
Priority channel. Set \(D=1\):
The main effect lowers the intercept by \(15\) dollars relative to standard. The interaction increases the slope by \(3.5\) dollars per service unit.
At \(x=4\), standard predicts \(120+8(4)=120+32=152\) dollars. Priority predicts \(105+11.5(4)=105+46=151\) dollars. Check priority using the original model: \(120+8(4)-15+3.5(4)=120+32-15+14=151\) dollars, matching the line calculation.
Common mistake avoided: Treating \(-15\), the factor main effect, as a slope adjustment. It changes the intercept; the \(3.5\) interaction changes the slope.
Extending the Calculation to Several Categories
With more than two categories, each non-reference category has its own main-effect and interaction coefficient. The reference line remains the starting point. For a specific category, use only that category’s indicator: its main effect adjusts the reference intercept, and its interaction adjusts the reference slope. This produces one fitted line per category without needing a separate unrelated model for each one.
Worked Example: Three Types of Equipment
A hypothetical maintenance analysis models predicted monthly expense \(Y\), in dollars, against operating time \(x\), in hundreds of hours. Equipment type A is the reference; types B and C have indicators \(D_B\) and \(D_C\). The fitted model is \(\widehat{Y}=30+4x+12D_B-1.5D_Bx-8D_C+2D_Cx\). Derive the three fitted lines and find the prediction for each type at \(x=5\).
Method and model. Use the treatment-coded equation as given, with \(D_B=1\) only for type B and \(D_C=1\) only for type C. The numeric value \(x=5\) means 500 operating hours.
Type A, the reference. Both indicators are zero, so \(\widehat{Y}_A=30+4x\). At \(x=5\), this is \(30+4(5)=30+20=50\) dollars.
Type B. Set \(D_B=1\) and \(D_C=0\):
At \(x=5\), the prediction is \(42+2.5(5)=42+12.5=54.5\) dollars.
Type C. Set \(D_B=0\) and \(D_C=1\):
At \(x=5\), the prediction is \(22+6(5)=22+30=52\) dollars. The three predictions are therefore \(50\), \(54.5\), and \(52\) dollars for types A, B, and C, respectively.
Check. Substituting \(x=5\) and the appropriate indicators into the original equation gives A: \(30+20=50\); B: \(30+20+12-7.5=54.5\); C: \(30+20-8+10=52\). Each agrees with its fitted line.
Common mistake avoided: Applying both non-reference categories’ coefficients to the same observation. A type B observation has \(D_B=1,D_C=0\); a type C observation has \(D_B=0,D_C=1\).
Why the Interaction Produces Different Slopes
The slope is the coefficient multiplying \(x\) in a category’s fitted line. In the binary model, the terms involving \(x\) are \(\beta_1x+\beta_3Dx\). When \(D=0\), the second term disappears and the slope is \(\beta_1\). When \(D=1\), the two terms combine to \((\beta_1+\beta_3)x\), so the slope is \(\beta_1+\beta_3\). This substitution is the reason the interaction coefficient is a slope adjustment.
If \(\beta_3=0\), the two slopes are both \(\beta_1\), even if \(\beta_2\) is nonzero. The category lines may then have different intercepts but are parallel. If \(\beta_2=0\) but \(\beta_3\) is nonzero, they share an intercept at \(x=0\) but have different slopes. These are consequences of the model’s algebra, not claims that the categories must behave that way in a particular application.
The interpretation relies on including the numeric and factor main effects along with their interaction. The response relationship is assumed linear in \(x\) within each category over the range being modeled. If the relationship is curved, or if the fitted line is used far outside the observed range, these lines may not provide an adequate or reliable description. An interaction represents a modeled difference in slopes; it does not establish why that difference occurs.
Common Exam Traps
- Putting the factor main effect into the slope. In \(\beta_0+\beta_1x+\beta_2D+\beta_3Dx\), \(\beta_2\) is added to the intercept and \(\beta_3\) to the slope for \(D=1\).
- Forgetting to add the baseline coefficient. A non-reference slope is not just the interaction coefficient. It is \(\hat{\beta}_1+\hat{\beta}_3\).
- Using the wrong indicator values. For a treatment-coded factor, only the indicator for the observed non-reference category is 1; the other category indicators are 0.
- Calling every factor model an interaction model. Factor main effects alone can shift fitted lines vertically. Category-specific slopes require factor-by-numeric interaction terms.
- Ignoring units. If \(x\) is measured in hundreds of hours, a slope is dollars per hundred hours, not dollars per hour.
A reliable exam calculation is to write the full model, state the indicator values for the category, substitute them, collect the constant terms, and then collect the terms multiplying \(x\). Calculate predictions only after the category-specific line is clear. This method is aligned with the SOA Exam PA (Predictive Analytics) syllabus.
Check Your Understanding
For each problem, derive the required category-specific line before calculating the requested prediction.
- A fitted model is \(\widehat{Y}=18+2x+7D-0.5Dx\), with \(D=1\) for the non-reference category. Find that category’s line and its prediction at \(x=6\). (Answer: \(\widehat{Y}=25+1.5x\); at \(x=6\), \(\widehat{Y}=34\).)
- A three-category model has reference line \(10+3x\), while category B has main effect \(-2\) and interaction \(+1\), and category C has main effect \(+5\) and interaction \(-2\). Find all three predictions at \(x=4\). (Answer: reference \(22\), B \(24\), C \(19\).)
- A binary-factor model is \(\widehat{Y}=90+5x+12D-2Dx\). State the reference and \(D=1\) slopes, then calculate the \(D=1\) prediction at \(x=7\). (Answer: reference slope \(5\), \(D=1\) slope \(3\); prediction \(123\).)
- For a factor with reference category R and category S, the fitted model is \(\widehat{Y}=400+25x-60D-4Dx\), where \(D=1\) for S. Derive both lines and calculate their predictions at \(x=8\). (Answer: R is \(400+25x\), predicting \(600\); S is \(340+21x\), predicting \(508\).)
- A model for categories A, B, and C has reference A line \(50+6x\). Category B has main effect \(10\) and interaction \(-2\); category C has main effect \(-5\) and interaction \(+3\). Derive the B and C lines and calculate each prediction at \(x=3\), checking that the category with the largest intercept need not have the largest slope. (Answer: B is \(60+4x\), predicting \(72\); C is \(45+9x\), predicting \(72\). B has the larger intercept, while C has the larger slope.)