Tutorials › Exam PA - Predictive Analytics › Additive Effects of Multiple Categorical Predictors

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

Additive Effects of Multiple Categorical Predictors

Build and interpret a model with two categorical predictors, calculate fitted values, and recognize when additivity may be an unsuitable assumption.

Intermediate 10 min read

What You'll Learn

  • Write an additive model for two categorical predictors using reference-level coefficients.
  • Calculate fitted values from main effects under treatment coding.
  • Derive fitted cell means in a balanced, complete factorial design.
  • Explain why an additive model assumes a factor's effect is constant across the levels of the other factor.
  • Identify situations where marginal-mean shortcuts do not apply.
  • Check residual patterns for evidence that the additive structure may be inadequate.

Why Model Two Categorical Predictors Additively?

A predictive model may use several categorical variables at once. For example, a hypothetical insurer might want to estimate a claim-related outcome using both a payment plan and a territory. Including both factors allows the model to represent their separate contributions. An additive model makes a further assumption: the contribution associated with either factor does not depend on the level of the other factor.

This assumption can make a model easier to interpret and may be reasonable when the available data are limited. It is not guaranteed to be true merely because the model can be fitted. In particular, if the difference between two payment plans changes substantially across territories, an additive model cannot represent that pattern exactly.

Definition: An additive linear model with two categorical predictors represents the conditional mean response as a baseline plus a contribution from the first factor and a contribution from the second factor. It contains no term for a joint effect of the two factors. Consequently, the modeled difference between any two levels of one factor is the same at every level of the other factor.

Writing and Interpreting the Model

Let \(A\) have levels \(A_1,\ldots,A_J\), and let \(B\) have levels \(B_1,\ldots,B_K\). Under treatment coding, choose \(A_1\) and \(B_1\) as reference levels. For a quantitative response \(Y\), an additive linear model can be written as

$$ E[Y\mid A=A_j,B=B_k] =\beta_0+\alpha_j+\gamma_k, \qquad \alpha_1=0,\quad \gamma_1=0. $$

Here \(\beta_0\) is the modeled mean for the reference combination \(A_1,B_1\). The coefficient \(\alpha_j\) is the modeled difference between level \(A_j\) and \(A_1\), holding the level of \(B\) fixed. Similarly, \(\gamma_k\) is the modeled difference between \(B_k\) and \(B_1\), holding the level of \(A\) fixed. The restrictions \(\alpha_1=0\) and \(\gamma_1=0\) make the reference levels the baseline; they are not additional estimated effects.

For example, if \(A\) is payment plan and \(B\) is territory, an additive model can assign a difference to moving from one payment plan to another and a separate difference to moving from one territory to another. It does not allow the payment-plan difference to vary by territory. In R, the additive formula is written as response ~ A + B; the plus sign includes both factors as predictors, without their interaction.

This description concerns the model for the conditional mean. A usual linear-model analysis also assumes errors have mean zero and are independent; constant error variance is commonly assumed for conventional standard errors. Normal errors are an additional assumption used for exact small-sample inference, not a requirement for calculating the least-squares fitted values. The additive mean structure itself is the key assumption in this tutorial.

Fitted Values in a Balanced Complete Design

A useful calculation applies when every combination of factor levels is observed and the design is balanced: each cell has the same number of observations. In that setting, the least-squares fitted cell mean for \(A_j,B_k\) is the row mean for \(A_j\), plus the column mean for \(B_k\), minus the grand mean. The formula is a shortcut for this specific design, not a general rule for every data set.

$$ \widehat{Y}_{jk} =\overline{Y}_{j\cdot}+\overline{Y}_{\cdot k}-\overline{Y}_{\cdot\cdot}. $$

The row mean \(\overline{Y}_{j\cdot}\) averages across the levels of \(B\), and the column mean \(\overline{Y}_{\cdot k}\) averages across the levels of \(A\). The grand mean \(\overline{Y}_{\cdot\cdot}\) is the average across all observations. Subtracting the grand mean prevents it from being counted twice.

Why the balanced-design formula holds: In a balanced design, each factor level occurs equally often with every level of the other factor. Therefore the least-squares row and column effects are the row and column means measured relative to the grand mean. Adding the grand mean and these two centered effects gives \(\overline{Y}_{\cdot\cdot}+(\overline{Y}_{j\cdot}-\overline{Y}_{\cdot\cdot})+(\overline{Y}_{\cdot k}-\overline{Y}_{\cdot\cdot})=\overline{Y}_{j\cdot}+\overline{Y}_{\cdot k}-\overline{Y}_{\cdot\cdot}\). Equivalently, the resulting fitted values have residuals whose sums are zero within every row and every column, the least-squares normal-equation conditions for this balanced additive model.

