Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Rank Deficiency Under Perfect Confounding

Batch Effects Confounded With Biological Condition · Tutorial 126 of 700

Rank Deficiency Under Perfect Confounding

Learn to recognize perfect confounding as a linear dependence in the design matrix, verify the rank loss, and interpret what a fitted model can and cannot estimate.

Advanced 10 min read

What You'll Learn

  • Write a two-way additive model using batch and condition indicators.
  • Show algebraically why identical indicators make design-matrix columns dependent.
  • Calculate the rank of a small perfectly confounded design matrix.
  • Distinguish unique fitted values from non-unique batch and condition coefficients.
  • Recognize how changing reference coding can hide, but cannot remove, rank deficiency.
  • Diagnose aliased terms and understand why adding a computational constraint does not add information.

Why the Design Matrix Matters

A model can describe observed expression well and still fail to distinguish the effects named in that model. This happens when the study design makes two predictors carry exactly the same information. For batch and biological condition, the most direct case is perfect confounding: every sample in one condition is in one batch, and every sample in the other condition is in another batch. The batch indicator and condition indicator then agree for every sample.

The issue is not a property of a particular gene or an estimation algorithm. It is a property of the design matrix: the array of predictor values supplied to the model. When columns of that matrix are linearly dependent, the model's coefficients are not uniquely determined by the observations. The expression values can determine fitted group means while leaving the separate batch and condition coefficients unresolved.

Definition: The rank of a design matrix \(X\) is the number of linearly independent columns in \(X\). A model with one coefficient for each column has a full-column-rank design when every column is linearly independent of the others. If the columns are dependent, \(X\) is rank-deficient and the coefficient vector is not uniquely identifiable by ordinary least squares.

Two-Way Model and the Rank Condition

For one gene, let \(y_i\) be its measured expression in sample \(i\), \(B_i\) an indicator equal to 1 for batch B and 0 for batch A, and \(C_i\) an indicator equal to 1 for condition 1 and 0 for condition 0. A two-way additive model with an intercept is

$$ y_i = \mu + \tau B_i + \gamma C_i + \varepsilon_i. $$

Here \(\mu\) is the intercept, \(\tau\) is the batch B coefficient relative to batch A, and \(\gamma\) is the condition 1 coefficient relative to condition 0. In matrix form, \(y=X\beta+\varepsilon\), where the rows of \(X\) are \((1,B_i,C_i)\), and \(\beta=(\mu,\tau,\gamma)^\mathsf{T}\).

The rank question is purely algebraic: can one column of \(X\) be written as a linear combination of the others? If \(B_i=C_i\) for every sample, the batch and condition columns are identical. Therefore the three columns are dependent, \(X\) cannot have rank 3, and the three coefficients cannot all be uniquely estimated. This conclusion does not require a particular probability distribution for \(\varepsilon_i\).

For ordinary least-squares estimation and its usual uncertainty calculations, a common working assumption is that errors have mean zero, are independent across samples, and have common variance. Normal errors are additionally used for exact small-sample \(t\)- and \(F\)-based inference. These assumptions concern the error model; they do not repair a rank-deficient \(X\). Even if every error is exactly zero, identical predictor columns still cannot tell the model how to divide an observed difference between \(\tau\) and \(\gamma\).

Worked Example: Finding the Rank From the Sample Layout

Suppose four hypothetical samples have the following design: two are in batch A and condition 0, while two are in batch B and condition 1. There are no samples in either batch A and condition 1 or batch B and condition 0. The design matrix includes an intercept, a batch B indicator, and a condition 1 indicator.

SampleBatchConditionIntercept\(B_i\)\(C_i\)
1A0100
2A0100
3B1111
4B1111

Thus

$$ X = \begin{pmatrix} 1&0&0\\ 1&0&0\\ 1&1&1\\ 1&1&1 \end{pmatrix}. $$

The second and third columns are identical. The intercept column and the batch indicator column are independent, so the rank is exactly 2, not 3. Equivalently, the third column can be obtained by multiplying the second column by 1, so the columns do not provide three independent pieces of information. More samples with these same two batch-condition combinations would add rows but would not make the rank equal to 3.

What the Data Determine

When \(B_i=C_i\), substitute that equality into the model:

$$ \mu+\tau B_i+\gamma C_i = \mu+(\tau+\gamma)B_i. $$

The predicted expression for batch A, condition 0 is \(\mu\); for batch B, condition 1 it is \(\mu+\tau+\gamma\). The observations can inform those two fitted means, but the second mean depends on \(\tau\) and \(\gamma\) only through their sum. For any change that increases one coefficient and decreases the other by the same amount, the predictions stay the same. That is why the separate coefficients are not uniquely determined.

This is also visible in the least-squares objective. If \(B_i=C_i\), then every residual \(y_i-\mu-\tau B_i-\gamma C_i\) depends on \(\tau\) and \(\gamma\) through \(\tau+\gamma\). Minimizing the sum of squared residuals cannot select one unique split of that sum into two effects. The normal-equation matrix \(X^\mathsf{T}X\) is singular when \(X\) has dependent columns, so the usual inverse-based coefficient formula does not exist.

Worked Example: A Non-Unique Coefficient Fit

Continue with the four hypothetical samples above. Suppose their expression values, in normalized expression units, are 7, 9, 13, and 15, respectively. The mean in batch A and condition 0 is \((7+9)/2=8\); the mean in batch B and condition 1 is \((13+15)/2=14\). Under the additive model, the fitted means therefore require

$$ \mu=8,\qquad \mu+\tau+\gamma=14, \qquad\text{so}\qquad \tau+\gamma=6. $$

