Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Choosing the Expression Scale for Variability Modeling

Highly Variable Genes and Feature Selection · Tutorial 117 of 700

Choosing the Expression Scale for Variability Modeling

Learn how library-size differences and nonlinear transformations alter gene-variability rankings, and how to diagnose whether a chosen expression scale is appropriate.

Intermediate 12 min read

What You'll Learn

  • Calculate sample variance on raw, normalized, and log-normalized expression values.
  • Explain why library-size differences can make raw-count rankings misleading.
  • Determine how log transformation changes the influence of large observations.
  • Diagnose scale problems using library-size associations and mean-variance patterns.
  • Compare direct expression-scale rankings with variance-adjusted alternatives.

Why the Expression Scale Changes the Ranking

A gene can appear highly variable because its expression differs across cells, because the cells have different sequencing depths, or because the chosen scale gives unusual weight to some observations. These possibilities are not interchangeable. A ranking based on raw counts answers a different question from one based on normalized counts or log-normalized values.

The goal here is not to declare one scale universally best. It is to identify what each scale measures, check whether its assumptions are plausible, and recognize when library-size differences or the transformation itself dominate the ranking. The earlier material on Pearson residuals provides another way to construct variance-adjusted features; the focus here is how expression-scale choice changes variability summaries.

Definition: Let \(C_{ig}\) be the observed count for gene \(g\) in cell \(i\). A normalized value can be written \(Y_{ig}=C_{ig}/s_i\), where \(s_i\) is the cell's normalization factor. A log-normalized value is often \(Z_{ig}=\ln(1+Y_{ig})\). For any one gene, its sample variance on a given scale is the sum of squared deviations from that scale's sample mean, divided by \(n-1\), where \(n\) is the number of cells.
$$ s_g^2=\frac{1}{n-1}\sum_{i=1}^{n}(X_{ig}-\bar X_g)^2 $$

Here \(X_{ig}\) denotes the values for gene \(g\) on whichever scale is being assessed. The formula is the same on each scale; what changes is the set of values being summarized. A variance has squared expression units, so a raw-count variance, a normalized-count variance, and a log-scale variance are not numerically interchangeable.

What Each Scale Emphasizes

Raw counts retain the observed sampling scale. When one cell has greater library depth, many genes can have larger counts in that cell even if their underlying relative expression is unchanged. Consequently, raw-count variability can partly measure depth variation rather than gene-specific differences. Raw counts are most interpretable for variability comparisons when exposure is sufficiently comparable across cells, or when the analysis explicitly accounts for exposure.

Normalized counts adjust for estimated differences in library size or other modeled exposure. They are more comparable across cells if the normalization factors capture the relevant technical differences and do not remove biological variation of interest. Normalization does not, by itself, make variance independent of the mean: genes with larger average expression may still have larger variance. Mean-variance adjustment, dispersion approaches, and model-based residual features address that issue in different ways.

Log-normalization compresses large values. It often makes a broad range of expression values easier to inspect and reduces the leverage of a few large observations. But the result is a new scale, not a guarantee of constant variance. The pseudocount in \(\ln(1+Y)\) also matters most near zero; two small normalized values can be affected differently from two large ones.

A Short Justification: Linear and Nonlinear Transformations

The effect of a transformation on variance can be shown directly. If \(W_i=a+bX_i\), then \(\bar W=a+b\bar X\), so every centered value is \(W_i-\bar W=b(X_i-\bar X)\). Squaring and summing gives the exact relationship below.

$$ s_W^2=\frac{1}{n-1}\sum_{i=1}^{n}b^2(X_i-\bar X)^2=b^2s_X^2 $$

Thus an additive shift does not change variance, and a constant rescaling multiplies variance by the square of the scale factor. Log-normalization is nonlinear, so there is no corresponding fixed multiplier. For nonnegative \(x\), the derivative of \(\ln(1+x)\) is \(1/(1+x)\), which decreases as \(x\) grows. This means that an equal-sized increase in expression produces a smaller change on the log scale at higher expression. The transformation can therefore change both the magnitude and the ordering of variances across genes.

Worked Example: Library Depth Reverses a Two-Gene Ranking

Consider four hypothetical cells with normalization factors \(s_i=(1,2,4,8)\). Suppose two genes have raw counts \(A=(2,4,8,16)\) and \(B=(0,2,4,8)\). Assume, for this illustration, that the factors adequately represent depth differences and that no other cell-level differences affect these values.

