Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Spectral Clustering from a Cell Graph

Graph-Based Clustering · Tutorial 249 of 700

Spectral Clustering from a Cell Graph

Construct graph Laplacians, interpret their eigenvectors, and use spectral coordinates to partition a small cell graph while checking assumptions and common failure modes.

Intermediate 10 min read

What You'll Learn

  • Construct the unnormalized and symmetric normalized Laplacians from a weighted cell graph.
  • Explain how Laplacian eigenvalues and eigenvectors reflect connectivity and within-group similarity.
  • Derive the graph-smoothness identity that motivates spectral coordinates.
  • Work through a weak-bridge example and obtain a two-group partition from eigenvector coordinates.
  • Recognize when isolated nodes, disconnected components, or normalization choices affect the result.
  • Distinguish spectral clustering from modularity-based and flow-based community detection.

From a Cell Graph to a Laplacian

A cell graph represents cells as vertices and neighborhood relationships as edges. In a weighted graph, a larger edge weight means a stronger relationship between the two cells. Spectral clustering uses a matrix built from these weights to find coordinates in which graph-connected cells tend to lie near one another. Clustering those coordinates can reveal a partition that is not obvious from the original high-dimensional expression measurements.

Assume the graph is undirected, its edge weights are nonnegative, and there are no self-loops. Write \(W\) for its symmetric weight matrix, so \(W_{ij}=W_{ji}\geq 0\) and \(W_{ii}=0\). The weighted degree of vertex \(i\) is \(d_i=\sum_j W_{ij}\). The degree matrix \(D\) is diagonal, with \(D_{ii}=d_i\).

Definition: The unnormalized graph Laplacian is \(L=D-W\). When every vertex has positive degree, the symmetric normalized Laplacian is \(L_{\mathrm{sym}}=I-D^{-1/2}WD^{-1/2}\). The random-walk Laplacian is \(L_{\mathrm{rw}}=I-D^{-1}W\). These matrices encode the same graph but scale vertex contributions differently.

The unnormalized Laplacian is often useful for understanding the basic spectral idea. The normalized Laplacian adjusts for degree, which can matter when some cells have many strong graph connections and others have few. The inverse degree matrices in the normalized definitions require positive degrees; an isolated vertex has \(d_i=0\), so it must be handled explicitly rather than inserted into these formulas without adjustment.

Worked Example: The Laplacian of a Three-Cell Path

Suppose three hypothetical cells form a path: cell 1 is connected to cell 2 with weight 1, and cell 2 is connected to cell 3 with weight 1. There is no edge between cells 1 and 3. In cell order, the weight and degree matrices are

$$ W= \begin{pmatrix} 0&1&0\\ 1&0&1\\ 0&1&0 \end{pmatrix}, \qquad D= \begin{pmatrix} 1&0&0\\ 0&2&0\\ 0&0&1 \end{pmatrix}. $$

Subtracting \(W\) from \(D\) gives

$$ L=D-W= \begin{pmatrix} 1&-1&0\\ -1&2&-1\\ 0&-1&1 \end{pmatrix}. $$

The eigenvalues are 0, 1, and 3. Corresponding eigenvectors, scaled to have length 1, are \((1,1,1)/\sqrt{3}\), \((1,0,-1)/\sqrt{2}\), and \((1,-2,1)/\sqrt{6}\). The constant vector has eigenvalue 0; the next eigenvector assigns opposite signs to the two endpoints and zero to the middle cell. It varies gradually across the path, rather than changing abruptly across an edge.

Why Low-Eigenvalue Coordinates Reflect Graph Structure

For any real vector \(x\) with one coordinate \(x_i\) per vertex, the Laplacian quadratic form measures how much \(x\) changes across weighted edges. Because \(W\) is symmetric and \(d_i=\sum_j W_{ij}\), expanding \(x^\mathsf{T}(D-W)x\) gives

$$ x^\mathsf{T}Lx =\sum_i d_i x_i^2-\sum_{i,j}W_{ij}x_ix_j =\frac{1}{2}\sum_{i,j}W_{ij}(x_i-x_j)^2. $$

Each term on the right is nonnegative. If two vertices have a large edge weight, assigning them very different coordinates incurs a large penalty. Thus vectors with small Laplacian quadratic form are smooth across strong connections.

The spectral theorem for real symmetric matrices gives an orthonormal set of eigenvectors for \(L\), with real, nonnegative eigenvalues. The smallest eigenvalue is 0, with the constant vector as an eigenvector. A vector for the next-smallest eigenvalue, often called the Fiedler vector, is the smoothest nonconstant direction: it minimizes \(x^\mathsf{T}Lx\) among unit-length vectors orthogonal to the constant vector. Further low-eigenvalue eigenvectors provide additional smooth directions.

