Tutorials › High-Dimensional Genomic Data Analysis › Log-CPM and Variance-Stabilizing Transformations

Normalization and Batch Effects · Tutorial 84 of 795

Log-CPM and Variance-Stabilizing Transformations

Calculate log-CPM with an explicit prior count and distinguish its visualization benefits from the goals and assumptions of variance-stabilizing transformations.

Intermediate 12 min read

What You'll Learn

  • Calculate CPM using an effective library size and state the units of the prior count.
  • Explain why adding a positive prior count defines log-CPM for zero counts.
  • Use the delta method to describe how log transformation changes count variance.
  • Derive a variance-stabilizing transformation from a specified variance function.
  • Compare log-CPM with square-root and model-based variance-stabilizing transformations.
  • Identify when transformed values are useful for exploration but unsuitable as count-model inputs.

Why Transform Normalized Counts?

Sequencing counts often span a wide range: a feature may have zero or one read in one sample and hundreds or thousands in another. Library-size normalization puts samples on a comparable scale, but it does not remove the strong relationship between a feature's mean count and its variance. A few high-count features can dominate a plot, while differences among low counts may be hard to see.

Log counts per million (log-CPM) is a convenient way to display normalized abundance across a broad range. A positive prior count makes the transformation defined at zero and moderates the influence of very small counts. A variance-stabilizing transformation (VST) has a different, more specific aim: under a stated mean-variance relationship, it is chosen so transformed values have approximately constant variance over the range of means. These approaches can support visualization and exploratory analysis, but they do not replace normalization or determine an appropriate model for inferential analysis.

Definition and Calculation of Log-CPM

Definition: Let \(y_{ij}\) be the observed count for feature \(i\) in sample \(j\), and let \(E_j\) be that sample's effective library size, measured in reads. Define the counts per million for that observation as \(\mathrm{CPM}_{ij}=10^6y_{ij}/E_j\). For a chosen prior count \(a>0\), measured in CPM units, define \(\mathrm{logCPM}_{ij}=\log_2(\mathrm{CPM}_{ij}+a)\). Because \(a\) is positive, this quantity is defined even when \(y_{ij}=0\).

The effective library size incorporates the library-size scaling choice used for normalization. If only the raw library size is being used, \(E_j\) is that raw size. If a size factor or other scaling adjustment has been applied, \(E_j\) should reflect that adjustment. The CPM unit is one count per million effective reads; \(a=0.5\), for example, means adding half a CPM, not half a read. Keeping the prior count in CPM units makes the rule explicit and gives the same offset on the normalized CPM scale across samples.

A base-2 logarithm makes a doubling correspond to one unit of difference when the prior count is negligible relative to both CPM values. More generally, the difference is \(\log_2((c_1+a)/(c_2+a))\), where \(c_1\) and \(c_2\) are the two CPM values. Near zero, the prior materially changes this ratio, so a one-unit difference should not automatically be described as a twofold difference in the underlying abundance.

Worked Example: Comparing Counts Across Library Sizes

Suppose a feature has 12 reads in a sample with effective library size 3,000,000 reads, and 120 reads in a sample with effective library size 30,000,000 reads. Use a prior count of \(a=0.5\) CPM.

For the first sample, \(\mathrm{CPM}=10^6(12)/3{,}000{,}000=4\). Its log-CPM is \(\log_2(4+0.5)=\log_2(4.5)\approx2.170\).

For the second sample, \(\mathrm{CPM}=10^6(120)/30{,}000{,}000=4\). Its log-CPM is also \(\log_2(4+0.5)\approx2.170\). The raw counts differ by a factor of ten, but the normalized CPM values match because the effective library sizes also differ by a factor of ten. This calculation illustrates the scaling; it does not establish that the samples have identical biological expression.

Worked Example: A Zero Count and the Prior's Influence

Consider two samples with effective library size 5,000,000 reads. In one sample the feature count is zero; in the other it is three. Use \(a=0.5\) CPM.

For the zero count, \(\mathrm{CPM}=0\), so \(\mathrm{logCPM}=\log_2(0+0.5)=-1\). For the count of three, \(\mathrm{CPM}=10^6(3)/5{,}000{,}000=0.6\), so \(\mathrm{logCPM}=\log_2(0.6+0.5)=\log_2(1.1)\approx0.1375\).

