Tutorials › Generalized Linear Models › Changing Reference Levels Without Changing Fits

Factors Contrasts and Interactions · Tutorial 144 of 981

Changing Reference Levels Without Changing Fits

Learn to transform factor coefficients exactly when changing the reference level, while preserving the model’s linear predictors and fitted means.

Intermediate 9 min read

What You'll Learn

  • Express a main-effects factor model using a chosen reference level
  • Derive the intercept and contrast-coefficient transformation for a new reference
  • Verify invariance of linear predictors and fitted means
  • Transform coefficient estimates and their covariance matrix
  • Recognize when unchanged numerical coefficients would give incorrect fitted values

Why Changing the Reference Level Is a Reparameterization

A factor’s reference level determines how its coefficients are expressed: the intercept corresponds to the reference level, and each other level’s coefficient compares that level with the reference. Choosing a different reference changes those descriptions and the numerical coefficients. It need not change the model’s predictions. The essential distinction is between changing the coordinates used to describe a model and changing the model itself.

We derive the transformation for a single factor in a generalized linear model (GLM) with a common set of additional covariates. The factor enters through main effects only: this tutorial does not include factor interactions. The response distribution and link function remain fixed throughout.

Definition: Suppose a factor \(G\) has \(K\) levels, labelled \(1,\ldots,K\), and let \(z_i\) be a vector of covariates for observation \(i\). With level 1 as the reference, write the linear predictor as \(\eta_i=\beta_0+\sum_{j=2}^{K}\alpha_j I(G_i=j)+z_i^\mathsf{T}\gamma\), where \(I(G_i=j)\) is 1 when observation \(i\) is in level \(j\) and 0 otherwise. Set \(\alpha_1=0\) for convenience. The GLM mean is \(\mu_i=g^{-1}(\eta_i)\), where \(g\) is the link function.

In this parameterization, \(\beta_0\) is the predictor at level 1 when the covariates are zero. Each \(\alpha_j\) is the difference between the linear predictor at level \(j\) and the predictor at level 1, holding the covariates fixed. On a nonlinear link scale, this is a difference in linear predictors; it is not generally a difference in response means.

The Coefficient Transformation

Now choose level \(r\) as the reference, with \(r\ne 1\). The new intercept must give the same predictor as before at level \(r\), so it is the old intercept plus the old contrast for level \(r\). Each new factor coefficient must compare its level with \(r\). Because both the old and new parameters describe linear predictors, that comparison is a subtraction.

Theorem: For the model above, set \(\alpha_1=0\) and choose level \(r\) as the new reference. The equivalent parameters are \(\beta_0^{*}=\beta_0+\alpha_r,\quad \gamma^{*}=\gamma,\quad \alpha_r^{*}=0,\quad \alpha_j^{*}=\alpha_j-\alpha_r\ \text{for }j\ne r.\) In particular, \(\alpha_1^{*}=-\alpha_r\). With these parameters, every observation has the same linear predictor under either reference-level choice, and hence the same fitted mean.

Proof. Consider an observation in factor level \(j\). Under the original parameterization, its factor contribution together with the intercept is \(\beta_0+\alpha_j\), using \(\alpha_1=0\). Under the new parameterization it is \(\beta_0^{*}+\alpha_j^{*}\). Substitution gives \(\beta_0^{*}+\alpha_j^{*}=(\beta_0+\alpha_r)+(\alpha_j-\alpha_r)=\beta_0+\alpha_j\). This calculation also applies when \(j=r\), because then \(\alpha_r^{*}=0\), and when \(j=1\), because \(\alpha_1=0\). Since \(\gamma^{*}=\gamma\), the covariate contribution is unchanged as well. Thus the linear predictor agrees for every factor level and every covariate vector. Applying the same inverse link \(g^{-1}\) gives the same fitted mean \(\mu_i\). \(\square\)