Raw counts. For gene A, the mean is \(7.5\), and its sample variance is \( \{(2-7.5)^2+(4-7.5)^2+(8-7.5)^2+(16-7.5)^2\}/3=115/3=38.33 \) squared counts. For gene B, the mean is \(3.5\), and its sample variance is \( \{(0-3.5)^2+(2-3.5)^2+(4-3.5)^2+(8-3.5)^2\}/3=35/3=11.67 \) squared counts. On the raw scale, A ranks above B.

Normalized counts. Dividing each observation by its cell's factor gives A as \((2,2,2,2)\) and B as \((0,1,1,1)\). Gene A has sample variance \(0\). Gene B has mean \(0.75\), so its sample variance is \( \{(0-0.75)^2+3(1-0.75)^2\}/3=0.75/3=0.25 \). The normalized ranking puts B above A. In this hypothetical example, the raw ranking elevated A because its counts rose with the stated library factors.

Log-normalized values. Applying \(\ln(1+Y)\) gives A as four copies of \(\ln 3\), with variance \(0\). B becomes \((0,\ln 2,\ln 2,\ln 2)\). Its mean is \(3\ln(2)/4\). The sample variance is \( \{(3\ln(2)/4)^2+3(\ln(2)/4)^2\}/3=(\ln 2)^2/4=0.1201 \). The ranking still places B above A, but its variance is now on a log scale and is not directly comparable to \(0.25\) on the normalized-count scale.

The calculation depends on treating the supplied factors as suitable depth adjustments. In real data, that premise should be checked: normalization factors can be imperfect, and biological differences correlated with depth can complicate interpretation.

Worked Example: A Large Observation Before and After Log Transformation

For one hypothetical gene, suppose the values on an expression scale are \(0,0,0,8\). First calculate the sample variance, then calculate it after applying \(z=\ln(1+x)\) to each value. This example isolates the effect of a nonlinear transformation; it does not establish that the original values are normalized appropriately.

On the original scale, the mean is \(2\). The sample variance is \( \{3(0-2)^2+(8-2)^2\}/3=(12+36)/3=48/3=16 \) squared expression units.

After transformation, the values are \(0,0,0,\ln 9\), with mean \(\ln(9)/4\). For values consisting of three zeros and one value \(a\), the sample variance is \(a^2/4\): the sum of squared deviations is \(3(a/4)^2+(3a/4)^2=3a^2/4\), and division by \(n-1=3\) gives \(a^2/4\). Therefore, the log-scale variance is \( (\ln 9)^2/4=1.207 \) squared log units. The outlying value contributes less variability after this transformation, but the numerical variances describe different scales.

For a separate arithmetic check, log-scale values \(0,0,0,2.305\) have mean \(0.57625\) and sample variance \( \{3(0-0.57625)^2+(2.305-0.57625)^2\}/3=2.305^2/4=1.33 \) to three significant figures. The corresponding last value before the log transformation is approximately \(\exp(2.305)-1\approx 9.024\). This calculation illustrates how to compute variance correctly for a highly unbalanced four-value vector; it is not the same input vector as \(0,0,0,8\).

A smaller variance after log transformation is not evidence that biological heterogeneity has disappeared. It shows that the transformation has compressed the values, especially the largest one. Whether that compression is useful depends on the intended feature representation.

Choosing and Checking a Scale

A defensible scale is selected by asking what variability should represent and whether the relevant technical effects have been handled. For each candidate scale, inspect whether the ranking is driven by library depth, average expression, or a small number of extreme cells. A ranking that changes substantially between scales is a signal to investigate, not proof that one method is wrong.

  • Check depth association. For genes near the top of a raw-count ranking, inspect whether their counts rise systematically with library size or the normalization factors. Broad association across many genes suggests that depth may be contributing to apparent variability.
  • Check the mean-variance pattern. Plot or summarize variance against mean on the chosen scale. A strong trend means a variance-only ranking may favor genes simply because of their expression level. Earlier material on mean-variance trends and dispersion addresses ways to adjust for this pattern.
  • Inspect the observations behind large variances. Determine whether variability is spread across cells or driven by one or two extreme values. A log transformation may reduce that leverage, but it does not establish that the extreme observations are technical errors.
  • Compare plausible scales. Examine whether top-ranked genes remain prominent on normalized and log-normalized scales, or under a variance-adjusted feature method. Disagreement can reveal sensitivity to depth, mean, or transformation.

