TExcelTAD
Home › Linear Algebra & Matrix Theory › Linear Independence

Linear Independence

A set of vectors is linearly independent when none of them is redundant: no vector can be built from the others. Independence is the property that makes coordinates unique, and its failure in data (one feature that is a combination of others) is a common source of broken regressions.

Definition

Vectors v1,…,vk\mathbf{v}_1, \ldots, \mathbf{v}_k are linearly independent if the only solution of

c1v1+c2v2+⋯+ckvk=0c_1\mathbf{v}_1 + c_2\mathbf{v}_2 + \cdots + c_k\mathbf{v}_k = \mathbf{0}

is the trivial one, c1=c2=⋯=ck=0c_1 = c_2 = \cdots = c_k = 0. Otherwise they are linearly dependent, and a non-trivial solution is called a linear dependence relation.

Equivalent formulation: the vectors are dependent exactly when one of them is a linear combination of the others. If, say, c3≠0c_3 \ne 0 in a dependence relation, divide by it and solve for v3\mathbf{v}_3.

Quick facts:

Situation Independent?
one vector v\mathbf{v} yes, unless v=0\mathbf{v} = \mathbf{0}
two vectors yes, unless one is a multiple of the other
any set containing 0\mathbf{0} no (1⋅0=01 \cdot \mathbf{0} = \mathbf{0} is a non-trivial relation)
more than nn vectors in Rn\mathbb{R}^n always dependent
a subset of an independent set independent

The test: pivots in every column

Put the vectors as columns of AA. Independence means Ac=0A\mathbf{c} = \mathbf{0} has only c=0\mathbf{c} = \mathbf{0}, i.e. the homogeneous system has no free variables (Homogeneous Systems). So:

v1,…,vk\mathbf{v}_1, \ldots, \mathbf{v}_k are independent   ⟺  \iff rref⁡(A)\operatorname{rref}(A) has a pivot in every column   ⟺  \iff rank⁡A=k\operatorname{rank} A = k.

This also proves the "more than nn vectors" fact: an n×kn \times k matrix with k>nk > n has at most nn pivots, so some column has none.

When the vectors are dependent, the null space of AA lists every dependence relation:

python · try it yourself
from sympy import Matrix

v1, v2, v3 = Matrix([1, 2, 1]), Matrix([0, 1, 3]), Matrix([2, 7, 11])
A = Matrix.hstack(v1, v2, v3)
R, piv = A.rref()
print("pivot columns:", piv, "-> independent:", len(piv) == A.cols)

rel = A.nullspace()[0]
print("dependence relation coefficients:", list(rel))
print("check:", list(rel[0] * v1 + rel[1] * v2 + rel[2] * v3))

B = Matrix.hstack(Matrix([1, 0, 1]), Matrix([1, 1, 0]), Matrix([0, 1, 1]))
print("B pivots:", B.rref()[1], "-> independent:", B.rank() == 3)
pivot columns: (0, 1) -> independent: False
dependence relation coefficients: [-2, -3, 1]
check: [0, 0, 0]
B pivots: (0, 1, 2) -> independent: True

The relation −2v1−3v2+v3=0-2\mathbf{v}_1 - 3\mathbf{v}_2 + \mathbf{v}_3 = \mathbf{0} says v3=2v1+3v2\mathbf{v}_3 = 2\mathbf{v}_1 + 3\mathbf{v}_2.

Why independence matters: unique coordinates

If v1,…,vk\mathbf{v}_1, \ldots, \mathbf{v}_k are independent and w=a1v1+⋯+akvk\mathbf{w} = a_1\mathbf{v}_1 + \cdots + a_k\mathbf{v}_k, the coefficients aia_i are unique. Proof: if also w=b1v1+⋯+bkvk\mathbf{w} = b_1\mathbf{v}_1 + \cdots + b_k\mathbf{v}_k, subtract to get (a1−b1)v1+⋯+(ak−bk)vk=0(a_1 - b_1)\mathbf{v}_1 + \cdots + (a_k - b_k)\mathbf{v}_k = \mathbf{0}, and independence forces every ai−bi=0a_i - b_i = 0. With dependent vectors, every w\mathbf{w} in the span has infinitely many representations. This is why a basis must be independent (Basis and Dimension).

In software: redundant features

In a data matrix XX (rows = samples, columns = features), a column that is a linear combination of other columns carries no new information. Typical causes: the same quantity in two units, a "total" column next to its parts, or one-hot encoding every category plus an intercept (the "dummy variable trap").

Then the columns are dependent, rank⁡X<number of columns\operatorname{rank} X < \text{number of columns}, XTXX^TX is singular, and ordinary least squares has no unique solution: infinitely many weight vectors fit equally well, and numerical solvers return huge, unstable coefficients.

python · try it yourself
import numpy as np

rng = np.random.default_rng(3)
n = 200
width = rng.uniform(1, 10, n)
height = rng.uniform(1, 10, n)
perimeter = 2 * width + 2 * height          # redundant: a combination of two others
X = np.column_stack([width, height, perimeter])

print("columns:", X.shape[1], " rank:", int(np.linalg.matrix_rank(X)))
print(f"condition number of X^T X: {np.linalg.cond(X.T @ X):.1e}")

