Tutorials › Exam PA - Predictive Analytics › Common Errors in Factor and Interaction Interpretation

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

Common Errors in Factor and Interaction Interpretation

Use the model equation and reference level to identify exactly what a factor or interaction coefficient does—and what it does not mean.

Intermediate 11 min read

What You'll Learn

  • Distinguish a reference-coded coefficient from a category mean.
  • Interpret a factor coefficient as a contrast at the specified predictor value.
  • Calculate group-specific intercepts, slopes, predictions, and differences in an interaction model.
  • Recognize when numeric category codes impose a linear trend.
  • Choose and check an appropriate R encoding for nominal categories.

Why Coefficient Interpretation Goes Wrong

A regression coefficient is not automatically a group average, nor does a factor coefficient in an interaction model necessarily describe a constant difference between groups. Its meaning depends on the model formula, the reference level, and the values of the other predictors. Misreading these details can lead to incorrect explanations even when the model was fitted correctly.

The examples use a continuous response and an identity-link linear model. Assume the conditional mean is specified correctly and the errors have conditional mean zero. Where a distribution is needed, assume independent errors with distribution \(N(0,\sigma^2)\), with \(\sigma^2\) constant. These assumptions support the stated model interpretation; a coefficient by itself does not establish a causal effect.

Definition: With treatment (reference-level) coding, a factor with \(K\) levels is represented using \(K-1\) indicator variables. One level is the reference level; the other coefficients compare their levels with that reference, conditional on the other predictors in the model. If the model contains an interaction, a main-effect coefficient is a comparison at the reference value of the interacting predictor, not necessarily a comparison that holds at every value.

Reference-Coded Coefficients Are Conditional Contrasts

For a two-level factor \(G\), let \(G=0\) denote the reference level and \(G=1\) the other level. Consider a linear mean model with a numeric predictor \(x\):

$$ E[Y\mid x,G]=\beta_0+\beta_GG+\beta_xx. $$

The fitted intercept \(\hat{\beta}_0\) is the predicted response for the reference level at \(x=0\). The fitted factor coefficient \(\hat{\beta}_G\) is the predicted difference between \(G=1\) and \(G=0\) at the same \(x\). If \(x\) is included in the model, the factor coefficient is not generally either group's overall average. Those averages depend on the predictor values at which each group is observed.

With several factor levels, each treatment-coded coefficient has the same kind of meaning: it is a model-based contrast with the reference level, holding other included predictors fixed. The intercept corresponds to the reference level and to zero values for the other numeric predictors. If zero is outside the relevant range, the intercept may have little practical meaning; centering a predictor can make the comparison point more useful.

Worked Example: A Factor Coefficient Is Not a Group Average

A hypothetical insurer models an annual service-cost index \(Y\), measured in hundreds of dollars, using distribution channel and policy tenure \(x\), measured in years. Let Direct be the reference channel and Broker be coded \(G=1\). The fitted model is

$$ E[Y\mid x,G]=12+3G-0.4x. $$

Assume the errors are independent \(N(0,\sigma^2)\) with conditional mean zero and constant variance. In the observed portfolio, the mean tenure is 4 years for Direct policies and 7 years for Broker policies. Find the model-predicted response for each channel at its observed mean tenure, and interpret the coefficient 3.

Method. Substitute each channel indicator and its tenure into the fitted conditional-mean equation. The reference coding is Direct \(G=0\) and Broker \(G=1\).

For Direct at \(x=4\), the prediction is \(12+3(0)-0.4(4)=12-1.6=10.4\), or $1,040. For Broker at \(x=7\), the prediction is \(12+3(1)-0.4(7)=12+3-2.8=12.2\), or $1,220.

The coefficient 3 is the predicted Broker-minus-Direct difference at the same tenure. For example, at \(x=5\), the Direct prediction is \(12-2=10\), while the Broker prediction is \(12+3-2=13\); the difference is \(13-10=3\). It is not the difference between the two predictions at their different observed mean tenures: that difference is \(12.2-10.4=1.8\).

