Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Handling Zeros in Median-Ratio Size-Factor Estimation

Normalization of Sparse Counts · Tutorial 83 of 700

Handling Zeros in Median-Ratio Size-Factor Estimation

Learn how to handle zero counts in median-ratio normalization, choose between reference-gene and positive-count strategies, and diagnose when sparse data make the resulting factors unreliable.

Intermediate 12 min read

What You'll Learn

  • Explain why a zero in a gene’s counts makes its ordinary geometric mean zero and its count-to-reference ratio undefined.
  • Estimate relative size factors using a set of genes that are positive in every cell.
  • Construct positive-count geometric means and calculate median ratios when the full matrix is sparse.
  • Distinguish including zero ratios from taking medians only over positive ratios.
  • Center estimated factors so their geometric mean is one, and interpret them as relative exposures.
  • Recognize when too few usable genes or widespread zeros make median-ratio factors unstable.

Why Zeros Complicate Median-Ratio Normalization

Median-ratio normalization compares each cell’s gene counts with a reference value for each gene. In the ordinary construction, that reference is the gene’s geometric mean across cells. This works when every count for a gene is positive. In a sparse single-cell matrix, however, a single zero makes the product of that gene’s counts zero, so its geometric mean is zero. Dividing a zero or positive count by that reference is undefined.

This is a computational problem in the reference construction, not evidence that a zero count should be replaced by a small number. Adding a pseudocount changes the ratios and can make the result depend strongly on the arbitrary value chosen. Two practical strategies are to construct references from a carefully chosen set of genes positive in every cell, or to calculate gene references using only their positive counts. These strategies make different compromises and neither automatically resolves every difficulty caused by sparsity.

Definition: Let \(Y_{ij}\) be the observed count for gene \(i\) in cell \(j\), with \(i=1,\ldots,G\) and \(j=1,\ldots,m\). A size factor \(s_j\) is a positive multiplicative exposure adjustment for cell \(j\). Median-ratio methods estimate relative size factors by comparing counts with gene-specific reference values and taking a median across genes. Because a common multiplier cannot be identified from endogenous counts alone, the estimated factors are conventionally centered to have geometric mean one.

A useful working model for a set of stable reference genes is that their expected counts satisfy \(E(Y_{ij})=s_jq_i\), where \(q_i>0\) is the same across the cells being compared. This model expresses the assumption that these genes differ in their average abundance but not systematically in their biological expression across cells. The factors are identifiable only up to a common multiplier: multiplying every \(s_j\) by a constant and dividing every \(q_i\) by that constant leaves the expected counts unchanged.

What the Ordinary Geometric-Mean Reference Estimates

If a gene has positive counts in all \(m\) cells, its ordinary geometric-mean reference is

$$ g_i=\left(\prod_{j=1}^{m}Y_{ij}\right)^{1/m} =\exp\left(\frac{1}{m}\sum_{j=1}^{m}\log Y_{ij}\right). $$

Its ratio for cell \(j\) is \(R_{ij}=Y_{ij}/g_i\). To see what this ratio targets under the stable-gene model, first consider expected counts rather than noisy observed counts. Their across-cell geometric mean is \(q_i(\prod_{k=1}^{m}s_k)^{1/m}\), so the ratio of the expected count in cell \(j\) to that reference is

$$ \frac{s_jq_i}{q_i(\prod_{k=1}^{m}s_k)^{1/m}} =\frac{s_j}{(\prod_{k=1}^{m}s_k)^{1/m}}. $$

Thus the gene-specific abundance \(q_i\) cancels. If the stable genes are representative in the sense that their gene-specific departures do not shift the median, the median ratio estimates the cell’s size factor relative to the geometric mean of the cell factors, not the uncentered \(s_j\). In log terms, the target is \(\log s_j-m^{-1}\sum_k\log s_k\). This qualification matters: the ordinary reference contains the average exposure across cells.

Key result: Median ratios from ordinary geometric-mean references estimate size factors up to a common multiplicative constant. Dividing the estimates by their geometric mean gives factors whose geometric mean is one. These are relative exposure corrections, not absolute measurements of RNA per cell.

The calculation above describes the model’s expected counts. Actual counts are random, and a ratio of observed counts is not generally equal to a ratio of expected counts. The method therefore relies on enough informative, sufficiently stable genes for the median to resist sampling variation and gene-specific departures. It also requires positive observations for every gene used to form an ordinary geometric mean.

Worked Example: Centering Ordinary Median Ratios

Suppose three hypothetical stable genes have counts \((100,200,100)\), \((50,100,50)\), and \((80,160,80)\) in three cells. Every entry is positive, so all three genes can contribute to ordinary geometric-mean references.