The transformed difference is approximately \(1.138\) log-base-2 units. The positive prior avoids an undefined logarithm and limits how far apart these two low values appear. It is a computational and scale choice, not evidence that a zero count represents a true abundance of 0.5 CPM. Changing the prior changes low-count transformed values, while having relatively little impact when CPM is large compared with \(a\).

What the Log Transformation Does to Variance

Log-CPM compresses the range of values, but it does not generally make variance constant. The delta method gives a local approximation to the variance of a smooth transformation: if \(Y\) has mean \(\mu\) and variance \(V(\mu)\), then for a function \(g\) differentiable near \(\mu\), \(\operatorname{Var}\{g(Y)\}\approx[g'(\mu)]^2V(\mu)\). This is an approximation for values concentrated near a positive mean, not an assertion that every transformed count has exactly that variance.

For log-CPM with effective library size \(E\) fixed and prior \(a>0\), write \(g(y)=\log_2(10^6y/E+a)\). Equivalently, \(g(y)=\log_2(y+A)+\log_2(10^6/E)\), where \(A=aE/10^6>0\). Thus \(g'(y)=1/((y+A)\ln 2)\). If \(Y\) has mean \(\mu>0\) and variance \(V(\mu)\), the delta-method approximation is

$$ \operatorname{Var}\{g(Y)\}\approx \frac{V(\mu)}{(\ln 2)^2(\mu+A)^2}. $$

For a Poisson count, \(V(\mu)=\mu\), so this approximation becomes \(\mu/((\ln 2)^2(\mu+A)^2)\). It is well-defined for the log-with-offset function, including at observed zero counts. At means large relative to \(A\), it decreases approximately as \(1/(\mu(\ln 2)^2)\); therefore log transformation does not stabilize Poisson variance across the whole range. Without a positive offset, \(\log_2(Y)\) would be undefined at zero, which has positive probability under a Poisson model. A derivative calculation for the unoffset log near a positive mean cannot define the variance of that undefined transformation.

Variance-Stabilizing Transformations

Definition: Suppose a random variable \(Y\) has mean \(\mu\) and a positive variance function \(V(\mu)\). A variance-stabilizing transformation targeting approximate variance 1 is a differentiable function \(h\) satisfying \(h'(\mu)=1/\sqrt{V(\mu)}\). An additive constant in \(h\) does not change the derivative or the approximate variance. The multiplicative scale is fixed by the target: replacing \(h\) by \(c h\) gives approximate variance \(c^2\), not 1.

The justification follows directly from the delta method. For values near \(\mu\),

$$ \operatorname{Var}\{h(Y)\}\approx[h'(\mu)]^2 V(\mu) =\frac{1}{V(\mu)}V(\mu)=1. $$

This is a local approximation, and it depends on the variance function being a reasonable description of the data. A variance function alone does not guarantee normality of transformed observations, independence across samples, or identical distributions. Those properties should not be inferred from a transformation.

Worked Example: The Square-Root Transformation for Poisson Counts

Suppose a count \(Y\) follows a Poisson distribution with mean \(\mu>0\), so that \(\operatorname{Var}(Y)=\mu\). The variance-stabilizing derivative is \(h'(\mu)=1/\sqrt{\mu}\). Integrating gives \(h(\mu)=2\sqrt{\mu}+C\), where \(C\) is an arbitrary additive constant.

The delta-method check is \(h'(\mu)=1/\sqrt{\mu}\), so \([h'(\mu)]^2\operatorname{Var}(Y)=(1/\mu)\mu=1\). For a count with mean near 9, the transformed mean-scale value is \(2\sqrt{9}=6\), and the local approximate variance is 1. The square-root transformation is defined at an observed zero, unlike an unoffset logarithm.

A commonly used refinement for Poisson counts is the Anscombe transformation \(2\sqrt{Y+3/8}\), which can improve finite-count approximation. It is an approximation, not an exact guarantee of equal variance for every count mean. Neither the basic square-root nor Anscombe transformation accounts for library-size differences by itself; normalization remains necessary.

Variance Functions and the Choice of Transformation

The appropriate transformation depends on the assumed relationship between mean and variance. For illustration, if counts follow a negative-binomial variance relationship \(V(\mu)=\mu+\phi\mu^2\), with dispersion parameter \(\phi>0\), integrating \(1/\sqrt{V(\mu)}\) gives

$$ h(\mu)=\frac{2}{\sqrt{\phi}}\operatorname{asinh}(\sqrt{\phi\mu})+C. $$

Differentiating yields \(h'(\mu)=1/\sqrt{\mu+\phi\mu^2}\), as required. When \(\phi\) approaches zero, this transformation approaches \(2\sqrt{\mu}\); at large \(\mu\), it grows approximately logarithmically. This example shows why a transformation tailored to a mean-variance model can behave differently from plain log-CPM. In practice, the variance relationship must be estimated or specified appropriately; a single transformation cannot guarantee stabilization if dispersion varies substantially among features.

Worked Example: Checking a Negative-Binomial VST Derivative

Take \(\phi=0.2\) and \(\mu=10\). The variance under the stated model is \(V(10)=10+0.2(10^2)=30\). The proposed transformation has derivative \(h'(10)=1/\sqrt{30}\approx0.1826\). Therefore its delta-method variance is approximately \((0.1826)^2(30)=1.000\), up to rounding.

For comparison, a log-like transformation has derivative that decreases approximately in proportion to \(1/\mu\) at high means, whereas this model-based derivative decreases according to \(1/\sqrt{\mu+\phi\mu^2}\). The VST derivative follows the variance assumed in this example. If the actual variance does not follow that relationship, the calculation no longer justifies approximate stabilization.

Use, Diagnostics, and Limitations

Log-CPM is useful for exploratory plots, clustering inputs, and summaries where normalized abundance on a compressed scale is helpful. A model-based VST can be useful when the objective is to make variability more comparable across a range of mean expression, provided its variance assumptions are defensible. Neither transformation is a replacement for the normalization step: CPM values still depend on the effective library sizes, and a VST cannot correct a systematic scaling error.

Check whether conclusions about broad patterns depend strongly on the prior count, particularly for features with many zeros or very small CPM. Inspect whether transformed values are dominated by a few highly expressed features, whether low-count values are compressed excessively, and whether apparent sample differences track library size or an obvious technical grouping. These are warnings to investigate, not formal tests. Detailed normalization diagnostic plots are considered separately.

ApproachPrimary useKey limitation
Raw countsRetain the observed count scaleLibrary sizes differ; high counts can dominate visual comparisons
Log-CPM with priorDisplay normalized abundance over a wide rangePrior affects low counts; log transformation does not generally stabilize variance
Variance-stabilizing transformationReduce mean-dependent variance under a specified variance modelDepends on the variance model and does not fix normalization or other systematic effects

A common mistake is to say, “The log makes the counts normally distributed with equal variance, so I can use the transformed values as if they were the original counts.” This reasoning is wrong: log compression alone does not establish normality or constant variance, and transformed values are not counts. Use transformations for the exploratory purpose they support, and use an analysis model appropriate to the count data when count-based inference is required.

Key takeaway: State the effective library size and prior-count scale whenever calculating log-CPM. Treat it as a useful normalized display scale, not automatically as a variance-stabilizing or inferential model. A VST targets approximate constant variance only relative to an explicit, suitable variance function.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A sample has 20 reads for a feature and an effective library size of 4,000,000 reads. With \(a=0.5\) CPM, calculate CPM and log-CPM.
  2. Why is a positive prior count needed when log-transforming CPM values that may be zero?
  3. For Poisson counts, verify that \(h(\mu)=2\sqrt{\mu}\) gives delta-method variance approximately 1.
  4. Does log-CPM with a prior necessarily produce constant variance across mean counts? Explain.

Solutions. (1) \(\mathrm{CPM}=10^6(20)/4{,}000{,}000=5\). Thus \(\mathrm{logCPM}=\log_2(5.5)\approx2.459\). (2) If CPM is zero, its logarithm is undefined; adding \(a>0\) makes the input positive and the value finite. (3) For a Poisson count, \(V(\mu)=\mu\), and \(h'(\mu)=1/\sqrt{\mu}\). Hence \([h'(\mu)]^2V(\mu)=(1/\mu)\mu=1\). (4) No. The delta-method approximation for log-CPM is \(\mu/((\ln 2)^2(\mu+A)^2)\) under a Poisson variance assumption, which changes with \(\mu\).

Clinical Biostats