Tutorials › Multi-Omics Data Integration › Nonnegative Matrix Factorization as a Data Model

Non-Negative Matrix Factorization · Tutorial 184 of 597

Nonnegative Matrix Factorization as a Data Model

You will learn to read the dimensions and nonnegativity constraints in \(X \approx WH\), interpret its factors, and recognize when preprocessing makes the model inappropriate.

Advanced 11 min read

What You'll Learn

  • Set up the feature-by-sample data matrix and the dimensions of both factor matrices.
  • Interpret columns of W as feature profiles and columns of H as sample-specific component abundances.
  • Derive the entry-wise reconstruction from matrix multiplication.
  • Check whether measurements and preprocessing preserve the nonnegative data domain.
  • Distinguish approximate reconstructions from observed values and identify useful diagnostics.
  • Compare the NMF data model with centered PCA-based representations.

Introduction

Multi-omics measurements often contain nonnegative quantities: counts, intensities, concentrations, or nonnegative scores. Such data can be represented as combinations of a smaller number of nonnegative patterns. Nonnegative matrix factorization (NMF) expresses this idea by approximating a data matrix with the product of two smaller matrices. The product links two kinds of quantities: which features characterize each component, and how strongly each component contributes to each sample.

The interpretation depends on how the data matrix is arranged and measured. A clear convention is therefore essential: rows will represent features and columns will represent samples. With that convention, the factor matrices have direct, distinct roles.

Definition: Let \(X \in \mathbb{R}_{\geq 0}^{m \times n}\) be a matrix of nonnegative measurements, with \(m\) features in rows and \(n\) samples in columns. An NMF representation with \(r\) components is \(X \approx WH\), where \(W \in \mathbb{R}_{\geq 0}^{m \times r}\) and \(H \in \mathbb{R}_{\geq 0}^{r \times n}\). The \(k\)th column of \(W\) is the feature profile for component \(k\); the \(j\)th column of \(H\) gives the component abundances for sample \(j\). The approximation sign means that the product is intended to represent, but need not equal, the observed matrix.

Dimensions and the Entry-Wise Model

The dimensions must agree for the product \(WH\) to be defined. The \(r\) columns of \(W\) correspond, in order, to the \(r\) rows of \(H\). The resulting product has \(m\) rows and \(n\) columns, just like \(X\). Thus each reconstructed entry corresponds to a particular feature in a particular sample.

$$ (m \times r)(r \times n)=m \times n $$

Matrix multiplication gives a precise expression for the model. For feature \(i\) and sample \(j\), the fitted or reconstructed value is the sum of the component-specific contributions for that feature and sample.

$$ \widehat{x}_{ij}=(WH)_{ij}=\sum_{k=1}^{r} W_{ik}H_{kj}, \qquad x_{ij}\approx\widehat{x}_{ij}. $$

Here, \(W_{ik}\) describes the contribution of feature \(i\) to the profile of component \(k\), while \(H_{kj}\) describes the abundance of component \(k\) in sample \(j\). Their product is that component's contribution to the reconstructed measurement for feature \(i\), sample \(j\). Adding those contributions across components gives \(\widehat{x}_{ij}\). This is an additive data model: a feature value is represented as a sum, not as a choice of just one component.

The dimensions also indicate how to read the factors. A column of \(W\) has one entry per feature, so it describes a pattern across features. A column of \(H\) has one entry per component, so it describes a sample across components. Confusing these orientations can produce a plausible-looking product with the wrong scientific interpretation.

Worked Example: Checking Dimensions and Multiplying the Factors

Consider a hypothetical data set with three features and three samples, represented by the following factors. All values are nonnegative.

$$ W= \begin{bmatrix} 4&0\\ 2&1\\ 0&3 \end{bmatrix}, \qquad H= \begin{bmatrix} 2&1&0\\ 0&1&2 \end{bmatrix}. $$

There are \(m=3\) features, \(n=3\) samples, and \(r=2\) components. The dimensions are \(W:3 \times 2\) and \(H:2 \times 3\), so \(WH\) has dimension \(3 \times 3\), as required for comparison with the data.

For example, the reconstructed value for feature 2 in sample 2 is \(\widehat{x}_{22}=W_{21}H_{12}+W_{22}H_{22}=(2)(1)+(1)(1)=3\). Multiplying all rows and columns gives

$$ WH= \begin{bmatrix} (4)(2)+(0)(0)&(4)(1)+(0)(1)&(4)(0)+(0)(2)\\ (2)(2)+(1)(0)&(2)(1)+(1)(1)&(2)(0)+(1)(2)\\ (0)(2)+(3)(0)&(0)(1)+(3)(1)&(0)(0)+(3)(2) \end{bmatrix} = \begin{bmatrix} 8&4&0\\ 4&3&2\\ 0&3&6 \end{bmatrix}. $$

