Why Categorical Predictors Need Careful Coding
A Poisson regression can compare expected counts across groups, such as the number of service claims in different plan types or the number of incidents recorded under different operating conditions. The interpretation becomes less direct when a model includes several categorical predictors: a coefficient usually describes a comparison at a particular reference level, and an interaction means that one predictor’s multiplicative effect can vary across levels of another predictor.
This tutorial develops indicator-variable coding for categorical predictors and interactions in a Poisson model with a log link. The examples concern hypothetical counts observed over the same defined observation window and under comparable observation conditions. They calculate expected counts, not rates.
Indicator Coding in a Poisson Log-Link Model
Let \(Y\) be a count. Conditional on its predictors, assume \(Y\) has a Poisson distribution with mean \(\mu\), so \(E[Y\mid\text{predictors}]=\mu\) and \(\operatorname{Var}(Y\mid\text{predictors})=\mu\). Assume observations are conditionally independent and use the log link. For two binary predictors \(A\) and \(B\), the model with an interaction is
Here \(A=0\) and \(B=0\) identify the reference combination. The product \(AB\) equals 1 only when both predictors equal 1. Exponentiating the linear predictor gives the fitted mean:
Thus, terms add on the log-mean scale and multiply on the mean scale. In particular, \(\exp(\beta_A)\) is the mean ratio comparing \(A=1\) with \(A=0\) when \(B=0\). When \(B=1\), that comparison is \(\exp(\beta_A+\beta_{AB})\). The interaction coefficient is not, by itself, the count difference between the two groups.
How the Interaction Changes the Comparison
The four fitted means implied by the binary-predictor model make the coefficient meanings explicit. Setting \(A\) and \(B\) to their four possible combinations gives the table below.
| A | B | Fitted mean | Comparison when one predictor changes |
|---|---|---|---|
| 0 | 0 | \(\exp(\beta_0)\) | Reference combination |
| 1 | 0 | \(\exp(\beta_0+\beta_A)\) | At \(B=0\), the A mean ratio is \(\exp(\beta_A)\) |
| 0 | 1 | \(\exp(\beta_0+\beta_B)\) | At \(A=0\), the B mean ratio is \(\exp(\beta_B)\) |
| 1 | 1 | \(\exp(\beta_0+\beta_A+\beta_B+\beta_{AB})\) | At \(B=1\), the A mean ratio is \(\exp(\beta_A+\beta_{AB})\) |
A useful interpretation of \(\beta_{AB}\) follows by comparing the A mean ratio at \(B=1\) with the A mean ratio at \(B=0\). Their ratio is
This quantity is called a ratio of mean ratios. If \(\beta_{AB}=0\), the A mean ratio is the same at both levels of B, so the model has no interaction on the log-mean (multiplicative mean) scale. A zero interaction does not mean that the predictors have no effects; it means their multiplicative effects do not vary with each other.
Worked Examples
Worked Example: Two Binary Predictors and Four Expected Counts
A hypothetical service program records the number of qualifying events for each account during the same observation window. Let \(A=1\) indicate the enhanced plan and \(B=1\) indicate a monitored operating condition. Suppose the fitted Poisson model has the following coefficients:
Calculate the fitted expected count in each group, the enhanced-plan mean ratio when \(B=1\), and the interaction’s ratio-of-ratios interpretation.
Method. Substitute each indicator combination into the linear predictor and exponentiate. The reference group is \(A=0,B=0\).
Reference group, \(A=0,B=0\): The linear predictor is \(\eta_{00}=\beta_0=\log(10)\), so \(\mu_{00}=\exp(\log(10))=10\).
Enhanced plan only, \(A=1,B=0\): The linear predictor is \(\eta_{10}=\log(10)+\log(1.5)=\log(15)\). Therefore \(\mu_{10}=15\).
Monitored condition only, \(A=0,B=1\): The linear predictor is \(\eta_{01}=\log(10)+\log(0.8)=\log(8)\). Therefore \(\mu_{01}=8\).
Both indicators equal 1: The linear predictor is \(\eta_{11}=\log(10)+\log(1.5)+\log(0.8)+\log(1.25)\). Thus \(\mu_{11}=10(1.5)(0.8)(1.25)\). Compute \(1.5(0.8)=1.2\), then \(1.2(1.25)=1.5\), so \(\mu_{11}=10(1.5)=15\).
At \(B=1\), the enhanced-plan mean ratio is \(\mu_{11}/\mu_{01}=15/8=1.875\). The coefficient interpretation gives the same result: \(\exp(\beta_A+\beta_{AB})=1.5(1.25)=1.875\). At \(B=0\), the enhanced-plan mean ratio is \(15/10=1.5\). The ratio of those two plan mean ratios is \(1.875/1.5=1.25=\exp(\beta_{AB})\), as required.
Check. The model predicts means \(10,15,8,15\) in the order \(00,10,01,11\); substituting the coefficients reproduces each mean. A common mistake is to report \(\exp(\beta_A)=1.5\) as the plan ratio for both values of \(B\). That is only the ratio at \(B=0\); the interaction changes it to \(1.875\) at \(B=1\).
Worked Example: A Three-Level Category With a Binary Interaction
A hypothetical monitoring study classifies sites as Alpha, Beta, or Gamma and records a count during a common observation window. Let Alpha be the reference category, and let \(B=1\) indicate use of a revised procedure. Suppose the baseline expected count is 20. Relative to Alpha, the site-category multipliers are 1.2 for Beta and 0.75 for Gamma. At Alpha, the procedure multiplier is 1.1. The procedure multiplier is further multiplied by 1.5 at Beta and by 0.8 at Gamma.
Use indicators \(I_B\) and \(I_G\) for Beta and Gamma, respectively, and \(Z\) for the procedure. Alpha is represented by \(I_B=I_G=0\). The model is
Alpha, procedure not used: All indicators are 0, so \(\mu=20\).
Alpha, procedure used: Only \(Z=1\), so \(\mu=20(1.1)=22\).
Beta, procedure not used: \(I_B=1\) and \(Z=0\), so \(\mu=20(1.2)=24\).
Beta, procedure used: \(I_B=1\) and \(Z=1\), so include both the procedure main effect and the Beta interaction: \(\mu=20(1.2)(1.1)(1.5)\). First \(20(1.2)=24\), then \(24(1.1)=26.4\), and \(26.4(1.5)=39.6\).
Gamma, procedure not used: \(I_G=1\) and \(Z=0\), so \(\mu=20(0.75)=15\).
Gamma, procedure used: \(I_G=1\) and \(Z=1\), so \(\mu=20(0.75)(1.1)(0.8)\). Compute \(20(0.75)=15\), \(15(1.1)=16.5\), and \(16.5(0.8)=13.2\).
The procedure mean ratios are \(22/20=1.1\) at Alpha, \(39.6/24=1.65\) at Beta, and \(13.2/15=0.88\) at Gamma. They also follow directly from the coefficient multipliers: \(1.1\), \(1.1(1.5)=1.65\), and \(1.1(0.8)=0.88\). For example, the Beta interaction multiplier 1.5 modifies the procedure effect relative to Alpha; it does not say that the procedure raises Beta’s expected count by 1.5 counts.
Check. The six fitted means are \(20,22,24,39.6,15,13.2\) in the order listed. Each is the baseline mean multiplied by the category and procedure factors active in that group. The model’s expected counts need not be integers.
Worked Example: Recovering the Interaction From Group Means
For a hypothetical two-category study, a fitted model gives expected counts of 12 for the reference category with the baseline procedure, 18 for the other category with the baseline procedure, 10 for the reference category with the revised procedure, and 18 when both the other category and revised procedure apply. Find the revised-procedure multiplier in the reference category, the category multiplier under the baseline procedure, and the interaction multiplier.
Step 1: Find the reference-category procedure ratio. It is \(10/12=5/6\).
Step 2: Find the category ratio at the baseline procedure. It is \(18/12=1.5\).
Step 3: Find the interaction multiplier as a ratio of ratios. Under the revised procedure, the category ratio is \(18/10=1.8\). Therefore the ratio of category ratios is \(1.8/1.5=1.2\). Equivalently, \[ \frac{18/10}{18/12}=\frac{18(12)}{10(18)}=\frac{12}{10}=1.2. \] The interaction coefficient is \(\log(1.2)\).
Check. Reconstruct the joint mean: \(12(1.5)(5/6)(1.2)=18\). The product is \(18\), matching the stated mean. The interaction multiplier is relative to the two main effects; it is not the joint mean divided by the reference mean, which would be \(18/12=1.5\).
More Than Two Levels and Reference Categories
For a predictor with three levels, two indicators are needed. With Alpha as reference, the indicators for Beta and Gamma are both zero at Alpha, only the Beta indicator is one at Beta, and only the Gamma indicator is one at Gamma. Including an interaction with a binary predictor requires a corresponding interaction for each nonreference level. Each interaction coefficient then compares that level’s multiplicative effect with the effect at the reference level.
Changing the reference category changes the individual coefficient values and their interpretations, but it does not change the fitted mean for a given group when the same model is represented correctly. Therefore, interpret coefficients in the context of the stated coding. If the reference category is not provided, do not assume that a particular named group is the baseline.
For two categorical predictors with multiple levels, the same logic extends across combinations of levels: use indicators for nonreference levels and include interaction terms for the relevant pairs. The number of coefficients grows with the number of combinations, so a table of group-specific means or comparisons is often a safer interpretation aid than reading coefficients in isolation.
Derivation: Why an Interaction Is a Ratio of Ratios
The ratio-of-ratios interpretation follows directly from the fitted means. Under the stated model, the expected means for the four binary combinations are \(\mu_{00}=\exp(\beta_0)\), \(\mu_{10}=\exp(\beta_0+\beta_A)\), \(\mu_{01}=\exp(\beta_0+\beta_B)\), and \(\mu_{11}=\exp(\beta_0+\beta_A+\beta_B+\beta_{AB})\). The A mean ratio when \(B=0\) is \[ \frac{\mu_{10}}{\mu_{00}} =\frac{\exp(\beta_0+\beta_A)}{\exp(\beta_0)} =\exp(\beta_A). \] When \(B=1\), it is \[ \frac{\mu_{11}}{\mu_{01}} =\frac{\exp(\beta_0+\beta_A+\beta_B+\beta_{AB})} {\exp(\beta_0+\beta_B)} =\exp(\beta_A+\beta_{AB}). \] Dividing the second ratio by the first cancels the shared A effect: \[ \frac{\mu_{11}/\mu_{01}}{\mu_{10}/\mu_{00}} =\frac{\exp(\beta_A+\beta_{AB})}{\exp(\beta_A)} =\exp(\beta_{AB}). \] This proves that the exponentiated interaction coefficient measures how much the A mean ratio changes when B changes from 0 to 1.
Common Interpretation Traps
- Reading a log coefficient as a mean ratio. The coefficient \(\beta_A\) is on the log-mean scale. Its mean-ratio interpretation is \(\exp(\beta_A)\), conditional on the other interacting predictor being at its reference level.
- Using a main effect at every level. When an interaction is present, \(\exp(\beta_A)\) applies at \(B=0\), not automatically at \(B=1\). At \(B=1\), use \(\exp(\beta_A+\beta_{AB})\).
- Calling the interaction a direct count increase. \(\exp(\beta_{AB})\) is a ratio of mean ratios. It is not an additive change in the expected count.
- Omitting a main effect when using its interaction. In the usual hierarchical model, include the component main effects along with their interaction. The joint mean uses all applicable terms.
- Confusing an expected count with an observed count. A fitted mean such as 13.2 is a model-based expectation; an individual observed count remains an integer.
Check Your Understanding
For each problem, identify the relevant reference comparison before interpreting the fitted means.
- A binary-predictor Poisson model has baseline mean 16, an A multiplier of 1.25, a B multiplier of 0.8, and an interaction multiplier of 1.5. Find the expected mean when both indicators equal 1 and its ratio to the baseline mean. (Answer: mean \(=24\); ratio \(=1.5\).)
- A three-level category has reference mean 30, with category multipliers 0.6 for Beta and 1.4 for Gamma. A binary procedure has reference-category multiplier 1.2 and interaction multipliers 1.5 for Beta and 0.75 for Gamma. Find the procedure-used means for Beta and Gamma, then find their ratio, Gamma to Beta. (Answer: Beta \(=32.4\), Gamma \(=37.8\), Gamma-to-Beta ratio \(=7/6\approx1.1667\).)
- A binary-interaction model has \(\beta_0=\log(9)\), \(\beta_A=\log(2)\), \(\beta_B=\log(0.5)\), and \(\beta_{AB}=\log(1.3)\). Find the expected means for \(00,10,01,11\), in that order. (Answer: \(9,18,4.5,11.7\).)
- For a two-by-two set of fitted means, let \(\mu_{00}=12,\ \mu_{10}=18,\ \mu_{01}=10,\ \mu_{11}=18\). Find the A mean ratio at \(B=0\), the A mean ratio at \(B=1\), and the interaction multiplier. (Answer: \(1.5,\ 1.8,\ 1.2\).)
- In a binary-interaction model, \(\exp(\beta_A)=0.9\) and \(\exp(\beta_{AB})=1.4\). Find the A mean ratio at \(B=1\), and state what comparison \(\exp(\beta_A)\) represents. (Answer: \(1.26\); \(\exp(\beta_A)=0.9\) is the A mean ratio at \(B=0\).)