For the first gene, \(g_1=(100\cdot200\cdot100)^{1/3}=125.992\). Its ratios are approximately \((0.7937,1.5874,0.7937)\). The other two genes are scaled versions of the same pattern, so their ratios are also approximately \((0.7937,1.5874,0.7937)\). Taking the median across the three genes gives raw cell factors \((0.7937,1.5874,0.7937)\).

Their geometric mean is \((0.7937\cdot1.5874\cdot0.7937)^{1/3}=1.000\), up to rounding, so centering leaves them unchanged. The middle cell’s estimated relative factor is about twice that of either other cell. The factors are relative: they correspond to exposure values proportional to \((1,2,1)\), centered to geometric mean one. The data do not establish the absolute exposure scale.

Strategy 1: Use a Reference-Gene Set That Is Positive Throughout

A direct way to avoid undefined references is to define a set \(\mathcal{R}\) of genes with positive counts in every cell used for estimation, calculate ordinary geometric means only for those genes, and take each cell’s median ratio across \(\mathcal{R}\). This works mathematically because every ratio has a positive denominator. The important statistical question is whether the selected genes provide a suitable reference.

The set should contain enough genes to make its median reasonably stable, and its members should not share a systematic expression shift across cells. Selecting genes merely because they happen to be positive everywhere does not guarantee stability: in a small data set, that selection can favor highly expressed genes, while in a large, sparse data set there may be very few such genes. If reference genes are selected using the same data, it is useful to report the selection rule and check whether a modest change to the set substantially changes the factors.

Worked Example: Estimating Factors From Two Positive Reference Genes

Consider a hypothetical count matrix with three cells. Two candidate reference genes have counts \((12,24,12)\) and \((30,60,30)\). A third gene has counts \((0,5,10)\), so it cannot have an ordinary geometric-mean reference across all three cells. Suppose the two positive genes are justified as a stable reference set for this illustration.

The first reference is \(g_1=(12\cdot24\cdot12)^{1/3}=15.119\), giving ratios \((0.7937,1.5874,0.7937)\). The second reference is \(g_2=(30\cdot60\cdot30)^{1/3}=37.796\), giving the same ratios. The median across the two reference genes is therefore \((0.7937,1.5874,0.7937)\). Its geometric mean is one, so no further change is needed beyond rounding.

The third gene is excluded from this calculation because its ordinary reference would be zero, not because its zero is an error. This example also exposes a limitation: two genes give a fragile median. In a real analysis, the stability and number of reference genes would need careful evaluation; arithmetic validity alone does not justify the biological reference assumption.

Strategy 2: Build References From Positive Counts

A positive-count strategy defines a gene reference from only that gene’s positive observed counts. Let \(P_i=\{j:Y_{ij}>0\}\) and \(n_i^+=|P_i|\). For a gene observed at least once, define

$$ g_i^+=\exp\left(\frac{1}{n_i^+}\sum_{j\in P_i}\log Y_{ij}\right). $$

This quantity is positive even when the gene has zeros in some cells. One common implementation then divides every cell’s count for that gene by \(g_i^+\), leaving a zero count as a zero ratio, and takes the median ratios across genes for each cell. A gene that is zero in every cell has no positive-count reference and is omitted. The resulting cell medians are centered by dividing by their geometric mean, provided the medians are all positive.

A different implementation takes the median only among genes with positive counts in each particular cell. This avoids zero ratios in that cell’s median, but changes the contributing gene set from cell to cell. The distinction should be stated explicitly: these are not identical calculations. In either version, the positive-only reference is not an ordinary geometric mean with zeros harmlessly removed. It is a different reference, and its behavior can depend on which cells detected each gene.

In particular, positive observations are selected observations. If counts are noisy, the positive counts for a rarely detected gene tend to omit low or undetected observations. The positive-only geometric mean can therefore be higher than a reference that represented all underlying expected counts. Also, if most genes are zero in a cell and zero ratios are included, its median ratio may be zero; a zero median cannot be used as a positive size factor or repaired by geometric-mean centering. These methods require enough nonzero information in each cell.

Worked Example: Positive-Count References With Zeros Retained as Ratios

Use this hypothetical matrix, with rows as genes and columns as cells:

GeneCell 1Cell 2Cell 3
A10200
B01020
C51010
D008

For gene A, \(g_A^+=(10\cdot20)^{1/2}=14.142\), giving ratios \((0.7071,1.4142,0)\). Gene B has the same positive-count reference, \(g_B^+=14.142\), and ratios \((0,0.7071,1.4142)\). For gene C, \(g_C^+=(5\cdot10\cdot10)^{1/3}=7.937\), giving approximately \((0.6300,1.2599,1.2599)\). For gene D, \(g_D^+=8\), giving \((0,0,1)\).

Taking the median of all four ratios in each cell, including zeros, gives Cell 1: the average of 0 and 0.6300, or 0.3150; Cell 2: the average of 0.7071 and 1.2599, or 0.9835; and Cell 3: the average of 1 and 1.2599, or 1.130. The geometric mean of these medians is approximately \((0.3150\cdot0.9835\cdot1.130)^{1/3}=0.7048\). Dividing by it gives centered factors approximately \((0.447,1.396,1.603)\).