Key result: For a graph with \(k\) connected components, the unnormalized Laplacian has exactly \(k\) zero eigenvalues. Its zero-eigenvalue eigenspace consists of vectors that are constant within each component. A small nonzero eigenvalue often indicates that the graph can be divided into groups connected to one another by relatively weak edges.

The last statement is a useful structural clue, not a guarantee that the graph has a uniquely correct clustering. Eigenvectors specify coordinates; a separate step turns the coordinates into labels. For two groups, a threshold on a Fiedler vector can be used. For \(k\) groups, a common approach is to use the first \(k\) eigenvectors as coordinates and apply \(k\)-means to the resulting rows.

Worked Example: Partitioning a Graph With a Weak Bridge

Consider four hypothetical cells arranged in a path. The edges from cell 1 to 2 and cell 3 to 4 each have weight 1, while the bridge from cell 2 to 3 has weight 0.1. This graph is connected, but the bridge is weaker than the two within-pair edges. Its matrices are

$$ W= \begin{pmatrix} 0&1&0&0\\ 1&0&0.1&0\\ 0&0.1&0&1\\ 0&0&1&0 \end{pmatrix}, \qquad D= \begin{pmatrix} 1&0&0&0\\ 0&1.1&0&0\\ 0&0&1.1&0\\ 0&0&0&1 \end{pmatrix}. $$

Therefore,

$$ L= \begin{pmatrix} 1&-1&0&0\\ -1&1.1&-0.1&0\\ 0&-0.1&1.1&-1\\ 0&0&-1&1 \end{pmatrix}. $$

The constant vector has eigenvalue 0. To find a low-eigenvalue direction that changes sign across the bridge, consider a vector of the form \(x=(a,b,-b,-a)^\mathsf{T}\). Multiplication by \(L\) gives first coordinate \(a-b\) and second coordinate \(-a+1.2b\). For \(Lx=\lambda x\), the first coordinate requires \(b=(1-\lambda)a\). Substituting this into the second-coordinate equation gives

$$ \lambda(1-\lambda)=1.2(1-\lambda)-1, \qquad \lambda^2-2.2\lambda+0.2=0. $$

The smaller root is \(\lambda=(2.2-\sqrt{4.04})/2\approx 0.09501\), and \(b/a=1-\lambda\approx0.9050\). Taking \(a=1\), a corresponding eigenvector is approximately \((1,0.9050,-0.9050,-1)^\mathsf{T}\). Its positive coordinates belong to cells 1 and 2, and its negative coordinates belong to cells 3 and 4. Thresholding at zero gives the partition \(\{1,2\}\) and \(\{3,4\}\), which cuts only the weak bridge.

This calculation is appropriate for the stated undirected, nonnegative graph. The eigenvector provides a one-dimensional spectral embedding; the sign split is a simple partitioning rule for this example, not a rule that must be used for every graph.

A Practical Spectral-Clustering Procedure

A common normalized procedure uses the symmetric normalized Laplacian. It is designed to reduce the influence of raw degree differences, but it still requires positive degrees and a choice of the number of groups \(k\). One standard version is:

1
Build the graph matrices.
Use the chosen cell graph to form its symmetric weight matrix \(W\), degree matrix \(D\), and \(L_{\mathrm{sym}}\).
2
Compute low-eigenvalue eigenvectors.
Find eigenvectors associated with the \(k\) smallest eigenvalues of \(L_{\mathrm{sym}}\), including zero eigenvalues when present. Place them as columns of a matrix \(U\).
3
Form spectral coordinates.
Represent each cell by its row in \(U\). In a common normalized variant, divide each nonzero row by its Euclidean length before clustering the rows.
4
Cluster the rows.
Apply \(k\)-means with \(k\) groups to the spectral coordinates. The resulting labels partition the cells; they are not, by themselves, biological cell-type annotations.

The row normalization in step 3 is part of a widely used normalized spectral-clustering variant, not a universal requirement for every spectral method. The unnormalized approach instead uses eigenvectors of \(L\), while normalized alternatives use \(L_{\mathrm{sym}}\) or \(L_{\mathrm{rw}}\). Their coordinates and sensitivity to degree can differ, so the Laplacian and embedding choices should be reported rather than treated as interchangeable implementation details.

Worked Example: Two Disconnected Cell Pairs