The first column of \(W\), \((4,2,0)^\mathsf{T}\), is the feature profile for component 1; the second, \((0,1,3)^\mathsf{T}\), is the profile for component 2. Sample 2 has abundance vector \((1,1)^\mathsf{T}\), so both components contribute to its reconstructed measurements. If this product were used as an exact representation, the observed data matrix would equal the product shown. In a fitted approximate representation, the observed entries may differ.

What Nonnegativity Says About the Model

The constraints \(X \geq 0\), \(W \geq 0\), and \(H \geq 0\) apply entry by entry. If \(W\) and \(H\) are nonnegative, then every component contribution \(W_{ik}H_{kj}\) is nonnegative, and their sum \(\widehat{x}_{ij}\) is nonnegative. This fits a model in which components add to a measured quantity without subtracting one component from another.

That statement does not imply that the residuals are nonnegative. Define the residual matrix \(E=X-WH\); its entries can be positive, negative, or zero. A positive residual means the observed measurement exceeds its reconstruction, and a negative residual means the reconstruction exceeds the observation. Nonnegative factors restrict the representation, not the direction of its errors.

The data domain is an assumption to check, not a cosmetic preference. A measurement matrix with negative entries cannot be represented by a product of nonnegative factors, because such a product is nonnegative entry by entry. Centering features by subtracting their means commonly creates negative values, so the centered matrix is no longer directly within the basic NMF data domain. Similarly, preprocessing should not be selected merely because it is familiar from another analysis.

Worked Example: Interpreting Profiles, Abundances, and Residuals

Suppose a hypothetical experiment records three nonnegative feature measurements in two samples. A proposed factorization is

$$ W= \begin{bmatrix} 1&0\\ 0.5&1\\ 0&0.75 \end{bmatrix}, \qquad H= \begin{bmatrix} 8&3\\ 2&6 \end{bmatrix}. $$

The dimensions are \(3 \times 2\) and \(2 \times 2\), giving a reconstructed \(3 \times 2\) matrix. The first profile assigns weights \(1, 0.5, 0\) to the three features; the second assigns \(0, 1, 0.75\). The abundance vectors are \((8,2)^\mathsf{T}\) for sample 1 and \((3,6)^\mathsf{T}\) for sample 2.

For feature 2 in sample 1, component 1 contributes \((0.5)(8)=4\), and component 2 contributes \((1)(2)=2\). The reconstructed value is therefore \(4+2=6\). Computing the other entries gives

$$ WH= \begin{bmatrix} (1)(8)+(0)(2)&(1)(3)+(0)(6)\\ (0.5)(8)+(1)(2)&(0.5)(3)+(1)(6)\\ (0)(8)+(0.75)(2)&(0)(3)+(0.75)(6) \end{bmatrix} = \begin{bmatrix} 8&3\\ 6&7.5\\ 1.5&4.5 \end{bmatrix}. $$

Suppose the hypothetical observed matrix is \(X=\begin{bmatrix}10&4\\5&8\\2&6\end{bmatrix}\). Then the residual matrix, using observed minus reconstructed values, is

$$ E=X-WH= \begin{bmatrix} 10-8&4-3\\ 5-6&8-7.5\\ 2-1.5&6-4.5 \end{bmatrix} = \begin{bmatrix} 2&1\\ -1&0.5\\ 0.5&1.5 \end{bmatrix}. $$

For feature 2 in sample 1, the reconstruction is 6 units while the observed measurement is 5 units, so the residual is \(-1\) measurement unit. The example illustrates why a fitted value should not be reported as though it were the observation, and why nonnegative factors do not force residuals to have one sign.

Assumptions, Units, and Preprocessing

The basic model is most interpretable when features and samples have been arranged consistently, measurements are nonnegative, and additive combinations of feature profiles are scientifically meaningful as an approximation. These conditions do not guarantee that NMF will recover uniquely defined biological entities, or that each component corresponds to a single biological mechanism. The factors summarize structure under the chosen data representation; interpretation still requires scientific judgment.

Units deserve attention. If \(X\) contains counts, then its reconstructed values are on the count scale. If it contains intensities, the reconstruction is on that intensity scale. In the product \(W_{ik}H_{kj}\), the units are determined jointly by the factor conventions: one factor's scale and the other's reciprocal scale can describe the same product. Therefore, numerical entries of a factor should not be given standalone physical units or interpreted as absolute abundance without specifying how the factors were scaled.

A transformation must be checked against the nonnegative constraint. The ordinary logarithm does not generally preserve nonnegativity: for example, \(\ln(0.5)\approx-0.6931\), and \(\ln(1)=0\). It produces nonnegative values only for inputs at least 1. A transformation such as \(\ln(1+x)\) is positive when \(x>0\) and equals zero at \(x=0\), but it changes the scale and the meaning of additive combinations. A model for transformed values is not automatically a model for the original measurements.

Worked Example: Checking a Log Transformation

Consider the hypothetical nonnegative matrix

$$ X= \begin{bmatrix} 0&0.5\\ 1&4 \end{bmatrix}. $$