Common mistake and correction. Calling 3 the Broker group mean confuses a conditional contrast with a level of the response. The model's prediction for a Broker policy at \(x=7\) is 12.2, not 3. The calculation is checked by substituting \(G=1,x=7\) back into the equation.

Interactions Change the Meaning of Main Effects

When a factor and a numeric predictor interact, the factor difference can vary with the numeric predictor. A model with a two-level factor and one numeric predictor is

$$ E[Y\mid x,G]=\beta_0+\beta_xx+\beta_GG+\beta_{xG}xG. $$

For the reference group \(G=0\), the intercept is \(\beta_0\) and the slope in \(x\) is \(\beta_x\). For \(G=1\), the intercept is \(\beta_0+\beta_G\), and the slope is \(\beta_x+\beta_{xG}\). Thus \(\beta_G\) compares the groups at \(x=0\), while \(\beta_{xG}\) is the difference between their slopes. The group difference at a general value \(x\) is \(\beta_G+\beta_{xG}x\).

Justification: Subtract the reference-group conditional mean from the \(G=1\) conditional mean. At \(G=0\), \(E[Y\mid x,0]=\beta_0+\beta_xx\). At \(G=1\), \(E[Y\mid x,1]=\beta_0+\beta_xx+\beta_G+\beta_{xG}x\). Therefore, $$ E[Y\mid x,1]-E[Y\mid x,0]=\beta_G+\beta_{xG}x. $$ The interaction term makes the difference depend on \(x\); when \(\beta_{xG}=0\), the model's difference is constant in \(x\).

Worked Example: A Main Effect in an Interaction Model

A hypothetical claim model predicts a severity index \(Y\) from a continuous exposure measure \(x\) and an indicator for enhanced coverage, \(G=1\). Standard coverage is the reference level. The fitted model is

$$ E[Y\mid x,G]=20+2x-5G+1.5xG. $$

Assume independent \(N(0,\sigma^2)\) errors with conditional mean zero and constant variance. Calculate both coverage groups' slopes, their predictions at \(x=4\), and the enhanced-minus-standard difference at \(x=4\).

Method. Set \(G=0\) to obtain the standard-coverage line: \(20+2x\). Its slope is 2. Set \(G=1\) to obtain the enhanced-coverage line: \(20+2x-5+1.5x=15+3.5x\). Its slope is 3.5.

At \(x=4\), the standard prediction is \(20+2(4)=20+8=28\). The enhanced prediction is \(15+3.5(4)=15+14=29\). The difference is \(29-28=1\). Equivalently, the difference formula gives \(-5+1.5(4)=-5+6=1\), which checks the two predictions.

The coefficient \(-5\) is the enhanced-minus-standard difference at \(x=0\), not at every exposure value. At \(x=4\), the interaction adds \(1.5(4)=6\), changing that difference to 1.

Common mistake and correction. Interpreting \(-5\) as a universal five-unit reduction ignores the interaction. The correct comparison at \(x=4\) includes both terms involving \(G\): \(-5+1.5(4)=1\).

Numeric Category Codes Can Impose an Unintended Trend

A variable recorded as 1, 2, and 3 is not necessarily quantitative. If the numbers identify categories, fitting them as a numeric predictor tells the model to use the numerical distances between the codes. In a simple linear model, that imposes a constant change in predicted response for each one-unit increase in code. A factor model instead permits separate conditional differences for the levels, subject to the rest of the model specification.

In R, a numeric column used directly in a formula is ordinarily treated as numeric. For nominal categories, convert it to a factor and set the reference level deliberately, for example with relevel(factor(tier), ref = "1"). Check the stored levels and the fitted model's contrasts; the intended reference should not be left to an assumption about how labels are ordered.

Worked Example: Numeric Codes Versus Factor Levels

A hypothetical pricing team records three non-ordered service tiers as codes 1, 2, and 3. In a training set with the same number of observations in each tier, the fitted mean response is $4,800 for Tier 1, $6,200 for Tier 2, and $6,400 for Tier 3. Compare a factor model with a numeric-code linear model, expressing responses in hundreds of dollars. Assume independent \(N(0,\sigma^2)\) errors with conditional mean zero and constant variance.