Suppose four hypothetical cells form two disconnected pairs. Cells 1 and 2 have edge weight 2, while cells 3 and 4 have edge weight 0.5. There are no edges between the pairs. Then \(D\) has diagonal entries \(2,2,0.5,0.5\). The unnormalized Laplacian is block diagonal:

$$ L= \begin{pmatrix} 2&-2&0&0\\ -2&2&0&0\\ 0&0&0.5&-0.5\\ 0&0&-0.5&0.5 \end{pmatrix}. $$

Each pair contributes one zero eigenvalue: its component-constant vector has zero Laplacian energy. Thus the graph has two zero eigenvalues, and choosing \(k=2\) yields a spectral subspace that distinguishes the two connected components. A clustering of suitable coordinates can assign cells 1 and 2 together and cells 3 and 4 together. Within either component, the vector that contrasts the two vertices has a positive eigenvalue, so it is not part of the zero-eigenvalue space.

For this graph, \(D^{-1/2}WD^{-1/2}\) has off-diagonal entry 1 within each pair: for the first pair, \(2/\sqrt{2\cdot2}=1\); for the second, \(0.5/\sqrt{0.5\cdot0.5}=1\). Consequently, each block of \(L_{\mathrm{sym}}\) is \(\begin{pmatrix}1&-1\\-1&1\end{pmatrix}\), again with one zero eigenvalue per component. This example shows why normalized and unnormalized Laplacians can encode the same disconnected components even when their edge weights and degrees differ.

Diagnostics, Alternatives, and Limitations

Before interpreting a spectral partition, check the graph and the spectral calculation. Confirm that weights are nonnegative and symmetric, that the degree distribution is as expected, and that there are no unhandled isolated vertices. Inspect the smallest eigenvalues: several exact or near-zero values can indicate disconnected or weakly connected regions. Check whether the proposed partition cuts a few strong edges or instead separates many strongly connected neighbors. If small eigenvalues are tightly clustered, the corresponding eigenvectors may not define a stable orientation on their own; different numerical bases for the same eigenspace can produce different coordinates.

A common mistake is to treat any low-eigenvalue eigenvector as a set of cluster labels. An eigenvector gives a continuous coordinate, and its sign or magnitude is not automatically a categorical assignment. The correction is to state the embedding and partitioning step explicitly—for example, thresholding a Fiedler vector for a two-way split or clustering rows of a selected eigenvector matrix. Also avoid interpreting a spectral cluster as a proven cell type: the result depends on the graph construction, edge weights, chosen \(k\), Laplacian, and downstream partitioning.

Spectral clustering differs from the community-detection methods already encountered in this unit. Modularity-based methods seek partitions that score well under a comparison with a degree-based random-graph reference, while Infomap uses the coding cost of random walks. Spectral clustering instead derives low-dimensional coordinates from eigenvectors of a Laplacian, then partitions those coordinates. All three approaches can use a cell graph, but their objectives and outputs need not agree. Spectral methods can be computationally demanding for very large graphs because they require eigenvectors, and their results may depend on the selected number of groups and the choice between normalized and unnormalized coordinates.

The central justification is the smoothness identity: strong edges penalize large coordinate differences, so low-eigenvalue directions tend to preserve strongly connected neighborhoods. This explains why spectral coordinates can expose weak connections between groups. It does not establish that every graph has a meaningful discrete partition; the graph must represent relevant cell relationships, and the resulting groups still require appropriate scientific interpretation.

Check Your Understanding

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

  1. For an undirected weighted graph, why is \(x^\mathsf{T}Lx\) nonnegative?
  2. A graph has three connected components. How many zero eigenvalues does its unnormalized Laplacian have?
  3. In a two-group spectral embedding, what does a Fiedler vector provide, and what additional step turns it into labels?
  4. Why can an isolated vertex not be inserted directly into the usual formula for \(L_{\mathrm{sym}}\)?
  5. What is one reason to consider a normalized Laplacian rather than the unnormalized Laplacian?

Solutions. (1) The identity \(x^\mathsf{T}Lx=\frac{1}{2}\sum_{i,j}W_{ij}(x_i-x_j)^2\) is a sum of nonnegative terms because \(W_{ij}\geq0\). (2) It has three zero eigenvalues, one for each connected component. (3) It provides a continuous coordinate that tends to vary smoothly across strong edges; a threshold or another explicit partitioning rule must convert coordinates into group labels. (4) Its degree is zero, so \(D^{-1/2}\) is undefined at that vertex; the isolate must be handled separately or the graph treatment revised. (5) Normalization adjusts for degree differences, which can otherwise influence the spectral coordinates and partition.

Clinical Biostats