Worked Example: Correcting for the Double-Counted Grand Mean

In a hypothetical, balanced, complete two-by-two study, the observed cell means are P-M: 8, P-N: 12, Q-M: 14, and Q-N: 16. Find the grand mean and the additive fitted mean for Q-N. Then check whether the additive fitted values preserve the grand total of the four cell means.

Method. Use the balanced-design formula. Because the design is balanced, each of the four cells receives equal weight in the grand mean.

Step 1: Calculate the grand mean. The sum of the four cell means is \(8+12+14+16=50\), so the grand mean is \(50/4=12.5\).

Step 2: Calculate the Q row mean. This is \((14+16)/2=30/2=15\).

Step 3: Calculate the N column mean. This is \((12+16)/2=28/2=14\).

Step 4: Calculate the additive fitted mean for Q-N. The Q row mean and N column mean both include the grand mean, so subtract it once: \(15+14-12.5=16.5\).

Step 5: Check the fit. The other fitted cell means are P-M: \(10+11-12.5=8.5\), P-N: \(10+14-12.5=11.5\), and Q-M: \(15+11-12.5=13.5\). Their total with Q-N is \(8.5+11.5+13.5+16.5=50\), the original total.

The additive fit for Q-N is 16.5, not the observed cell mean of 16. The residuals, defined as observed minus fitted, are \(-0.5, 0.5, 0.5, -0.5\) in P-M, P-N, Q-M, Q-N order. They sum to zero in each row and column, as required by the balanced least-squares fit. Common mistake: adding the Q row mean and N column mean without subtracting the grand mean gives \(15+14=29\), which double-counts the overall level and is not a fitted cell mean.

Reading the Constant-Effect Assumption

The absence of an interaction has a direct interpretation. For any fixed level of \(B\), the modeled difference between two levels of \(A\) is

$$ E[Y\mid A=A_j,B=B_k]-E[Y\mid A=A_1,B=B_k]=\alpha_j. $$

The right-hand side does not depend on \(k\). Thus the model assigns the same difference to \(A_j\) versus \(A_1\) whether the other factor is at its reference level or any other level. The equivalent statement holds for differences between levels of \(B\).

This is a restriction on the modeled means, not a statement that observed sample means must display identical differences. Observed cell means include sampling variation and may depart from the additive pattern. Residuals can help reveal systematic departures: if the model repeatedly underpredicts some combinations and overpredicts others, the pattern may indicate that the constant-effect assumption is inadequate. A residual pattern is a reason to investigate model structure and data quality, not by itself proof of a particular alternative.

Worked Example: Predicting from Reference-Level Coefficients

Suppose a hypothetical insurer fits an additive linear model for a dollar-valued response. Annual payment and Central territory are the reference levels. The estimated intercept is 520, the coefficient for Installment payment is \(+48\), the coefficient for Coastal territory is \(-30\), and the coefficient for Inland territory is \(+22\). Calculate the fitted response for an Installment policy in Inland territory and compare it with the fitted response for an Annual policy in Inland territory.

Method. Under treatment coding, start with the intercept and add the coefficient for each nonreference level present in the case.

Step 1: Predict for Installment and Inland. Both levels differ from the references, so the fitted response is \(520+48+22=590\).

Step 2: Predict for Annual and Inland. Annual is the reference level for payment, so no payment coefficient is added. The fitted response is \(520+22=542\).

Step 3: Compare. The difference is \(590-542=48\), exactly the Installment coefficient. The additive model assigns this same \(48\)-unit payment-plan difference in Central and Coastal territories as well. Check: the Inland coefficient shifts both predictions by \(+22\) relative to their corresponding Central-territory predictions, while leaving their difference unchanged. The common mistake is to treat a factor coefficient as a full prediction; the coefficient is a difference from its reference level, not the fitted response by itself.

When the Marginal-Mean Shortcut Does Not Apply

The balanced-design formula is convenient, but its conditions matter. If cell sizes differ, row and column averages can give factor levels unequal effective weights. If some combinations are absent, the data may not contain enough information to estimate every comparison without additional assumptions. In either case, do not automatically calculate a fitted value as row mean plus column mean minus grand mean. Fit the specified additive model using the observed records, and use its estimated coefficients or model predictions.