Applying the ordinary natural logarithm entry by entry gives \(\ln(0)\), which is undefined, and \(\ln(0.5)\approx-0.6931\), which is negative. The other two entries are \(\ln(1)=0\) and \(\ln(4)\approx1.3863\). Thus the ordinary log-transformed matrix is not a nonnegative data matrix, even if one uses a convention to handle the zero.

Instead, applying \(\ln(1+x)\) gives

$$ \begin{bmatrix} \ln(1+0)&\ln(1+0.5)\\ \ln(1+1)&\ln(1+4) \end{bmatrix} \approx \begin{bmatrix} 0&0.4055\\ 0.6931&1.6094 \end{bmatrix}. $$

These transformed values are nonnegative, so they meet the domain condition for basic NMF. However, the fitted component contributions now add on the \(\ln(1+x)\) scale, not on the original scale of \(X\). Choosing this transformation is a modeling decision, not a way to preserve the original additive interpretation.

Diagnostics and Alternative Representations

Several checks help reveal when the data model is being used inappropriately. First, verify the dimensions and orientation before fitting: rows should correspond to the defined features and columns to the defined samples, and the dimensions of \(W\), \(H\), and \(WH\) should match that convention. Second, inspect the input for negative values, missing values, and zeros. A missing measurement is not automatically a measured zero; treating it as zero changes the data being represented. Third, compare observed entries with reconstructed entries and inspect residuals by feature and sample. Large or systematic residual patterns indicate that the chosen representation may not capture important structure.

Also check whether component profiles are interpretable in context and whether their sample abundances vary in a way that is credible. A nonnegative factorization can be mathematically valid while its components are unstable or scientifically unhelpful. Examine whether conclusions depend on preprocessing choices, feature selection, or the chosen number of components. These checks diagnose the adequacy and interpretability of the representation; they do not by themselves prove that a component is a real biological source.

NMF differs from centered PCA-based representations, including methods discussed in the earlier material on Multiple Factor Analysis and joint PCA. PCA represents deviations around feature means, and its loadings and scores can be negative. NMF instead uses nonnegative profiles and abundances to represent nonnegative measurements as additive contributions. Centering before NMF can therefore defeat its basic domain constraint. Neither representation is universally preferable: the appropriate choice depends on the data scale and the scientific meaning of the desired components.

Key takeaway: In \(X \approx WH\), rows of \(X\) and \(W\) index features, columns of \(X\) and \(H\) index samples, and the shared dimension indexes components. The columns of \(W\) are feature profiles; the columns of \(H\) are sample-specific component abundances. Both factors are constrained to be nonnegative, so data handling must preserve the meaning and domain of the measurements.

Common Mistakes and Limitations

  • Reversing the factor interpretation. With features in rows of \(X\), the columns of \(W\), not \(H\), are feature profiles. The columns of \(H\) describe components within samples.
  • Assuming the factors must reproduce every entry exactly. The model is generally approximate. Compare \(X\) with \(WH\), and distinguish observations from their reconstructions.
  • Assuming all residuals are nonnegative. The factors and reconstruction are nonnegative, but observed-minus-reconstructed residuals can have either sign.
  • Logging nonnegative data without checking the result. The ordinary logarithm of values between 0 and 1 is negative, and zero has no ordinary logarithm. Check the transformed values and the interpretation of the new scale.
  • Treating any fitted component as a biological entity. A component is a pattern in a chosen representation. Its biological interpretation requires evidence beyond the factorization itself.

The basic model also has limits: its additive, nonnegative representation may not suit centered data, measurements with meaningful negative values, or relationships that are not well described by additive component contributions. A good fit alone does not establish a causal mechanism or uniquely identify biological sources.

Check Your Understanding

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

  1. If \(X\) has 12 features and 7 samples and a model uses 3 components, what are the dimensions of \(W\), \(H\), and \(WH\)?
  2. For a particular feature and sample, \(W_{i1}=2\), \(H_{1j}=3\), \(W_{i2}=0.5\), and \(H_{2j}=4\). What is the reconstructed entry when there are two components?
  3. Can a product of nonnegative \(W\) and \(H\) represent a matrix with an entry of \(-2\)? Explain.
  4. Does the ordinary natural logarithm preserve nonnegativity for every positive input? Give a counterexample.
  5. If the reconstructed value is 7 units and the observed value is 5 units, what is the residual under the convention \(E=X-WH\), and what does its sign mean?

Solutions. (1) \(W\) is \(12 \times 3\), \(H\) is \(3 \times 7\), and \(WH\) is \(12 \times 7\). (2) The reconstructed entry is \((2)(3)+(0.5)(4)=6+2=8\). (3) No. Every product entry is a sum of nonnegative terms, so it is nonnegative and cannot equal \(-2\). (4) No: \(\ln(0.5)\approx-0.6931\), which is negative. (5) The residual is \(5-7=-2\) units; its negative sign means the reconstruction is 2 units greater than the observation.

Clinical Biostats