Tutorials › High-Dimensional Genomic Data Analysis › Principal Components From a Genotype Matrix

Population Structure, Ancestry and Relatedness · Tutorial 104 of 795

Principal Components From a Genotype Matrix

See how the SVD of a genotype matrix yields principal-component directions, individual scores, and the eigenvalues used to summarize variation.

Intermediate 12 min read

What You'll Learn

  • Define the genotype matrix and the centering and scaling conditions relevant to its decomposition.
  • Derive the links between its SVD and the eigen-decompositions of both Gram matrices.
  • Distinguish individual eigenvectors from individual principal-component scores.
  • Calculate scores, singular values, eigenvalues, and variance proportions in small examples.
  • Check the effects of scaling conventions, zero singular values, and sign ambiguity.
  • Diagnose computational mismatches and identify when an eigen-based route can replace direct SVD.

From Genotypes to Individual Scores

Principal components give coordinates for individuals along directions that capture variation in a data matrix. In genotype analysis, the central computational object is a matrix with individuals in rows and genetic variants in columns. Singular value decomposition (SVD) provides one route from this matrix to individual coordinates; eigen-decomposition of a related matrix provides another. The two routes agree, with a specific scaling relationship between their outputs.

The distinction matters in practice: an eigenvector of the matrix of individual-by-individual inner products is not itself the usual vector of principal-component scores. The score also includes a singular-value factor. Keeping that factor straight makes calculations interpretable and helps detect implementation errors.

Definition: Let \(G\) be an \(n \times m\) genotype matrix, with \(n\) individuals in rows and \(m\) variants in columns. Let \(Z\) be the matrix after applying the chosen column-centering and scaling to \(G\). The \(k\)th individual principal-component score vector is the projection of \(Z\) onto a unit-length variant direction \(v_k\): \(t_k=Zv_k\). The rows of the matrix \(T=ZV\) contain the individuals’ coordinates on the selected component directions.

Here \(Z\) is the input to the decomposition; the algebra below applies to any real-valued \(Z\). For genotype analysis, its columns are typically centered across individuals, and their scaling follows the chosen genotype-standardization convention. These choices affect which variants contribute how much to the decomposition. A column that is constant across individuals has zero variance and cannot be divided by its standard deviation; it must be excluded or handled before standardizing. The calculations assume a finite matrix without unresolved missing entries.

The SVD and the Two Gram Matrices

The SVD of \(Z\) can be written as \(Z=UDV^{\mathsf T}\), where the columns of \(U\) and \(V\) are orthonormal, and \(D\) has nonnegative singular values \(d_1 \geq d_2 \geq \cdots \geq 0\) on its diagonal. For a matrix of rank \(r\), the \(r\) positive singular values correspond to nonzero components. The SVD directly gives the principal-component scores: \(ZV=UD\).

There are two relevant Gram matrices. \(ZZ^{\mathsf T}\) is \(n \times n\), with one row and column per individual; \(Z^{\mathsf T}Z\) is \(m \times m\), with one row and column per variant. Substitution of the SVD shows that the left singular vectors are eigenvectors of the first, while the right singular vectors are eigenvectors of the second.

$$ ZZ^{\mathsf T}=UDV^{\mathsf T}VDU^{\mathsf T} =UD^2U^{\mathsf T}, \qquad Z^{\mathsf T}Z=VD^2V^{\mathsf T}. $$
Theorem: If \(Z=UDV^{\mathsf T}\), then for each positive singular value \(d_k\), \(u_k\) is an eigenvector of \(ZZ^{\mathsf T}\) with eigenvalue \(d_k^2\), and \(v_k\) is an eigenvector of \(Z^{\mathsf T}Z\) with the same eigenvalue. The individual score vector is \(t_k=Zv_k=d_ku_k\). Thus the eigenvector \(u_k\) supplies the score direction across individuals, while \(d_k\) supplies its scale.

The score relationship follows directly from the SVD:

$$ Zv_k=UDV^{\mathsf T}v_k =UD e_k =d_k u_k, $$

where \(e_k\) is the \(k\)th coordinate vector and \(V^{\mathsf T}v_k=e_k\). The same result follows from the individual Gram matrix. If \(ZZ^{\mathsf T}u_k=d_k^2u_k\) with \(d_k>0\), define \(v_k=Z^{\mathsf T}u_k/d_k\). Then

$$ v_k^{\mathsf T}v_k =\frac{u_k^{\mathsf T}ZZ^{\mathsf T}u_k}{d_k^2}=1, \qquad Zv_k=\frac{ZZ^{\mathsf T}u_k}{d_k}=d_ku_k. $$