The meaning of a coefficient still follows from the chosen coding scheme. Under treatment coding it is a difference from a reference level. With a different valid contrast coding, individual coefficients may instead represent other comparisons, while the fitted means for the same model remain unchanged. For a prediction, combine the intercept and all applicable factor contributions using the coding actually used to fit the model.

Worked Example: Applying Additivity to a Three-by-Two Table

A hypothetical study has a balanced, complete design. Its observed cell means for factor A's levels A1, A2, A3 and factor B's levels B1, B2 are: A1-B1: 4, A1-B2: 10; A2-B1: 7, A2-B2: 9; A3-B1: 13, A3-B2: 12. Use the additive model to calculate the fitted mean for A3-B2 and assess how the model treats the B2-versus-B1 difference.

Method. Calculate the A3 row mean, B2 column mean, and grand mean, then apply the balanced-design formula.

Step 1: Calculate the A3 row mean. \((13+12)/2=25/2=12.5\).

Step 2: Calculate the B2 column mean. \((10+9+12)/3=31/3=10.3333\ldots\).

Step 3: Calculate the grand mean. The total is \(4+10+7+9+13+12=55\), so the grand mean is \(55/6=9.1666\ldots\).

Step 4: Calculate the fitted mean. For A3-B2, the fitted mean is \(12.5+31/3-55/6=25/2+62/6-55/6=82/6=41/3\), or 13.667 to three decimal places.

Step 5: Compare the B-level differences. The observed B2-minus-B1 differences are \(10-4=6\) at A1, \(9-7=2\) at A2, and \(12-13=-1\) at A3. The additive model instead assigns one common difference: the B2 column mean minus the B1 column mean. The B1 column mean is \((4+7+13)/3=24/3=8\), so the modeled difference is \(31/3-8=7/3=2.333\ldots\) at each A level. The observed differences vary, so the additive fit will not reproduce every cell mean. Check: the fitted A3-B2 value, 13.667, is not the observed mean of 12; the model is imposing a common factor difference, not simply copying each cell mean.

Exam Traps and Practical Checks

  • Forgetting the reference level. A reference category contributes zero to the coded linear predictor. Do not add a coefficient for it.
  • Adding two marginal means without subtracting the grand mean. In the balanced complete design, the grand mean is included in both marginal means and must be removed once.
  • Using the balanced shortcut for unbalanced data. Unequal cell sizes or missing combinations can invalidate the simple marginal-mean calculation; use the fitted model.
  • Claiming the observed effects must be constant. Additivity constrains the model's fitted means. Sample cell means can differ because of residual variation, and systematic residual patterns deserve attention.
  • Interpreting a coefficient as a universal causal effect. A fitted coefficient is a model-based comparison under the specified coding and assumptions; it is not automatically a causal conclusion.

A useful check is to state the implication in words before using the model: “The difference between these two levels of factor A is assumed to be the same at every level of factor B.” If that is not a plausible working assumption for the problem, an additive model may be too restrictive. This treatment is aligned with the SOA Exam PA (Predictive Analytics) syllabus.

Check Your Understanding

For each problem, identify the relevant additive-model calculation or assumption before giving your answer.

  1. In a balanced, complete two-by-two design, the cell means are R-X: 6, R-Y: 10, S-X: 12, and S-Y: 20. Calculate the grand mean and the additive fitted mean for S-Y. (Answer: grand mean 12; fitted S-Y mean 19.)
  2. A treatment-coded model has reference levels Basic and North, an intercept of 300, a coefficient of \(+25\) for Plus, and a coefficient of \(-8\) for South. Calculate the fitted response for Plus-South. (Answer: 317.)
  3. In an additive model with factor A at levels L and H and factor B at levels U and V, the fitted means are L-U: 5, L-V: 8, H-U: 11, and H-V: 14. What difference does the model assign to H versus L at each B level? (Answer: \(+6\) at both U and V.)
  4. A balanced, complete two-by-three design has observed means R-X: 20, R-Y: 22, R-Z: 28, S-X: 30, S-Y: 32, and S-Z: 35. Calculate the additive fitted mean for S-Z. (Answer: 36.)
  5. A two-factor data set has unequal numbers of observations in its cells. A candidate calculates a fitted value by adding the relevant row and column means and subtracting the unweighted grand mean. What is the key problem with this method? (Answer: the balanced-design shortcut is not generally valid with unequal cell sizes; calculate predictions from the fitted additive model.)
Clinical Biostats