Several coefficient vectors satisfy these equations. For example, \((\mu,\tau,\gamma)=(8,6,0)\), \((8,0,6)\), and \((8,2,4)\) all give fitted values 8 for the first two samples and 14 for the last two. The model's predictions are the same for all three choices, even though their separate batch and condition coefficients differ.

The least-squares residuals are \(-1,1,-1,1\), so the residual sum of squares is \(1+1+1+1=4\) for each of these coefficient choices. This confirms that the data do not prefer one split of the six-unit difference over another. Reporting \(\tau=6\) as a batch effect and \(\gamma=0\) as a condition effect would be an arbitrary allocation, not a conclusion supported by this design.

A Short Algebraic Justification

The same result follows directly from the definition of linear dependence. Let \(\mathbf b\) and \(\mathbf c\) denote the batch and condition columns of \(X\). Under perfect confounding in the indicator coding above, \(\mathbf b=\mathbf c\). Therefore

$$ 0\mathbf 1+1\mathbf b-1\mathbf c=\mathbf 0. $$

This is a nonzero combination of the columns that equals the zero vector, so the columns are linearly dependent. Consequently \(\operatorname{rank}(X)\) is smaller than its number of columns. Also, for any real number \(a\), replacing \(\tau\) with \(\tau+a\) and \(\gamma\) with \(\gamma-a\) leaves the linear predictor unchanged:

$$ \mu+(\tau+a)B_i+(\gamma-a)C_i =\mu+\tau B_i+\gamma C_i+a(B_i-C_i) =\mu+\tau B_i+\gamma C_i, $$

because \(B_i-C_i=0\) for every sample. Thus at least one coefficient direction is invisible to the fitted values. This algebra explains both rank deficiency and the non-uniqueness seen in the numerical example.

Worked Example: Reference Coding Does Not Create Information

A model may use different reference categories. Suppose the batch predictor is instead \(A_i=1\) for batch A and 0 for batch B, while the condition predictor remains \(C_i=1\) for condition 1 and 0 for condition 0. In the same perfectly confounded layout, \(A_i=1-C_i\) for every sample. With an intercept, the design rows are \((1,1,0)\) for the two batch A, condition 0 samples and \((1,0,1)\) for the two batch B, condition 1 samples.

Now the two indicator columns are not identical, but the intercept is their sum:

$$ \mathbf 1=\mathbf a+\mathbf c. $$

So this coding is still rank-deficient. If the model coefficients are \((\mu,\beta_A,\gamma)\), the two fitted group means impose only \(\mu+\beta_A=8\) and \(\mu+\gamma=14\). For any chosen value \(t\) of \(\mu\), setting \(\beta_A=8-t\) and \(\gamma=14-t\) gives the same two fitted means. The visible form of the dependence changes with coding, but no reference-category choice supplies the missing batch-condition combinations.

Diagnostics, Remedies, and Limits

A practical first check is a batch-by-condition cross-tabulation. If each observed batch occurs in only one condition and the two indicators agree sample by sample, the perfect-confounding pattern is immediately apparent. A second check is to inspect the design matrix: identical columns, or a column exactly expressible as a combination of other columns, establish rank deficiency. Statistical software may report a singular design, mark a coefficient as aliased, omit a column, or apply a convention to produce one numerical solution. Such behavior is a computational response to dependence, not evidence that the omitted or displayed coefficient has been separately learned from the data.

It is important to distinguish the model's fitted values from its coefficient interpretation. In the example, the two observed group means can be fitted, but the batch and condition contributions to their difference cannot be separated by this model and design. Dropping one term can make a reduced model's coefficients computable, but the remaining group contrast then combines the changes represented by batch and condition; it does not become a separately established biological effect. Likewise, a numerical constraint or penalty may choose one solution from many, but that choice depends on the constraint or penalty and is not supplied by the observed comparison.

The direct design remedy is to collect samples that break the exact alignment—for example, include both conditions within a batch or include a condition in more than one batch. Such overlap makes the corresponding indicators differ across at least some samples. Whether a particular resulting design has enough independent information is still checked by its full design matrix. A rank check diagnoses the exact algebraic problem; it does not, by itself, assess other issues such as measurement quality, model fit, or how precisely an estimable effect is measured.

Key takeaway: If batch and condition indicators are identical across samples, their design-matrix columns are linearly dependent. A fitted contrast between the observed groups may be available, but an additive model cannot uniquely assign that contrast to batch and condition separately. Re-coding the same samples does not remove the dependence.

Check Your Understanding

Answer each question, then compare with the solutions.

  1. If the batch and condition indicator columns are identical, what is the maximum rank of a design matrix containing an intercept and those two indicators?
  2. In the four-sample example, the observed group means are 8 and 14. What equation must the batch and condition coefficients satisfy?
  3. Why does adding more samples in the same two observed batch-condition combinations fail to identify separate coefficients?
  4. With an intercept, suppose two indicator columns satisfy \(\mathbf 1=\mathbf a+\mathbf c\). Are the three columns independent? Explain.

Solutions. (1) The maximum rank is 2: the batch and condition columns are duplicates, while the intercept and either indicator are independent. (2) The model requires \(\tau+\gamma=14-8=6\); it does not specify the two coefficients separately. (3) The added rows repeat the same indicator pattern, so the batch and condition columns remain identical and the rank remains below 3. (4) No. The equation \(\mathbf 1-\mathbf a-\mathbf c=\mathbf 0\) is a nonzero linear dependence among the columns.

Clinical Biostats