Why Use Effect Coding?
A factor-only generalized linear model assigns a separate linear predictor to each level of a categorical factor. Reference coding expresses those predictors relative to one selected level. Effect coding instead centers the level-specific predictors around their unweighted mean. This makes the intercept a “grand mean” across levels, while the coefficients describe deviations from it.
The word “mean” needs care here. In a generalized linear model, the intercept is generally an average on the linear-predictor scale, not an arithmetic average of the expected responses. The link function connects those two scales, and a nonlinear inverse link does not preserve averages.
Definition and Coding Matrix
Suppose a factor has \(K\) levels, labelled \(1,\ldots,K\), and the model contains no other predictors or offset. Let \(\eta_j\) denote the linear predictor for level \(j\). For an observation \(i\) in level \(j\), its expected response \(\mu_i=E[Y_i]\) is related to the predictor by \(g(\mu_i)=\eta_j\), where \(g\) is the GLM link.
A common coding matrix uses \(K-1\) columns. The first \(K-1\) levels receive the rows of the identity matrix, and the final level receives \(-1\) in every column. If \(\boldsymbol{\gamma}=(\alpha_1,\ldots,\alpha_{K-1})^\mathsf{T}\), the model is \(\eta_j=\beta_0+\mathbf{c}_j^\mathsf{T}\boldsymbol{\gamma}\), where \(\mathbf{c}_j\) is the coding row for level \(j\). The implied deviation for level \(K\) is \(\alpha_K=-\sum_{j=1}^{K-1}\gamma_j\).
The final row is not a reference level with zero effect. It represents the level whose deviation is the negative sum of the other deviations. This is what enforces the constraint.
Worked Example: Three Levels With an Identity Link
Suppose a Gaussian identity-link model has level-specific fitted means 10, 14, and 22 for levels A, B, and C. With an identity link, these are also the level-specific linear predictors: \(\eta_A=10\), \(\eta_B=14\), and \(\eta_C=22\).
Intercept. The unweighted mean of the three predictors is
Deviations. Subtracting this intercept gives
The constraint holds because \((-16-4+20)/3=0\). Under the stated coding, the two fitted coefficients are \(\gamma_A=-16/3\) and \(\gamma_B=-4/3\); the coding implies \(\alpha_C=-\gamma_A-\gamma_B=20/3\). Adding the intercept back recovers all three predictors.
Why the Intercept Is the Unweighted Mean
The interpretation follows directly from the constraint. It does not depend on the distribution family or link function: those determine how the linear predictors relate to the response distribution, but not how the factor levels are coded.
To verify the result, substitute \(\eta_j=\beta_0+\alpha_j\) and use \(\sum_j\alpha_j=0\):
Conversely, for any given set of \(K\) level-specific predictors, define \(\beta_0=K^{-1}\sum_j\eta_j\) and \(\alpha_j=\eta_j-\beta_0\). Then \(\sum_j\alpha_j=\sum_j\eta_j-K\beta_0=0\), so these parameters satisfy the effect-coding representation. Thus the constraint gives a valid representation for every set of level predictors.
The \(K-1\) coefficients in the displayed coding matrix are identifiable as a parameterization of these predictors. In fact, if \(\beta_0\mathbf{1}+C\boldsymbol{\gamma}=\mathbf{0}\), the mean of the \(K\) entries on the left is \(\beta_0\), because every column of \(C\) sums to zero. Therefore \(\beta_0=0\). The first \(K-1\) entries then equal the respective components of \(\boldsymbol{\gamma}\), so \(\boldsymbol{\gamma}=\mathbf{0}\). The columns for the intercept and the \(K-1\) effects are linearly independent, and the parameterization has full rank. \(\square\)
This is a parameterization of the level predictors, not a claim about how the predictors will be estimated. Estimation still depends on the response data and likelihood. When a factor-only model allows a separate predictor for each level, effect coding and reference coding describe the same set of possible level predictors; they differ in the coordinates used to express them.
Worked Example: A Log-Link Model and the Geometric Mean
Consider a Poisson model with a log link and three factor levels whose fitted means are 2, 8, and 4. The linear predictors are their natural logarithms:
The effect-coded intercept is their unweighted mean:
The deviations are \(\alpha_A=\log 2-\log 4=\log(1/2)\), \(\alpha_B=\log 8-\log 4=\log 2\), and \(\alpha_C=\log 4-\log 4=0\). They sum to zero. With A and B as the first two coded levels, the coefficients are \(\gamma_A=\log(1/2)\) and \(\gamma_B=\log 2\); the implied deviation for C is \(-\gamma_A-\gamma_B=0\).
Here the inverse link of the intercept is \(e^{\beta_0}=4\), the geometric mean of the three fitted response means, not their arithmetic mean \((2+8+4)/3=14/3\). The intercept remains the average of the linear predictors; applying the inverse link does not turn it into an arithmetic average of responses.
Unequal Group Sizes Do Not Change the Coding
The grand mean in this parameterization gives equal weight to each level, not to each observation. This distinction matters when the observed group sizes differ. The likelihood may give levels with more observations more influence on the estimates, but that does not change the definition of the effect-coded intercept.
Worked Example: Unequal Binomial Group Sizes
Suppose three groups have independent Bernoulli observations, with observed success proportions \(2/10\), \(1/2\), and \(8/10\). In a factor-only logistic model, the fitted probabilities are these proportions, and their level-specific linear predictors are the logits:
The effect-coded intercept is
Thus the three deviations are \(-\log 4\), \(0\), and \(\log 4\). The groups have sizes 10, 2, and 10, but the intercept is still the unweighted mean across the three level predictors. For comparison, the observation-count-weighted average of those predictors is
In this particular set of counts it happens to equal the unweighted mean. That equality is not guaranteed by effect coding; it occurs because the first and third groups have equal sizes and opposite predictors. Changing the third group size to 4 would make the weighted average \((-10\log 4+4\log 4)/16=-3\log 4/8\), while the effect-coded intercept would remain 0 for the same three level predictors.
What the Coefficients Mean
For each of the first \(K-1\) levels, its coefficient is the difference between that level’s linear predictor and the unweighted mean across all levels. The last level’s deviation is not separately estimated as an additional free coefficient; it is the negative sum of the displayed coefficients. Individual coefficients therefore have a direct deviation interpretation, but they are not pairwise differences between levels.
For example, in the Poisson example, \(\gamma_A=\log(1/2)\) says that level A’s log mean is \(\log(1/2)\) below the average log mean. Exponentiating gives the ratio of A’s mean to the geometric mean across levels: \(e^{\gamma_A}=1/2\). It does not say that A’s mean is half the mean of a chosen reference group. Pairwise comparisons require subtracting the corresponding level deviations.
Common Mistake: Averaging Responses Instead of Predictors
A common mistake is to say that the intercept is the average response across levels, or to average the level predictors using group sizes. Neither statement describes the coding constraint. The intercept is the unweighted average of the \(K\) level-specific linear predictors. For a nonlinear link, its inverse-link value need not be the arithmetic mean of the level-specific expected responses. Unequal numbers of observations also do not turn the coding constraint into an observation-weighted average.
Another tempting error is to treat the final level as the reference level because it has a row of negative ones. Under this coding, that level generally has a nonzero deviation. Its contribution is determined by the sum-to-zero constraint; it is not fixed at zero as a reference-level predictor would be.
Check Your Understanding
Use the sum-to-zero coding convention described above.
- A four-level factor has linear predictors 1, 3, 5, and 7. What are the effect-coded intercept and the four deviations?
- For a three-level factor, the first two deviations are \(-2\) and 5. What is the deviation for the third level?
- In a log-link model, what scale does the effect-coded intercept average? Why need it not be the arithmetic mean of the fitted means?
- If factor levels have unequal sample sizes, does the effect-coding constraint weight a level by its number of observations? Explain.
- Under the stated coding, why is the final factor level not generally a zero-deviation reference level?