Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 14

Rank Deficiency & Multicollinearity in Least Squares

Recommended resources

Introduction

In our last lesson, we successfully derived the normal equations, , which provide a direct algebraic path to finding the best-fit parameters for a linear model. We concluded that if the matrix is invertible, a unique solution exists: . This formula represents a major triumph, connecting a clear geometric principle—orthogonal projection—to a concrete computational recipe.

However, this solution hinges on a crucial "if": the invertibility of . What happens when this condition fails? This is not just a mathematical curiosity; it's a common and important failure mode for models in the wild, especially in fields like computational biology where features can be highly interrelated. This lesson delves into the scenario where is singular, or non-invertible. You will learn why this situation arises from rank deficiency in your feature matrix , why it leads to infinitely many "best" solutions, and how this phenomenon, known as multicollinearity, critically affects the interpretability of your machine learning models.


When Can't We Invert ?

The entire solvability of our system rests on the properties of the matrix . A fundamental theorem of linear algebra provides a direct link between the properties of and the invertibility of .

A matrix is invertible if and only if the columns of are linearly independent.

Conversely, if the columns of are linearly dependent, then is singular (non-invertible), and our closed-form solution breaks down. Linear dependence means that at least one feature vector in our matrix can be written as a linear combination of the others. In the context of machine learning, this is the definition of perfect multicollinearity.

Multicollinearity - Gregory Gundersen

This article provides a clear, formal link between linearly dependent predictors and the non-invertibility of the Gram matrix, X^T X.

First, read the introductory section titled "Linearly dependent predictors" to solidify the connection between the invertibility of A^T A and the rank of A. Then, for a more rigorous justification, review the proof in the appendix, "A1. Proof that G=A⊤A is invertible iff A is full rank". The proof is concise and demonstrates that if A\mathbf{x} = \mathbf{0} for some non-zero \mathbf{x} (the definition of linear dependence), then it must be that A^T A\mathbf{x} = \mathbf{0} as well, which proves A^T A is singular.

The key takeaway is that redundant features—features that provide no new information relative to others—are the root cause of the mathematical problem. For instance, if your dataset includes features for a patient's height in inches () and height in centimeters (), these columns are linearly dependent because . The matrix containing these columns is not full rank, and will be singular.


Geometric Intuition: Collapsing Spaces

To understand why this leads to infinite solutions, let's revisit the geometric picture. The columns of your feature matrix define the basis vectors of your model's column space, . This is the "output space" where all possible predictions, , must live.

When the columns are linearly independent, they span a space whose dimension is equal to the number of columns (features). For example, two independent vectors in span a plane. However, if the columns are linearly dependent, the space they span "collapses" into a lower dimension. Two dependent vectors in don't span a plane; they only span a line.

This "squishing" of space is precisely what a non-invertible transformation does. The concept of rank formalizes this idea.

Inverse matrices, column space and null space | Chapter 7, Essence of linear algebra

This video from 3Blue1Brown provides a beautiful geometric intuition for rank and its connection to the null space.

Please watch from 08:02 to 10:40. Pay close attention to these two concepts: Rank: The number of dimensions in the output of a transformation (i.e., the dimension of the column space). If the rank is less than the number of columns, the matrix is "rank-deficient." Null Space (or Kernel): The set of all vectors that get squished to the zero vector by the transformation. For a full-rank matrix, only the zero vector itself is in the null space. For a rank-deficient matrix, a whole line or plane of vectors can be squished to zero.

When is rank-deficient, the projection of onto still gives us a unique prediction vector . The problem is finding the coordinates that produce it. Since the basis vectors (the columns of ) are redundant, there are infinitely many ways to combine them to get to the same point .

Imagine trying to specify a location on a line using two collinear vectors, and . The target point is . You could describe this as , or , or , and so on. The coordinate pair is not unique. This is exactly what happens with our regression coefficients.


Why Infinite Solutions Emerge

This lack of uniqueness can be understood through several powerful analogies.

Is there an intuitive explanation why multicollinearity is a problem in ...

This discussion on Cross Validated offers several excellent intuitive explanations for the problem of multicollinearity.