These numbers demonstrate the calculation, not a claim that the factors recover a known biological truth. In particular, the small matrix has only four genes, and Cell 1’s median is strongly affected by two zero ratios. A larger set of credible genes and diagnostics would be needed before interpreting such estimates.

Choosing and Checking a Zero-Handling Strategy

The strategies answer different practical constraints. An all-positive reference-gene set keeps the ordinary geometric-mean definition, but may discard most genes and can select an unrepresentative subset. The positive-count construction can use genes that are not detected in every cell, but changes the reference definition and can be sensitive to detection patterns. Neither strategy makes zeros disappear, and neither guarantees that the median is informative.

StrategyReference requirementMain advantageMain concern
All-positive reference genesEvery contributing gene is positive in every cellUses ordinary geometric means and avoids zero denominatorsMay leave too few or biologically unrepresentative genes
Positive-count referencesEach contributing gene is positive in at least one cellCan retain genes with some zero observationsReference depends on detection pattern; zero ratios can dominate a cell median
Pseudocount before geometric meansAdds a chosen constant to countsProduces positive inputs by constructionChanges the data-dependent ratios; results can depend on the arbitrary constant

A practical diagnostic sequence is to check the calculation and then its stability. Confirm that every included reference is positive where required, that no cell has an undefined or zero median factor, and that all final factors are finite and positive. Record how many genes contribute to each cell’s median. Compare factors under reasonable alternative reference sets or filtering thresholds. Large changes, very few contributing genes, or many zero ratios signal that the estimates may be driven more by sparsity and selection than by a common exposure correction.

It is also useful to inspect whether candidate reference genes show a consistent shift across cells. If the majority of genes used in a median move together for biological reasons, their common change can be mistaken for a change in exposure. That is a limitation of endogenous size factors, not a zero-specific issue. Total-count scaling is a simple alternative, but it can be distorted when a small number of highly abundant genes dominate the total. TMM is another normalization approach based on trimmed and weighted log ratios; its construction is a separate alternative rather than a zero-filling rule for geometric means.

Common Mistakes and Limits

  • Computing an ordinary geometric mean when a gene has a zero. The product is zero and the count-to-reference ratio is undefined. Exclude that gene from the ordinary reference calculation or use a clearly specified positive-count strategy.
  • Adding a pseudocount without checking its impact. A constant makes the arithmetic possible but changes the ratios, especially for low counts. It is not a neutral substitute for a zero-handling method.
  • Calling raw median ratios the uncentered size factors. Ordinary geometric-mean references contain the across-cell geometric mean exposure. The raw ratios estimate relative factors up to a common constant; centering makes their geometric mean one.
  • Assuming positive-only references are unbiased because zeros were omitted. Detection determines which observations enter each reference, and that selection can alter the reference. Assess sensitivity to detection patterns and gene filtering.
  • Treating successful computation as evidence of validity. Finite factors do not establish that the genes used are stable, that enough informative genes contributed, or that exposure is separable from biological shifts.

These methods estimate relative factors under assumptions about the genes informing the median. They do not determine whether a zero represents a biological gene-off state or non-detection, and they do not estimate absolute RNA content per cell. Their role is narrower: to construct a usable relative exposure correction from a sparse count matrix while making the zero-handling rule and its consequences explicit.

Check Your Understanding

Answer each question, then compare with the brief solutions below.

  1. A gene has counts \((4,0,9)\) across three cells. Why can it not have an ordinary geometric-mean reference for all three cells?
  2. For positive counts \((2,8)\) and a zero in a third cell, calculate the positive-count geometric mean and the three count-to-reference ratios.
  3. Why do ordinary median ratios estimate factors relative to a common scale rather than the uncentered \(s_j\)?
  4. In a positive-count method that includes zero ratios, what problem arises if at least half of the ratios in a cell are zero?
  5. Name one advantage and one limitation of an all-positive reference-gene set compared with positive-count references.

Solutions. (1) The product includes zero, so the ordinary geometric mean is zero and division by it is undefined. (2) The positive-count reference is \((2\cdot8)^{1/2}=4\); the ratios are \(2/4=0.5\), \(8/4=2\), and \(0/4=0\). (3) Each ordinary reference includes the across-cell geometric mean exposure, so the ratios target \(s_j/(\prod_k s_k)^{1/m}\); centering expresses estimates on a geometric-mean-one scale. (4) The median can be zero, which is not a valid positive size factor and cannot be used in geometric-mean centering. (5) It preserves ordinary geometric means and avoids zero denominators, but may leave too few or unrepresentative genes; positive-count references use more genes with some zeros but depend on detection patterns.

Clinical Biostats