Why Contrast Matrices Need Two Conditions
A factor with \(K\) levels can be described by \(K\) level effects, but including all \(K\) effects alongside an intercept introduces redundancy: adding a constant to every level effect and subtracting it from the intercept leaves every fitted linear predictor unchanged. Contrast coding removes this redundancy by representing level effects in a \(K-1\)-dimensional space. The key is to distinguish two conditions: the columns must sum to zero, and they must be linearly independent.
This tutorial focuses on how those conditions encode factor effects and what they do—and do not—establish about identifiability. Identifiability is ultimately a property of the design actually used in the model, not just of a coding matrix considered in isolation.
The zero-sum condition says that every represented level-effect vector satisfies \(\mathbf{1}_K^T\alpha=0\). The rank condition says that the columns represent \(K-1\) independent directions, rather than repeating or omitting some direction. Together, these conditions make the columns a basis for the space of zero-sum level effects.
What the Rank and Zero-Sum Conditions Establish
The space of zero-sum vectors in \(\mathbb{R}^K\) has dimension \(K-1\): its elements satisfy one linear constraint, and the first \(K-1\) coordinates can be chosen freely while the last is determined by their sum. A full-rank contrast matrix has \(K-1\) independent columns in this space, so it spans the whole space.
Proof. Since \(\mathbf{1}_K^TC=0\), every vector \(C\gamma\) has sum zero. The zero-sum space has dimension \(K-1\), and the columns of \(C\) are \(K-1\) independent vectors in that space. They therefore form a basis for it, so every zero-sum \(\alpha\) can be written as \(C\gamma\). For uniqueness, suppose \(C\gamma=C\tilde{\gamma}\). Then \(C(\gamma-\tilde{\gamma})=0\). Full column rank implies that the null space of \(C\) contains only the zero vector, so \(\gamma=\tilde{\gamma}\). \(\square\)
In a factor-only model, the linear predictor for level \(k\) is \(\eta_k=\beta_0+\alpha_k\). With \(\alpha=C\gamma\), the \(K\) level predictors are represented as \(\boldsymbol{\eta}=\beta_0\mathbf{1}_K+C\gamma\). Because the columns of \(C\) sum to zero, their average is \(\beta_0\). Thus the intercept is the unweighted average of the level-specific linear predictors, while \(\gamma\) gives coordinates for their deviations from that average. This is an average on the linear-predictor scale; for a nonidentity link it is not generally the average of the response means.
Worked Example: Encoding Three Level Effects
Consider a three-level factor and the matrix
Each column sums to zero: \(1+0-1=0\) and \(0+1-1=0\). The columns are independent because \(a(1,0,-1)^T+b(0,1,-1)^T=0\) forces \(a=0\) from the first coordinate and \(b=0\) from the second. Thus \(C\) has rank two, as required for a full contrast basis with three levels.
For \(\gamma=(0.4,-0.1)^T\), the level effects are
Their sum is \(0.4-0.1-0.3=0\). Conversely, if the level effects are \((0.4,-0.1,-0.3)^T\), their first two entries determine \(\gamma=(0.4,-0.1)^T\), and the third is then fixed by the zero-sum constraint. This is a unique coordinate representation, not an extra assumption about the observed responses.
For example, if \(\beta_0=1\), the three linear predictors are \(1.4,\;0.9,\;0.7\), whose average is \(1\). This illustrates the intercept interpretation directly.
From a Contrast Basis to Identifiable Coefficients
A full-rank contrast matrix guarantees that the coefficients uniquely encode the level effects. It does not, by itself, guarantee that a fitted model can distinguish all coefficients from the observations. For that, the design matrix must also have adequate rank. For a GLM, the linear predictor has the form \(\boldsymbol{\eta}=X\beta\), where \(X\) is the observed design matrix. If two coefficient vectors give the same \(\boldsymbol{\eta}\), the model cannot distinguish them through the linear predictor.
Proof. If \(X\) has full column rank, its null space contains only zero. If \(X\beta=X\tilde{\beta}\), then \(X(\beta-\tilde{\beta})=0\), hence \(\beta-\tilde{\beta}=0\), so \(\beta=\tilde{\beta}\). Conversely, if \(X\) does not have full column rank, there is a nonzero vector \(v\) with \(Xv=0\). For any \(\beta\), \(X(\beta+v)=X\beta+Xv=X\beta\); therefore distinct coefficient vectors give the same linear predictor. For the GLM statement, equality of response distributions at the design points implies equality of their means under the stated distribution-identifiability condition. A one-to-one link then gives equality of the corresponding linear predictors. Full column rank implies equality of the coefficient vectors by the first part. \(\square\)
For a factor represented by an intercept and a contrast matrix, the design matrix has a row \((1,c_k^T)\) for an observation at level \(k\), where \(c_k^T\) is row \(k\) of \(C\). If all levels are observed and \(C\) is a full contrast basis, these factor columns have full rank. Indeed, if \(a_0+c_k^Tb=0\) at every level, summing those equations over \(k\) gives \(Ka_0=0\), because the columns of \(C\) sum to zero. Thus \(a_0=0\). The equations then say \(Cb=0\), and full column rank gives \(b=0\). This argument concerns the factor-only design; when other predictors are included, the rank of the complete design matrix must be checked.
Worked Example: Identifiability in a Three-Level Binomial GLM
Suppose each of three factor levels has a positive number of binomial trials, and use the contrast matrix from the previous example. The level-specific logistic model is
The three distinct design rows are \((1,1,0)\), \((1,0,1)\), and \((1,-1,-1)\). The determinant of the resulting square design matrix is
The determinant is nonzero, so the design has rank three and the linear-predictor coefficients are uniquely determined by the three level predictors. For a concrete coefficient vector, take \(\beta_0=0\) and \(\gamma=(\log 2,-\log 2)^T\). The linear predictors are \(\log 2,-\log 2,0\), giving probabilities \(2/3,1/3,1/2\), respectively, since \(\operatorname{logit}^{-1}(x)=e^x/(1+e^x)\). With positive trial counts at all levels, the binomial distributions at the observed levels determine these probabilities, and the full-rank design makes the coefficient representation unique.
Worked Example: Zero-Sum Columns That Do Not Identify Both Coefficients
For three levels, consider
Both columns sum to zero, but they are identical, so the matrix has rank one rather than two. For \(\gamma=(0.3,0.2)^T\), the effects are \((0.5,0,-0.5)^T\). The different coefficient vector \(\tilde{\gamma}=(0.4,0.1)^T\) gives exactly the same effects, since \(0.4+0.1=0.5\). Thus zero-sum columns alone do not give unique coefficients or span all zero-sum effect vectors.
For instance, \((1,-1,0)^T\) is a zero-sum vector, but it cannot be written as \(C\gamma=(s,0,-s)^T\) for any \(s\). This coding describes only one direction of level variation. The problem is not repaired by observing more responses at those same levels: the two coefficient columns remain identical in the design.
What to Check in an Applied GLM
A useful check separates the coding question from the observed-design question. First, verify that the proposed contrast columns sum to zero and have rank \(K-1\); this confirms that they form a basis for zero-sum level effects. Then form the complete model matrix for the observations and check its column rank. A factor can be coded with a valid contrast basis and still fail to have identifiable coefficients in a particular model—for example, if the observed design makes a factor column redundant with other predictors.
Sum each column of \(C\). Every sum must be zero for this zero-sum parameterization.
Confirm \(\operatorname{rank}(C)=K-1\). A zero-sum matrix with lower rank omits some level-effect directions or uses redundant columns.
Assess the rank of the matrix built from the actual observations and all included predictors. Full rank is the condition for unique linear-predictor coefficients.
Common mistake: “The columns sum to zero, so the factor coefficients must be identifiable.” The conclusion does not follow. Zero sums constrain the effects to have average zero, but the columns might be linearly dependent, as in the preceding example. Even a full-rank contrast basis cannot prevent a loss of rank caused by the observed design or other model columns. The correction is to check both the contrast matrix and the complete design matrix, and to be clear about which parameters are being claimed to be identifiable.
Check Your Understanding
Use the distinction between contrast coding and design identifiability to answer these questions.
- Why do the zero-sum and full-rank conditions have different roles in a contrast matrix?
- A factor has four levels. What rank must a full contrast basis have, and what dimension is the space of zero-sum level-effect vectors?
- For a factor-only model with an intercept and a full contrast basis, why does observing every level imply full rank for those factor columns?
- Can a full-rank contrast matrix guarantee identifiable coefficients when the complete design includes other predictors? Explain.
- In a binomial logistic model, what role do positive trial counts and the one-to-one link play when interpreting design-matrix rank as coefficient identifiability?