Read the following three short answers, which each provide a different mental model for the same problem: The Geometric Answer: Start with the answer by user "Scortchi" which begins here. This directly relates our geometric intuition of a collapsed subspace to the non-uniqueness of the coefficients \beta_1 and \beta_2. The Boulder Analogy: Next, read the answer by user "Charlie" starting with "Two people are pushing...". This is a fantastic non-mathematical analogy. If two forces are always applied together, you can measure their combined effect, but you can't disentangle their individual contributions. The regression coefficients are these individual contributions. The Information Overlap: Finally, read the answer by user "Abhijit" starting here. This frames the problem in terms of information. Correlated features contain redundant information, and the model has no unique way to "apportion" the explanatory power to the individual features.

From an algebraic standpoint, the existence of infinite solutions stems from the null space of . If is singular, its null space contains non-zero vectors. Let be any such vector, so that .

If we find one solution that satisfies the normal equation , we can create another valid solution by adding any multiple of :

Since there are infinitely many choices for the scalar , there are infinitely many solution vectors , all of which are equally "optimal" in that they produce the exact same prediction vector and thus the same minimum sum of squared errors.


The Real-World Problem: Near-Multicollinearity

In practice, perfect multicollinearity is rare and often easy to spot (e.g., the dummy variable trap or including a variable twice in different units). The more common and insidious problem is near-multicollinearity, where features are highly correlated but not perfectly dependent.

In this case, is technically invertible, but it is ill-conditioned. This means it is very close to being singular. An ill-conditioned matrix is numerically unstable; small changes in the input data can lead to massive changes in the output of the inverse.

For our regression model, this means the estimated coefficients can swing wildly with minor variations in the training data. This makes the model's parameters completely uninterpretable.

This plot visualizes the effect of near-multicollinearity. A linear model was trained repeatedly on slightly different subsets of data. The features Height, Weight, and BMI are highly correlated. Notice how their estimated coefficients vary dramatically across runs, with BMI even flipping sign. In contrast, the coefficient for Age, which is uncorrelated, remains stable. The horizontal lines show the mean coefficient value for each feature.

This instability destroys our ability to make sense of the model. We might train a model and get a coefficient of +2.3 for "Weight". We train it again on slightly different data and get -5.1. We cannot possibly conclude anything about the effect of weight on the outcome.

This phenomenon is a classic "failure mode" you should be aware of, especially in your work with biological data. In genomics, expression levels of genes within the same pathway are often highly correlated. If you include them all in a linear model to predict a phenotype (like ALL vs. AML cancer), the model might have good overall predictive accuracy, but the coefficients for the individual genes will be unstable and meaningless. You cannot use them to claim "Gene X is an important positive driver," because its estimated effect is hopelessly entangled with the effects of other correlated genes.

Multicollinearity

This video provides a practical explanation of how multicollinearity manifests in model results.

Watch the segment from 01:04 to 04:25. The example of TV and radio advertising spend is analogous to two correlated genes. The key symptom described is that the overall model can have a very high R-squared (it explains the data well), but the individual coefficients for the correlated variables have huge standard errors and are statistically insignificant (high p-values). The model knows that collectively the features are important, but it cannot confidently assign credit to any individual feature.


Conclusion

In this lesson, we explored the consequences of a non-invertible matrix, linking it from a formal mathematical condition to a practical and common pitfall in machine learning.

Key Takeaways:

  • The normal equations have a unique solution only if is invertible, which requires the columns of the feature matrix to be linearly independent.
  • When the columns of are linearly dependent (perfect multicollinearity), the matrix is rank-deficient. Geometrically, its column space collapses into a lower dimension.
  • This rank deficiency leads to a singular and results in infinitely many solutions for the regression coefficients , rendering the individual coefficients uninterpretable.
  • More commonly, near-multicollinearity (highly correlated features) makes ill-conditioned. This causes the coefficient estimates to be highly unstable and sensitive to small changes in the data, again destroying their interpretability.
  • The primary symptom of multicollinearity is a model that may predict well overall (e.g., high R-squared) but has large standard errors and insignificant p-values for the correlated individual coefficients.

So, if perfect multicollinearity leads to infinite solutions, how do software packages often manage to return an answer instead of just an error? They employ a strategy to select one specific solution out of the infinite set. In our next lesson, we'll investigate the Moore-Penrose pseudoinverse, a generalization of the matrix inverse that provides a principled way to find the "best" and most stable solution, even when the system is rank-deficient.