# null space from the SVD: the right singular vector for the ~0 singular value
_, s, Vt = np.linalg.svd(X)
relation = Vt[-1] / Vt[-1][0]
print("smallest singular value ~ 0:", s[-1] < 1e-9)
print("relation (scaled):", np.round(relation, 4).tolist())
columns: 3  rank: 2
condition number of X^T X: 1.7e+16
smallest singular value ~ 0: True
relation (scaled): [1.0, 1.0, -0.5]

The relation [1,1,−0.5][1, 1, -0.5] reads width+height−0.5⋅perimeter=0\text{width} + \text{height} - 0.5 \cdot \text{perimeter} = 0. Libraries respond with warnings ("singular matrix", "collinearity"); scikit-learn's OneHotEncoder(drop="first") and regularisation (Regularization) are standard fixes. Near-dependence (features that are almost combinations of others) causes the same instability in a milder form, called multicollinearity.

Exercises

Exercise 1: By inspection

Decide without computing: (a) {[1,2],[3,6]}\{[1, 2], [3, 6]\}, (b) {[1,0,0],[0,0,0],[0,1,0]}\{[1, 0, 0], [0, 0, 0], [0, 1, 0]\}, (c) {[1,2],[0,1],[5,5]}\{[1, 2], [0, 1], [5, 5]\}.

Answer

All three are dependent.

Solution

(a) [3,6]=3⋅[1,2][3, 6] = 3 \cdot [1, 2]. (b) The set contains the zero vector. (c) Three vectors in R2\mathbb{R}^2 are always dependent.

Exercise 2: Find a relation

Show that [1, 1, 0], [0, 1, 1], [1, 3, 2] are dependent and write the third as a combination of the first two.

Answer

[1,3,2]=1⋅[1,1,0]+2⋅[0,1,1][1, 3, 2] = 1 \cdot [1, 1, 0] + 2 \cdot [0, 1, 1].

Solution
a⋅[1,1,0]+b⋅[0,1,1]=[1,3,2]first coordinate: a=1;third: b=2;second: a+b=3✓\begin{aligned} &a \cdot [1, 1, 0] + b \cdot [0, 1, 1] = [1, 3, 2] \\ &\text{first coordinate: } a = 1; \quad \text{third: } b = 2; \quad \text{second: } a + b = 3 \checkmark \end{aligned}
python · try it yourself
from sympy import Matrix
A = Matrix([[1, 0, 1], [1, 1, 3], [0, 1, 2]])
print(A.rank(), list(A.nullspace()[0]))
2 [-1, -2, 1]

The null-space vector [−1,−2,1][-1, -2, 1] is the relation −v1−2v2+v3=0-\mathbf{v}_1 - 2\mathbf{v}_2 + \mathbf{v}_3 = \mathbf{0}.

Exercise 3: Choose h

For which hh are [1,2,3][1, 2, 3], [2,5,7][2, 5, 7], [1,h,5][1, h, 5] dependent?

Answer

h=4h = 4.

Solution

Row-reduce the matrix with these columns:

[12125h375]→[12101h−2012]→[12101h−2004−h]\begin{bmatrix} 1 & 2 & 1 \\ 2 & 5 & h \\ 3 & 7 & 5 \end{bmatrix} \to \begin{bmatrix} 1 & 2 & 1 \\ 0 & 1 & h-2 \\ 0 & 1 & 2 \end{bmatrix} \to \begin{bmatrix} 1 & 2 & 1 \\ 0 & 1 & h-2 \\ 0 & 0 & 4-h \end{bmatrix}

There is a pivot in every column unless 4−h=04 - h = 0. So they are dependent exactly when h=4h = 4. (Check h=4h = 4: [1,4,5]=−3⋅[1,2,3]+2⋅[2,5,7]=[1,4,5][1, 4, 5] = -3 \cdot [1, 2, 3] + 2 \cdot [2, 5, 7] = [1, 4, 5] ✓.)

Exercise 4: Detect a redundant column

Build a 100×4 data matrix with seeded random columns aa, bb, cc and a fourth column d=a−3cd = a - 3c. Use np.linalg.matrix_rank to show the redundancy, then drop dd and check the rank is full.

Answer

Rank 3 with dd, rank 3 (full, 3 columns) without it.

Solution
python · try it yourself
import numpy as np
rng = np.random.default_rng(0)
a, b, c = rng.normal(size=(3, 100))
X = np.column_stack([a, b, c, a - 3 * c])
print("rank with d:", int(np.linalg.matrix_rank(X)), "of", X.shape[1])
print("rank without d:", int(np.linalg.matrix_rank(X[:, :3])), "of", 3)
rank with d: 3 of 4
rank without d: 3 of 3

Test yourself

Five vectors in R4\mathbb{R}^4 are given. What can you conclude?

  1. They are independent
  2. They are dependent
  3. They span R4\mathbb{R}^4
  4. Nothing

The vectors are the columns of AA. Which condition means they are linearly independent?

  1. rref⁡(A)\operatorname{rref}(A) has a pivot in every column
  2. rref⁡(A)\operatorname{rref}(A) has a pivot in every row
  3. AA is square
  4. AA has no zero entries

A dataset has columns price_usd and price_eur=0.92⋅price_usd\text{price\_eur} = 0.92 \cdot \text{price\_usd}. What happens to XTXX^TX?

  1. It becomes the identity
  2. It becomes skew-symmetric
  3. Nothing
  4. It becomes singular, so least squares has no unique solution