Why Coding Changes Need Not Change a Rating Model
Categorical predictors can be represented by different sets of columns. Reference coding makes coefficients easy to interpret relative to a selected level; effect coding expresses deviations under a different constraint. These choices change the coefficient values and their interpretations. They do not necessarily change the fitted rating structure.
The key question is whether the two design matrices describe the same set of possible linear predictors. If they do, an unpenalized GLM fitted to the same data, with the same response, link, offset, and other model terms, has the same fitted linear predictors and fitted means. This tutorial focuses on that equivalence and on calculating relativities consistently across codings.
For a GLM with linear predictor \(\eta=X\beta+o\), \(o\) denotes any fixed offset. With a log link, the fitted mean is \(\mu=\exp(\eta)\). An equivalent coding can be written \(Z=XA\), where \(A\) is invertible. The coefficient vector in the new coding must then be \(\gamma=A^{-1}\beta\), since \(Z\gamma=XA A^{-1}\beta=X\beta\). The offset is not recoded; it is added to either representation.
Why the Fitted Values Are Invariant
The reparameterization argument gives a direct justification. Every coefficient vector in one coding corresponds to exactly one vector in the other coding, and the resulting linear predictors are equal. Therefore, each candidate fit available to one model is also available to the other. Since the response distribution, likelihood, and offset are unchanged, maximizing the likelihood selects the same fitted linear predictor when the maximum is finite and the fitted predictor is identified.
For a log-link model, equality of \(\eta\) implies equality of \(\mu=\exp(\eta)\). It also implies equality of a segment relativity calculated as a ratio of fitted means at two specified predictor profiles, provided the profiles use the same offset or are compared on the same exposure basis. The coefficients themselves need not match: they are coordinates for the same fitted structure in different bases.
This result requires equivalent model spaces and an unchanged fitting problem. It does not say that any two codings produce the same fit. If a term is omitted, the matrices have different column spaces, or a coding-dependent constraint or penalty is imposed, the available fits can change. In particular, applying the same numerical ridge penalty to differently scaled columns generally does not preserve the penalized fit.
Worked Examples With Factor Relativities
Worked Example: Three Levels Under Reference and Effect Coding
A hypothetical territory factor has three levels, A, B, and C. A fitted log-link model gives rates of $80, $160, and $40 per exposure unit, respectively. Use A as the reference level first, then express the same fitted rates using effect coding with columns \((1,0)\) for A, \((0,1)\) for B, and \((-1,-1)\) for C. Calculate the rate relativities of B and C to A.
Method. Work with log rates, since the link is logarithmic. Under reference coding, the intercept is the log rate at A: \(\beta_0=\ln(80)\). The B coefficient is the log ratio of B to A, and the C coefficient is the log ratio of C to A: \(\beta_B=\ln(160/80)=\ln(2)\) and \(\beta_C=\ln(40/80)=\ln(0.5)=-\ln(2)\).
Thus the reference-coded linear predictors are \(\ln(80)\) for A, \(\ln(80)+\ln(2)=\ln(160)\) for B, and \(\ln(80)-\ln(2)=\ln(40)\) for C. Exponentiating returns the given rates: $80, $160, and $40.
For effect coding, let the intercept be \(\alpha\), with level effects \(\delta_A,\delta_B,\delta_C\). The specified columns impose \(\delta_C=-\delta_A-\delta_B\), so the three level predictors are \(\alpha+\delta_A\), \(\alpha+\delta_B\), and \(\alpha-\delta_A-\delta_B\). Set these equal to the three log rates. Their sum gives \(3\alpha=\ln(80)+\ln(160)+\ln(40)=3\ln(80)\), so \(\alpha=\ln(80)\). Then \(\delta_A=0\), \(\delta_B=\ln(2)\), and \(\delta_C=-\ln(2)\).
The effect-coded predictors are therefore \(\ln(80)\), \(\ln(80)+\ln(2)\), and \(\ln(80)-\ln(2)\). They reproduce $80, $160, and $40 exactly. The relativities are \(160/80=2.000\) for B to A and \(40/80=0.500\) for C to A.
Check and common mistake. Both codings give the same three fitted rates, so the ratios agree. A common mistake is to treat an effect-coded coefficient as a direct level-to-reference log ratio in every coding. Here \(\delta_B=\ln(2)\) happens to equal B's log ratio to A because \(\delta_A=0\); that coincidence is not a general interpretation rule. Calculate the desired fitted-rate ratio from the level predictors.
Worked Example: A Two-Factor Interaction in Two Codings
A hypothetical rating table has fitted rates \(m_{AX}=100\), \(m_{AY}=200\), \(m_{BX}=150\), and \(m_{BY}=600\). First write the reference-coded log-link model using A and X as reference levels. Then use effect-coded indicators \(z_A=-1,+1\) for A,B and \(z_Y=-1,+1\) for X,Y, with predictor \(\eta=\alpha+a z_A+b z_Y+c z_Az_Y\). Verify all four rates and calculate the B-to-A relativity within each level of the second factor.
Reference coding. The intercept is \(\ln(100)\). The B main effect is \(\ln(150/100)=\ln(1.5)\), and the Y main effect is \(\ln(200/100)=\ln(2)\). The interaction is the extra log factor needed for cell BY: \(600/[100(1.5)(2)]=2\). Thus the interaction coefficient is \(\ln(2)\).
The four reference-coded predictors are \(\ln(100)\), \(\ln(100)+\ln(2)\), \(\ln(100)+\ln(1.5)\), and \(\ln(100)+\ln(1.5)+\ln(2)+\ln(2)\). Exponentiating gives $100, $200, $150, and $600, respectively.
Effect coding. With the stated signs, the four predictors are \(\alpha-a-b+c\), \(\alpha-a+b-c\), \(\alpha+a-b-c\), and \(\alpha+a+b+c\), in the order AX, AY, BX, BY. Adding the four log rates cancels each effect coefficient, so \(\alpha=\frac14\ln(100\cdot200\cdot150\cdot600)=\ln(205.9767\ldots)\). The other coefficients follow by signed sums: \(a=\frac14\ln[(150\cdot600)/(100\cdot200)]=\frac14\ln(4.5)\), \(b=\frac14\ln[(200\cdot600)/(100\cdot150)]=\frac14\ln(8)\), and \(c=\frac14\ln[(100\cdot600)/(200\cdot150)]=\frac14\ln(2)\).
Numerically, \(a\approx0.376019\), \(b\approx0.519860\), and \(c\approx0.173287\). Substitution gives \(\exp(\alpha-a-b+c)=100\), \(\exp(\alpha-a+b-c)=200\), \(\exp(\alpha+a-b-c)=150\), and \(\exp(\alpha+a+b+c)=600\); equivalently, these identities follow exactly from the signed-sum formulas before rounding.
Within X, the B-to-A relativity is \(150/100=1.500\). Within Y, it is \(600/200=3.000\). The change in relativity across the second factor is the interaction: \(3/1.5=2\). This is the same interaction factor as the reference-coded coefficient \(\exp(\ln 2)=2\).
Check and common mistake. Each set of coded coefficients reconstructs the same cell log rates. Do not interpret the effect-coded coefficient \(a\) as the B-to-A log relativity within either level; that relativity depends on both \(a\) and \(c\). The coefficient \(c\) describes the interaction on the log scale, while the fitted cell ratios give the requested segment relativities.
Offsets and a Change of Basis
An exposure offset is part of the linear predictor but not part of the factor coding. For a count response with exposure \(e\), a log-link rate model can be written \(\eta=\ln(e)+\) rating terms, so \(\mu=e\exp(\text{rating terms})\). The ratio of fitted counts at different exposures includes the exposure ratio; the rate relativity compares the rating terms and does not.
Worked Example: Binary Factor Coding With an Exposure Offset
A hypothetical claim-count model uses exposure \(e\) and a binary vehicle-use factor. The reference level has fitted frequency \(0.04\) claims per exposure unit; the other level has fitted frequency \(0.06\). The reference-coded model is \(\eta=\ln(e)+\beta_0+\beta_1x\), where \(x=0\) for the reference and \(x=1\) for the other level. Re-express it using \(z=2x-1\), so \(z=-1\) or \(+1\). Calculate the coefficients, predictions for exposures 200 and 500, and the frequency relativity.
For reference coding, \(\beta_0=\ln(0.04)\) and \(\beta_1=\ln(0.06/0.04)=\ln(1.5)\). Since \(x=(z+1)/2\), the rating terms become \(\ln(0.04)+\ln(1.5)(z+1)/2\). Therefore \(\gamma_0=\ln(0.04)+\frac12\ln(1.5)=\ln(\sqrt{0.04\cdot0.06})=\ln(0.0489898\ldots)\) and \(\gamma_1=\frac12\ln(1.5)\approx0.202733\).
At the reference level, \(z=-1\), so the rate is \(\exp(\gamma_0-\gamma_1)=0.04\). With exposure 200, the fitted expected count is \(200(0.04)=8\). At the other level, \(z=+1\), so the rate is \(\exp(\gamma_0+\gamma_1)=0.06\). With exposure 500, the fitted expected count is \(500(0.06)=30\).
The frequency relativity is \(0.06/0.04=1.500\), independent of exposure. The ratio of these particular expected counts is \(30/8=3.75\), which is not the factor relativity: it also includes the exposure ratio \(500/200=2.5\), and \(2.5(1.5)=3.75\).
Check and common mistake. The alternative coding gives the same rates and expected counts because \(z=2x-1\) is an invertible recoding of the binary indicator. A common error is to call \(30/8\) the segment relativity. Divide out the exposure difference, or compare rates at a common exposure, to obtain the factor relativity of 1.500.
Practical Interpretation and Limits
A coefficient table is coding-dependent; fitted predictions are not, when the model spaces are equivalent. This distinction matters when reviewing model output, comparing implementations, or translating a model into rating factors. A reference coefficient is often a log ratio to the reference level when the model structure permits that interpretation. An effect-coded coefficient generally represents a deviation under its coding constraint, not automatically a ratio to a particular category.
A reliable comparison works from fitted linear predictors. For a log-link model, take the difference between the two relevant predictors and exponentiate it:
If both profiles have the same offset, it cancels in the difference. If exposures differ, distinguish the rate ratio from the expected-count ratio. With interactions, specify the other factor levels before calculating a segment relativity; the ratio can vary across those levels.
The equivalence result also provides a useful diagnostic. If two genuinely equivalent, unpenalized full-rank codings fitted to the same data produce materially different predictions, check whether the offset, included terms, weights, observations, or fitting constraints differ. Small numerical differences can arise from optimization tolerances, but a substantial difference is not explained merely by changing a full-rank basis.
Check Your Understanding
For each problem, compare fitted predictors or rates rather than assuming that coefficients have the same meaning across codings.
- A reference-coded factor has rate 90 at level R and 117 at level S. With coding \(z=-1\) for R and \(z=+1\) for S, find the intercept and slope in \(\eta=\gamma_0+\gamma_1z\), and give the S-to-R relativity. (Answer: \(\gamma_0=\ln(\sqrt{10530})\approx\ln(102.615)\), \(\gamma_1=\tfrac12\ln(1.3)\approx0.1312\), relativity \(1.300\).)
- For three levels with fitted rates 64, 128, and 32, use the effect-coded columns \((1,0),(0,1),(-1,-1)\). Give the intercept and the three level effects, then state the second-to-first and third-to-first relativities. (Answer: intercept \(\ln(64)\); effects \(0,\ln(2),-\ln(2)\); relativities \(2.000\) and \(0.500\).)
- A two-level factor has reference rate 0.08 and other-level rate 0.10. Under \(z=-1,+1\), calculate the effect-coded intercept and slope, and verify the rate ratio. (Answer: \(\gamma_0=\ln(\sqrt{0.008})\), \(\gamma_1=\tfrac12\ln(1.25)\approx0.1116\); exponentiating the difference \(2\gamma_1\) gives relativity \(1.250\).)
- A log-link count model predicts rates 0.03 and 0.045 for two segments. Their exposures are 400 and 800. Find their expected counts, the expected-count ratio, and the rate relativity. (Answer: expected counts 12 and 36; count ratio \(3.000\); rate relativity \(0.045/0.03=1.500\), with the remaining factor of 2 due to exposure.)
- Two full-rank design matrices are related by an invertible transformation, but one model also has a ridge penalty applied directly to its displayed coefficients. Can equality of fitted values be concluded solely from the coding equivalence? (Answer: No. The penalty can change under a basis transformation unless it is transformed consistently; unpenalized coding equivalence alone does not establish equal penalized fits.)