This transformation is reversible. In the new parameterization, \(\beta_0=\beta_0^{*}+\alpha_1^{*}\), \(\alpha_r=-\alpha_1^{*}\), and \(\alpha_j=\alpha_j^{*}-\alpha_1^{*}\) for \(j\ne 1,r\). The covariate coefficients remain \(\gamma=\gamma^{*}\). The two parameterizations therefore describe the same set of linear predictors, just with different coefficient coordinates.

Worked Example: Changing the Reference in a Logistic Model

Suppose a logistic regression uses treatment \(A\) as the reference and has \(\eta=-1+0.8I(\text{treatment}=B)+0.3x\), where \(x\) is a centered covariate. The mean is the probability \(p=1/(1+\exp(-\eta))\). Find the equivalent parameterization with \(B\) as reference, then check both fitted probabilities at \(x=1\).

The old intercept is \(-1\), and the old coefficient for \(B\) is \(0.8\). Changing the reference to \(B\) gives the new intercept \(-1+0.8=-0.2\). The new coefficient for \(A\), relative to \(B\), is \(0-0.8=-0.8\). The covariate slope is unchanged. Thus \(\eta=-0.2-0.8I(\text{treatment}=A)+0.3x\).

For treatment \(A\) at \(x=1\), the old predictor is \(-1+0.3=-0.7\), and the new predictor is \(-0.2-0.8+0.3=-0.7\). The fitted probability is \(1/(1+\exp(0.7))\approx 0.3318\) in either form. For treatment \(B\), the old predictor is \(-1+0.8+0.3=0.1\), and the new predictor is \(-0.2+0.3=0.1\). The fitted probability is \(1/(1+\exp(-0.1))\approx 0.5250\) in either form.

The intercept and treatment coefficient have changed, but neither linear predictor nor fitted probability has changed.

Worked Example: Three Levels in a Poisson Model

Suppose a Poisson model with a log link has a factor with levels \(A,B,C\), and \(A\) is the reference. Let the fitted means be 2 for \(A\), 3 for \(B\), and 5 for \(C\). Find the coefficients with \(B\) as the reference and verify all three means.

With \(A\) as reference and no other covariates, the intercept is \(\log 2\). The factor coefficients are \(\alpha_B=\log(3/2)\) and \(\alpha_C=\log(5/2)\), because exponentiating the linear predictor gives the mean. With \(B\) as reference, the new intercept is \(\log 2+\log(3/2)=\log 3\). The coefficient for \(A\) is \(-\log(3/2)=\log(2/3)\), and the coefficient for \(C\) is \(\log(5/2)-\log(3/2)=\log(5/3)\).

The new predictor for \(A\) is \(\log 3+\log(2/3)=\log 2\), so its fitted mean is 2. For \(B\), the predictor is \(\log 3\), giving mean 3. For \(C\), it is \(\log 3+\log(5/3)=\log 5\), giving mean 5. The coefficients express comparisons on the log-mean scale, while the fitted means are identical.

What Happens to Estimates and Uncertainty?

The coefficient transformation applies to estimates as well as to parameter values. If an estimate under the old reference is \(\hat\beta_0,\hat\alpha_1,\ldots,\hat\alpha_K,\hat\gamma\), then the corresponding estimate under the new reference is obtained by applying the same formulas. This is a linear transformation of the coefficient vector, so its covariance matrix must also be transformed. In general, coefficient standard errors do not simply stay attached to the same coefficient label.

Result: Let \(\hat\theta^{*}=A\hat\theta\) be a linear transformation of an estimated coefficient vector, with covariance matrix \(\widehat{\operatorname{Var}}(\hat\theta)\). Then \(\widehat{\operatorname{Var}}(\hat\theta^{*})=A\,\widehat{\operatorname{Var}}(\hat\theta)\,A^\mathsf{T}\). This follows from the covariance identity \(\operatorname{Var}(AX)=A\operatorname{Var}(X)A^\mathsf{T}\), applied to \(X=\hat\theta\), provided the covariance matrix exists.

