Why Reference Coding Matters
A rating factor such as territory or vehicle class is categorical: a policy belongs to one level, not to a numerical point on a scale. A generalized linear model still needs numerical predictors, so the levels must be represented in a design matrix. Reference coding does this by choosing one level as the reference and assigning an indicator variable to each of the other levels.
Under a log link, these indicators have a direct multiplicative interpretation. The intercept gives the fitted mean for the reference combination, and exponentiating a level's coefficient gives its relativity to that baseline, with other modeled predictors held fixed. This tutorial focuses on constructing those indicators and reading their coefficients correctly.
The Log-Link Model and the Baseline
Let \(\mu\) be the positive conditional mean being rated, such as expected claim cost per exposure. With one categorical factor and a log link, reference coding gives
where \(x_j\) is the indicator for non-reference level \(j\). The model assumes that the log of the conditional mean is linear in these indicators. For the examples below, fitted coefficients are treated as given, and the factor effects are additive unless otherwise stated. The response distribution and its variance structure are separate parts of a GLM; they do not change how these coefficients translate into fitted means.
If an observation is in the reference level, every \(x_j=0\), so its fitted mean is \(\exp(\beta_0)\). If it is in level \(j\), then \(x_j=1\) and all the other indicators for this factor are 0. Its fitted mean is \(\exp(\beta_0+\beta_j)\). Thus:
The coefficient \(\beta_j\) is a difference on the log-mean scale; it is not itself a percentage change or a dollar change. The corresponding multiplicative relativity is \(\exp(\beta_j)\). A coefficient of zero means relativity 1, while a positive or negative coefficient gives a relativity above or below 1, respectively.
The reference level is a coding choice, not a claim that it is average, safest, or otherwise special. Choosing a different reference changes the intercept and coefficient values, but it does not change the fitted mean for any rating cell when the model is merely recoded.
Constructing the Design Row
For a single factor with levels North, Central, and Coastal, suppose North is the reference. The design uses two indicators: one for Central and one for Coastal. Each observation receives exactly one row of zeros and ones.
| Territory | Central indicator | Coastal indicator |
|---|---|---|
| North (reference) | 0 | 0 |
| Central | 1 | 0 |
| Coastal | 0 | 1 |
With an intercept, an observation in North has predictor \(\beta_0\); one in Central has \(\beta_0+\beta_{\mathrm{Central}}\); and one in Coastal has \(\beta_0+\beta_{\mathrm{Coastal}}\). The all-zero row is how the model identifies the reference. It does not mean that the reference territory has zero expected cost.
For \(K\) levels, using an intercept and all \(K\) indicators would make the columns redundant: for every row, the sum of the \(K\) indicators is 1, which duplicates the intercept column. The resulting parameters are not separately identifiable. Reference coding avoids that redundancy by using only \(K-1\) indicators. This is why the omitted level must be understood as the baseline, not as a level with no effect.
Worked Example: Coding Territory and Calculating Its Relativity
A hypothetical insurer models expected claim cost per exposure using a log link and territory alone. North is the reference territory. The fitted intercept is \(\log(400)\), the Central coefficient is \(\log(1.15)\), and the Coastal coefficient is \(\log(0.80)\). Construct the rows for all territories, find the fitted mean for each, and compare Central with Coastal. Assume the fitted model has no additional predictors.
Method and model. Use two reference-coded indicators, \(x_C\) for Central and \(x_K\) for Coastal, in \(\log(\mu)=\beta_0+\beta_Cx_C+\beta_Kx_K\). The conditional mean is positive and modeled with a log link. The coefficients are the stated fitted values; no particular response variance assumption is needed for this calculation.
North. Its row is \((0,0)\), so \(\log(\mu_N)=\log(400)\), and \(\mu_N=400\).
Central. Its row is \((1,0)\), so \(\log(\mu_C)=\log(400)+\log(1.15)=\log(400\times1.15)\). Therefore \(\mu_C=400\times1.15=460\).
Coastal. Its row is \((0,1)\), so \(\log(\mu_K)=\log(400)+\log(0.80)=\log(400\times0.80)\). Therefore \(\mu_K=400\times0.80=320\).
Central relative to Coastal. Divide their fitted means: \(460/320=1.4375\). Equivalently, divide the relativities \(1.15/0.80=1.4375\). Thus Central's fitted mean is 1.4375 times Coastal's, or 43.75% higher. The calculation checks because both approaches give the same ratio.
Common mistake avoided: treating \(\log(1.15)\) as a 1.15% increase. It is the coefficient on the log scale; exponentiating it gives the actual relativity, 1.15.
More Than One Categorical Factor
If territory and vehicle class enter additively, each factor gets its own reference level and its own set of indicators. For example, with \(K\) territory levels and \(L\) vehicle-class levels, an intercept model uses \(K-1\) territory indicators and \(L-1\) class indicators. Under this no-interaction specification, the log-link mean is
Here \(x_j\) and \(z_m\) are the reference-coded indicators for the two factors. Exponentiating shows that their relativities multiply on the mean scale. This multiplicative combination follows from the additive log-mean specification; it is not a general guarantee that every real-world factor combination behaves that way.
Worked Example: Combining Territory and Vehicle-Class Indicators
For a hypothetical portfolio, a log-link model estimates expected claim cost per exposure. Territory T1 and vehicle class V1 are the respective references. The baseline fitted mean is $300. The estimated relativities are 1.10 for T2, 0.90 for T3, 1.40 for V2, and 1.20 for V3. The model includes these main effects only, with no interactions. Find the fitted mean for a T2/V3 policy and compare it with a T3/V2 policy.
Method and model. Use indicator columns \(x_{T2},x_{T3},z_{V2},z_{V3}\), with the given factors interpreted as exponentiated log-link coefficients. The baseline is the T1/V1 fitted mean of $300. Since the model is additive on the log scale, apply the territory and class relativities multiplicatively.
T2/V3 design row. In the stated column order its row is \((1,0,0,1)\). The fitted mean is \(300\times1.10\times1.20=300\times1.32=\$396\).
T3/V2 design row. Its row is \((0,1,1,0)\). The fitted mean is \(300\times0.90\times1.40=300\times1.26=\$378\).
Comparison. The ratio is \(396/378=1.32/1.26=22/21\), approximately 1.0476. Therefore the T2/V3 fitted mean is about 4.76% higher than the T3/V2 fitted mean. The dollar difference is \(\$396-\$378=\$18\).
Common mistake avoided: adding the two relativities to the baseline. The model adds coefficients on the log scale, which means the corresponding relativities multiply on the mean scale; \(300(1.10)(1.20)\), not \(300(1+0.10+0.20)\), is the specified calculation.
Changing the Reference Level
A reference can be changed as a re-expression of the same fitted model. The new intercept becomes the fitted log mean at the new reference level. Each other level's new coefficient is its log-mean difference from that new reference. The fitted means themselves remain the same, provided the model's terms are otherwise unchanged.
In the second expression, \(\beta_{j,\mathrm{old}}\) is the old-coded coefficient for level \(j\), and the new reference's old-coded coefficient is subtracted. For the old reference itself, its old-coded coefficient is understood to be zero. These formulas follow by taking the log-mean difference between each level and the new reference.
Worked Example: Re-Referencing Vehicle Class Without Changing Predictions
A hypothetical vehicle-class model uses Private as the reference. Its fitted mean is $250; Delivery has relativity 1.30 to Private, and Taxi has relativity 0.80 to Private. Recode the model with Delivery as the reference, then verify the fitted Taxi mean. The model has a log link and this is its only predictor.
Method and model. The original log-mean coefficients are \(\beta_0=\log(250)\), \(\beta_{\mathrm{Delivery}}=\log(1.30)\), and \(\beta_{\mathrm{Taxi}}=\log(0.80)\). Choose Delivery as the new reference and express each remaining level relative to it.
New intercept. The Delivery fitted mean is \(250\times1.30=\$325\). Therefore the new intercept is \(\log(325)=\log(250)+\log(1.30)\), and the new baseline mean is $325.
Private coefficient. Private relative to Delivery is \(250/325=1/1.30=10/13\). Its new coefficient is \(\log(10/13)\), approximately \(-0.2624\).
Taxi coefficient. Taxi relative to Delivery is \((250\times0.80)/325=200/325=8/13\). Its new coefficient is \(\log(8/13)\), approximately \(-0.4855\).
Verification. With the new coding, Taxi's fitted mean is \(325\times(8/13)=\$200\). Under the original coding it is \(250\times0.80=\$200\). The predictions agree, as they must when only the reference coding changes. Coefficients are rounded to four decimal places; the fitted means use the exact ratios.
Common mistake avoided: using the old Taxi relativity of 0.80 as the new Taxi coefficient's relativity. That value compares Taxi with Private. With Delivery as reference, the correct comparison is \(0.80/1.30=8/13\).
Common Coding and Interpretation Traps
Reference coding is straightforward once the reference is made explicit, but several errors can silently change the implied model or the comparison being reported.
- Including an indicator for every level plus an intercept. This creates a redundant design because the indicators sum to 1. Use \(K-1\) indicators for \(K\) levels when an intercept is present.
- Calling the reference mean zero. Its indicators are zero, but its fitted mean is \(\exp(\beta_0)\), which is positive.
- Reporting a coefficient as a relativity. Exponentiate a log-link coefficient to obtain the multiplicative factor. A coefficient \(\beta\) corresponds to relativity \(\exp(\beta)\).
- Comparing a level with the wrong baseline. A coefficient is relative to the reference used in that particular coding. To compare two non-reference levels, take the difference of their log coefficients and exponentiate, or divide their relativities.
- Assuming additive factor effects without checking the specification. The product of territory and class relativities follows from a model with additive terms on the log scale and no interaction between those factors. Do not apply that rule if the fitted model specifies a different structure.
For instance, suppose two non-reference levels have coefficients \(\beta_A\) and \(\beta_B\) against the same reference. Their level-to-level ratio is \(\exp(\beta_A-\beta_B)\), not \(\exp(\beta_A)\) alone. This is a useful check whenever the requested comparison is not against the reference level.
Check Your Understanding
For each problem, identify the reference coding before calculating. Assume the stated log-link model and coefficients apply.
- A hypothetical territory model has reference A with baseline mean $180. Territory B has coefficient \(\log(1.25)\), and C has coefficient \(\log(0.90)\). What is the fitted mean for B? (Answer: $225 per exposure.)
- A four-level vehicle-class factor uses L1 as reference. The baseline mean is $420, and L3 has coefficient \(\log(0.85)\). Give L3's indicator values in the order L2, L3, L4, and calculate its fitted mean. (Answer: \((0,1,0)\); $357 per exposure.)
- A factor has three levels and the model includes an intercept. A proposed design includes three level indicators, one for each level. Explain the coding problem and give the number of indicators required for reference coding. (Answer: The three indicators sum to the intercept column and cause redundancy; use two indicators.)
- A hypothetical additive log-link model has baseline mean $500 for reference territory R and reference vehicle class Standard. Territory X has relativity 1.20 and Sport class has relativity 1.40. Find the fitted mean for X/Sport and its ratio to the baseline. (Answer: $840 per exposure; ratio 1.68.)
- A class model has Private as reference with fitted mean $200; level A has relativity 1.50 and level B has relativity 0.75. If A becomes the reference, give the new baseline mean and the new relativities for Private and B. (Answer: New baseline $300; Private relativity \(2/3\); B relativity \(0.50\).)