So a positive-eigenvalue individual eigenvector recovers a unit-length variant direction and the corresponding individual scores. If \(d_k=0\), this division is not defined: the component has no variation in the data, and it has no nonzero score vector.

Worked Calculations

Worked Example: Decomposing a Small Genotype Matrix

Consider this hypothetical centered, transformed genotype matrix for three individuals and two variants:

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

The columns each sum to zero. First form the individual Gram matrix:

$$ ZZ^{\mathsf T}= \begin{pmatrix} 1&0&-1\\ 0&1&-1\\ -1&-1&2 \end{pmatrix}. $$

The unit vector \(u_1=(1,1,-2)^{\mathsf T}/\sqrt{6}\) is an eigenvector with eigenvalue 3: multiplying the matrix by \((1,1,-2)^{\mathsf T}\) gives \((3,3,-6)^{\mathsf T}\). The unit vector \(u_2=(1,-1,0)^{\mathsf T}/\sqrt{2}\) is an eigenvector with eigenvalue 1. The remaining eigenvalue is zero, since the matrix has rank at most two.

The positive singular values are therefore \(d_1=\sqrt{3}\) and \(d_2=1\). The score vectors are \(t_k=d_ku_k\):

$$ t_1= \begin{pmatrix} 1/\sqrt{2}\\ 1/\sqrt{2}\\ -\sqrt{2} \end{pmatrix}, \qquad t_2= \begin{pmatrix} 1/\sqrt{2}\\ -1/\sqrt{2}\\ 0 \end{pmatrix}. $$

For a direct check, the matching variant directions are \(v_1=(1,1)^{\mathsf T}/\sqrt{2}\) and \(v_2=(1,-1)^{\mathsf T}/\sqrt{2}\). Multiplying \(Z v_1\) and \(Z v_2\) gives exactly \(t_1\) and \(t_2\). The total squared matrix length is \(1+0+0+1+1+1=4\), also \(d_1^2+d_2^2=3+1=4\). The two components account for \(3/4\) and \(1/4\) of this total, respectively.

Worked Example: Recovering Scores From Variant Eigenvectors

Suppose a second hypothetical transformed matrix is

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

The variant Gram matrix is \(Z^{\mathsf T}Z=\begin{pmatrix}2&2\\2&2\end{pmatrix}\). Its leading unit eigenvector is \(v_1=(1,1)^{\mathsf T}/\sqrt{2}\), with eigenvalue 4. Thus \(d_1=\sqrt{4}=2\). The score vector is the matrix projection, not the variant eigenvector:

$$ t_1=Zv_1= \begin{pmatrix} -\sqrt{2}\\ 0\\ \sqrt{2} \end{pmatrix}. $$

Equivalently, the individual eigenvector is \(u_1=t_1/2=(-1,0,1)^{\mathsf T}/\sqrt{2}\), and its eigenvalue in \(ZZ^{\mathsf T}\) is \(d_1^2=4\). The second eigenvalue of \(Z^{\mathsf T}Z\) is zero: the two columns are identical, so the data contain only one nonzero direction. This example shows why reporting \(v_1\) alone would describe a variant direction, not the three individuals’ coordinates.

Worked Example: Changing a Covariance Divisor

For four hypothetical individuals, take the centered matrix

$$ Z= \begin{pmatrix} \sqrt{2}&0\\ -\sqrt{2}&0\\ 0&1\\ 0&-1 \end{pmatrix}. $$

Its columns are orthogonal, and \(Z^{\mathsf T}Z=\operatorname{diag}(4,2)\). The singular values are \(2\) and \(\sqrt{2}\), while the leading score vector is the first column of \(Z\), because the leading variant direction is \(v_1=(1,0)^{\mathsf T}\).

If a covariance-style matrix is defined as \(ZZ^{\mathsf T}/(n-1)\), here \(n-1=3\), its nonzero eigenvalues are \(4/3\) and \(2/3\). If instead the Gram matrix is divided by \(m=2\), its nonzero eigenvalues are \(2\) and \(1\). The eigenvalue scales differ, but the component directions and the proportion of total squared length are unchanged: \(4/(4+2)=2/3\) for the first component and \(2/(4+2)=1/3\) for the second. State the divisor when reporting eigenvalues; do not confuse a common scaling of eigenvalues with a change in the directions.

Why the Equivalence Is Useful