Method 1: treat tier as a factor. Use Tier 1 as the reference. The fitted intercept is 48. The Tier 2 coefficient is \(62-48=14\), and the Tier 3 coefficient is \(64-48=16\). The model's fitted tier means are therefore \(48\), \(48+14=62\), and \(48+16=64\). This coding makes no equal-increment assumption between the three tiers.

Method 2: treat the code as numeric. With equal numbers of observations at each code, the three points used to fit the one-predictor line are \((1,48),(2,62),(3,64)\). Their means are \(\bar{x}=2\) and \(\bar{Y}=(48+62+64)/3=58\). The least-squares slope is

$$ \hat{\beta}_1=\frac{(-1)(48-58)+(0)(62-58)+(1)(64-58)}{(-1)^2+0^2+1^2} =\frac{10+0+6}{2}=8. $$

The intercept is \(\hat{\beta}_0=\bar{Y}-\hat{\beta}_1\bar{x}=58-8(2)=42\). The numeric-code model therefore predicts \(42+8(1)=50\), \(42+8(2)=58\), and \(42+8(3)=66\). These are $5,000, $5,800, and $6,600. They differ from the observed tier means because the numeric model fits a straight line with a constant increment of 8 hundreds of dollars per code step.

Common mistake and correction. Treating the codes as numeric because they look like numbers silently imposes a trend and equally spaced effects. If the tier labels are nominal, use a factor model; use numeric coding only when a one-unit increase has a substantive meaning and the imposed trend is defensible.

A Practical Interpretation Check

Before explaining any factor or interaction coefficient, write down the model and answer these questions:

1
Identify the coding.
Name the reference level and determine whether category labels are being treated as a factor or as numeric values.
2
Substitute the reference values.
For an interaction, set the relevant predictor to zero or to its stated centering value before interpreting a main effect.
3
Calculate the requested comparison.
For a group prediction, include every coefficient whose term applies to that group. For a group difference, subtract the two predicted means.
4
Check the interpretation against predictions.
Evaluate both groups at the same predictor values. Their prediction difference must agree with the contrast obtained from the model equation.

A coefficient describes the fitted model, not necessarily an unadjusted comparison in the data. Interactions further make some comparisons depend on the predictor value. State the reference category, specify the value at which a comparison applies, and distinguish model predictions from observed group averages. This careful interpretation is aligned with the SOA Exam PA (Predictive Analytics) syllabus.

Check Your Understanding

For each problem, write the model-based comparison before interpreting the coefficient.

  1. A model uses \(E[Y\mid x,G]=18+4G-0.5x\), with \(G=0\) as the reference. The mean \(x\) is 2 in the reference group and 6 in the \(G=1\) group. Find each group's prediction at its mean \(x\), and state what the coefficient 4 represents. (Answer: Reference prediction 17; \(G=1\) prediction 19; coefficient 4 is the difference at the same \(x\), not the difference between those two group-specific predictions.)
  2. A fitted interaction model is \(E[Y\mid x,G]=30+2x-3G+0.75xG\), with \(G=0\) as reference. Find the two slopes and both predictions at \(x=6\). (Answer: Slopes 2 and 2.75; predictions 42 and 43.5, respectively.)
  3. A factor model has fitted means 25, 31, and 40 for levels A, B, and C, with A as reference. State the B-versus-A and C-versus-A contrasts. What does fitting the codes 0, 1, and 2 as numeric additionally assume? (Answer: Contrasts 6 and 15; the numeric model imposes a linear trend with a constant change per one-unit code increase.)
  4. Let \(u=x-5\), and fit \(E[Y\mid u,G]=10+3u+2G-G u\), with \(G=0\) as reference. Find the group difference at \(x=8\). (Answer: \(u=3\), so the difference is \(2-3=-1\).)
  5. For nominal tiers A, B, and C, a model in R is fitted as lm(y ~ code), where code contains the values 1, 2, and 3. What change makes the model estimate separate level effects, and why? (Answer: Fit the tier variable as a factor, such as lm(y ~ factor(code)); numeric code otherwise imposes a one-slope linear trend.)
Clinical Biostats