These checks are descriptive diagnostics, not tests of a causal mechanism. Cells from one sample can share biological and technical structure, so the number of cells is not automatically the number of independent biological replicates. Variability across captured cells should not be interpreted as a population-level treatment effect without a suitable design and inferential model.

Worked Example: Diagnosing a Raw-Scale Candidate

Suppose a hypothetical gene ranks highly by raw variance in a dataset where the normalization factors range from \(0.8\) to \(2.4\). The gene's largest raw counts occur mostly in cells with the largest factors. After dividing by the factors, its variance falls sharply, and its log-normalized values show no single extreme cell. Assume the factors were estimated using an appropriate normalization procedure and that the gene is not known to be part of a biological program associated with depth.

The pattern is consistent with library-size differences contributing to the raw ranking: high raw counts co-occur with high factors, and the ranking weakens after adjustment. The appropriate conclusion is limited: the raw variance is depth-sensitive under these conditions. It would be too strong to conclude that the gene has no biological variability, because normalization can be imperfect and biology can also covary with depth.

A next diagnostic is to compare the gene's normalized mean and variance with the overall mean-variance pattern, and to inspect the cells contributing to its values. A model-based residual feature may be a useful comparison if its assumptions are suitable. If the gene remains variable after these checks, the evidence for variation not explained by the measured depth differences is stronger, though still descriptive unless a relevant inferential design is used.

Alternatives and Limitations

ApproachWhat it summarizesMain caution
Raw-count varianceSpread of observed countsCan rank genes according to depth differences as well as expression differences
Normalized-count varianceSpread after estimated exposure adjustmentMay still depend on mean and on the quality of normalization factors
Log-normalized varianceSpread after exposure adjustment and nonlinear compressionDepends on transformation and pseudocount; does not automatically stabilize variance
Variance-adjusted or model-based featuresVariation relative to an expected mean-variance relationshipDepends on model assumptions and the adequacy of the fitted trend

Direct variance is simple and transparent, but it does not separate technical from biological variation by itself. Normalization addresses estimated exposure differences, while log transformation changes the scale and compresses large values. Mean-adjusted dispersion and model-based residuals address different aspects of the problem; they are not merely alternative labels for log variance. Each approach can fail if its assumptions are unsuitable, such as when normalization factors are poorly estimated or the model's mean-variance relationship is inadequate.

There is no scale-independent definition of “most variable” unless the target quantity is specified. A practical report should name the scale and transformation, state whether normalization was applied, and describe the checks used to assess depth and mean dependence. This makes the ranking interpretable and its limitations visible.

Common Mistake

Common mistake: “Gene A has the largest raw-count variance, so it must be the most biologically variable gene.” This reasoning ignores that raw counts can increase with library size and that variance also tends to depend on the mean. The correction is to state the scale, assess depth association, and compare variability after appropriate normalization and, where needed, mean adjustment. A change in ranking is diagnostic evidence about scale sensitivity, not proof that any one ranking is biologically correct.
Key takeaway: Variability belongs to a chosen scale. Raw counts can reflect library depth; normalization adjusts estimated depth differences; log transformation compresses large values but does not guarantee constant variance. Diagnose these effects before interpreting a gene ranking.

Check Your Understanding

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

  1. Why can a gene with constant expression per unit of library size have substantial raw-count variance?
  2. For values \(0,0,0,4\), calculate the sample variance before and after applying \(z=\ln(1+x)\).
  3. If a gene's variance decreases after log transformation, does that show that its biological variability has been removed? Explain.
  4. A raw-count ranking is strongly associated with library factors, but the association weakens after normalization. What is a reasonable interpretation, and what conclusion would be too strong?
  5. Why should a variance-only ranking be checked against the mean-variance pattern?

Solutions. (1) Counts can rise with cell-specific exposure even if relative expression is constant; raw variance then includes depth variation. (2) The mean is \(1\), so the original variance is \(\{3(0-1)^2+(4-1)^2\}/3=12/3=4\). The transformed values are \(0,0,0,\ln 5\); using the three-zero formula, the variance is \((\ln 5)^2/4=0.6476\) squared log units. (3) No. The decrease reflects compression on a different scale and does not establish that biological variation disappeared. (4) It is reasonable to say the raw ranking is depth-sensitive. It is too strong to conclude that the gene has no biological variability, because normalization may be imperfect and biology may covary with depth. (5) Genes with larger means can also have larger variances, so a variance-only ranking may favor expression level rather than unusual variability relative to the mean.

Clinical Biostats