The two Gram matrices have the same positive eigenvalues, but their dimensions differ. The individual matrix \(ZZ^{\mathsf T}\) is \(n \times n\), and the variant matrix \(Z^{\mathsf T}Z\) is \(m \times m\). When one dimension is much smaller than the other, an eigen-decomposition on the smaller Gram matrix can reduce computation. The SVD, in contrast, gives the left and right singular vectors together and makes the score scaling explicit. Either route should return equivalent components, subject to numerical precision and choices about component signs.

For a nonzero component, its eigenvalue in either unscaled Gram matrix is \(d_k^2\). The total squared length of the matrix is

$$ \lVert Z\rVert_F^2 =\sum_{i=1}^{n}\sum_{j=1}^{m}Z_{ij}^2 =\sum_k d_k^2. $$

Consequently, the fraction of total squared length associated with component \(k\) is \(d_k^2/\sum_\ell d_\ell^2\), or the same ratio formed from Gram-matrix eigenvalues. When the columns of \(Z\) are centered, this corresponds to the fraction of total centered variation under the stated scaling. This description is algebraic: it does not by itself establish a biological cause for a component or a sampling-based uncertainty statement.

Checks, Failure Modes, and Conventions

A useful implementation check is to compare both the eigenvalues and the score scaling. If \(u_k\) is unit length, then the squared length of the score vector must be \(t_k^{\mathsf T}t_k=d_k^2\). Also, a score matrix formed from \(K\) right singular vectors should equal \(ZV_K\), and it should equal \(U_KD_K\) up to numerical precision. A substantial mismatch often indicates a transposed input, a missing singular-value multiplier, inconsistent scaling, or misaligned individual ordering.

Signs need not match between software outputs. If \(u_k\) and \(v_k\) are both multiplied by \(-1\), the SVD remains valid and the scores reverse sign. The coordinates have not changed in any substantive way; comparisons should allow for this sign flip. If singular values are repeated, the vectors within the corresponding subspace need not be uniquely determined: different valid orthonormal bases can represent the same subspace. In that case, compare the subspace or reconstructed matrix rather than expecting component vectors to match one by one.

The matrix identity also does not validate the input. Check that rows and columns are in the intended order, that the centering and scaling were applied consistently, and that no undefined values remain. If the chosen standardization gives one variant far greater weight than intended, the resulting components can reflect that weighting. Algebraically correct decomposition cannot repair an inappropriate or inconsistent preprocessing choice.

A frequent mistake is to call an eigenvector \(u_k\) from \(ZZ^{\mathsf T}\) the individual scores without qualification. It is a unit-length direction across individuals; the projection scores are \(d_ku_k\). Another mistake is to compare eigenvalues from matrices divided by different constants as if their magnitudes should agree. Check the matrix definition and divisor first. Finally, a zero eigenvalue is not a direction with a hidden nonzero score: it corresponds to no additional variation in the matrix.

Key takeaway: For \(Z=UDV^{\mathsf T}\), \(ZZ^{\mathsf T}\) and \(Z^{\mathsf T}Z\) share the positive eigenvalues \(d_k^2\). Individual scores are \(Zv_k=d_ku_k\), not just \(u_k\). The scaling used to construct \(Z\) and any divisor used for a covariance-style matrix must be reported consistently.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. If a positive eigenvalue of \(ZZ^{\mathsf T}\) is 9, what is the corresponding singular value, and how are its unit eigenvector and score vector related?
  2. Why does \(Z^{\mathsf T}Z\) have the same positive eigenvalues as \(ZZ^{\mathsf T}\), even though the matrices can have different dimensions?
  3. If every eigenvalue is divided by 5 because the whole Gram matrix is divided by 5, what happens to its eigenvectors and to the proportions of total variation?
  4. A software output gives unit eigenvectors \(u_k\) and eigenvalues \(\lambda_k\) from \(ZZ^{\mathsf T}\). Write the corresponding score vector for a positive eigenvalue.
  5. Why can the sign of a component differ across two correct SVD implementations?

Solutions. (1) The singular value is \(d_k=\sqrt{9}=3\), and the score vector is \(t_k=3u_k\). (2) The SVD gives \(ZZ^{\mathsf T}=UD^2U^{\mathsf T}\) and \(Z^{\mathsf T}Z=VD^2V^{\mathsf T}\), so both have the same positive eigenvalues \(d_k^2\); their dimensions differ because one indexes individuals and the other variants. (3) Eigenvectors are unchanged by multiplication of the matrix by a positive scalar, and all eigenvalues are scaled equally, so their ratios to the total eigenvalue sum are unchanged. (4) \(t_k=\sqrt{\lambda_k}\,u_k\). (5) Reversing the signs of both matching singular vectors leaves the decomposition valid, so the corresponding scores may also have their signs reversed.

Clinical Biostats