The identity follows directly from the definition of covariance. If \(m=E[X]\), then \(E[AX]=Am\), and \(\operatorname{Var}(AX)=E[(AX-Am)(AX-Am)^\mathsf{T}]=E[A(X-m)(X-m)^\mathsf{T}A^\mathsf{T}]=A\operatorname{Var}(X)A^\mathsf{T}\). The final equality uses that \(A\) is fixed, so it can be taken outside the expectation. \(\square\)

Worked Example: Transforming a Coefficient Covariance Matrix

Consider a Gaussian model with two group levels, \(A\) and \(B\), using \(A\) as the reference. Suppose the estimated intercept and \(B\) coefficient are \(\hat\beta_0=2\) and \(\hat\alpha_B=1.2\), and their estimated covariance matrix is \(\begin{pmatrix}0.09&-0.03\\-0.03&0.16\end{pmatrix}\). Transform to \(B\) as the reference and calculate the new standard errors.

The new intercept is \(\hat\beta_0^{*}=\hat\beta_0+\hat\alpha_B=3.2\), and the coefficient for \(A\) is \(\hat\alpha_A^{*}=-\hat\alpha_B=-1.2\). In matrix form, the transformation is \(A=\begin{pmatrix}1&1\\0&-1\end{pmatrix}\). Therefore the new covariance matrix is \(A\begin{pmatrix}0.09&-0.03\\-0.03&0.16\end{pmatrix}A^\mathsf{T}=\begin{pmatrix}0.19&-0.13\\-0.13&0.16\end{pmatrix}\).

The new intercept standard error is \(\sqrt{0.19}\approx0.436\), and the new \(A\)-versus-\(B\) coefficient standard error is \(\sqrt{0.16}=0.4\). The estimated mean for \(A\) is \(3.2-1.2=2\), and the estimated mean for \(B\) is \(3.2\). Both match the original fitted means, 2 and \(2+1.2=3.2\). The covariance has changed because the coefficient coordinates have changed; the fitted group means have not.

Fitting Invariance and Its Limits

Because the transformation is one-to-one, the two parameterizations assign the same linear predictor to every possible combination of factor level and covariate values. For a fixed GLM family, link, and any other parameters, they therefore give the same fitted means and the same likelihood for corresponding parameter values. If a maximum-likelihood estimate exists, a maximizer in one parameterization maps to a maximizer in the other: every candidate in either parameterization has a corresponding candidate with the same likelihood.

This statement concerns corresponding fits. If the design is rank deficient, the coefficients may not be uniquely determined; changing the reference does not repair that identifiability problem. The parameterization still represents the same possible linear predictors, but one should not infer unique coefficients merely from the fact that the reference-level transformation is reversible.

Common Mistake

A common error is to change the reference label while keeping all the old coefficient values. In the logistic example, retaining an intercept of \(-1\) and a coefficient of \(0.8\) after declaring \(B\) the reference would give predictor \(-1\) for \(B\) at \(x=0\). The original predictor for \(B\) at \(x=0\) was \(-1+0.8=-0.2\). The fitted probability would therefore change from \(1/(1+\exp(0.2))\approx0.4502\) to \(1/(1+\exp(1))\approx0.2689\). That is not a reference-level change alone; it is a different fitted model. The correction is to transform both the intercept and the factor coefficients, then verify the predictor level by level.

Key takeaway: A new reference level changes the intercept and each factor contrast by adding or subtracting the old reference contrast. Transform the coefficients together, and the linear predictors—and therefore the fitted means—remain unchanged.

Check Your Understanding

Use the transformation formulas to answer these questions.

  1. A factor has levels \(1,2,3\), with level 1 as reference, intercept \(\beta_0\), and coefficients \(\alpha_2,\alpha_3\). What are the intercept and factor coefficients if level 3 becomes the reference?
  2. Why does an unchanged linear predictor imply an unchanged fitted mean even when the link is nonlinear?
  3. In a Poisson model with a log link, how does a factor coefficient relate to the ratio of the fitted means for its level and the reference level?
  4. When coefficients are transformed, what operation gives the corresponding transformed covariance matrix?
  5. Does changing the reference level resolve non-identifiability caused by a rank-deficient design matrix? Explain.
Clinical Biostats