Skip to content

VST: stabilizing variance

VST (variance stabilizing transformation) is a statistical transformation that brings variances that differ with the mean level onto a similar scale. It applies a transformation function f to data whose fluctuations grow in larger-value regions, making the range of variation appear relatively consistent across regions after transformation.

VST is not the name of one fixed formula. Depending on the probability distribution of the data and the relationship between its mean and variance, you select a different function such as a square-root, logarithmic, or Anscombe transformation.

The same relative fluctuation produces different variances

Section titled “The same relative fluctuation produces different variances”

Suppose repeated measurements at two levels are:

LevelRepeated measurementsMeanSample standard deviation
Low level8, 10, 12102
High level800, 1,000, 1,2001,000200

Both rows fluctuate by about 20% of their mean. In the original units, however, their standard deviations are 2 and 200, a hundredfold difference. This property, in which variance grows together with the mean, is called heteroscedasticity.

If these values are used directly in a scatter plot, distance calculation, or least-squares regression, the high-level observations can dominate the calculation. VST compresses distances more strongly in the high range, placing fluctuations in low and high ranges on scales that are easier to compare.

The synthetic dataset below makes six variables fluctuate by the same proportion around their respective means. Move the F6 mean, then switch between the raw-value and VST views to see how absolute variance grows for a variable with a larger mean and becomes more even after transformation. This example uses log2(x + 1), which is suitable for proportional error.

The principle for choosing a transformation function

Section titled “The principle for choosing a transformation function”

Let the mean of a value X be μ\mu, and suppose its variance changes with the mean according to v(μ)v(\mu). After applying a transformation function ff, the delta method approximates the variance of the transformed value as:

Var[f(X)](f(μ))2v(μ)\operatorname{Var}[f(X)] \approx \left(f'(\mu)\right)^2 v(\mu)

f(μ)f'(\mu) is the slope of the transformation function near the mean. To make the expression above approximately constant and independent of the mean μ\mu, set the slope according to this relationship:

f(μ)1v(μ)f'(\mu) \propto \frac{1}{\sqrt{v(\mu)}}

This means that where variance grows rapidly, the function’s slope is made smaller to compress the distances between values more strongly. If the form of v(μ)v(\mu) is known, integrating this slope gives a suitable transformation function.

The formula changes with the mean-variance relationship

Section titled “The formula changes with the mean-variance relationship”

Representative relationships and transformations include:

Property of the dataMean-variance relationshipCommon transformation
Integer event counts with a Poisson formVar(X)μ\operatorname{Var}(X) \approx \muSquare-root or Anscombe transformation
Positive data where error is proportional to the valueVar(X)μ2\operatorname{Var}(X) \propto \mu^2Log transformation
Proportions with a fixed number of trialsVar(X)p(1p)\operatorname{Var}(X) \propto p(1-p)Arcsine square-root transformation
Positive data whose relationship is difficult to specify in advanceSearch the data for transformation strengthBox-Cox family transformation

For example, if variance is proportional to the mean, then v(μ)=μv(\mu)=\mu, so the required slope is proportional to 1/μ1/\sqrt{\mu}. Integrating it produces a square-root transformation.

For better correction of small values from a Poisson distribution, you can use the Anscombe transformation instead of a simple square root.

f(x)=2x+38f(x) = 2\sqrt{x + \frac{3}{8}}

It resembles a square-root transformation for large values, while the 3/83/8 adjustment improves the approximation for small values.

VST applies the same function f to every value before transformation. If the original data is a table, the numbers of rows and columns remain unchanged and only the value in each cell changes.

With a monotonically increasing transformation, the order of values is generally preserved. The largest value does not become the smallest. Differences, ratios, and units do change, so interpretations from the original units such as twice as large or an increase of 100 cannot be applied directly to transformed values.

VST does not automatically perform any of these tasks:

  • Make the mean of every variable zero
  • Make the variance of every variable exactly one
  • Remove outliers
  • Remove group differences
  • Fix an incorrect model or measurement error
  • Calculate effect sizes in the original, untransformed units

The goal is not to make every variance exactly equal. It is to reduce systematic dependence between the mean level and variance.

The relationship between log transformation and VST

Section titled “The relationship between log transformation and VST”

A log transformation is one of the most familiar VST candidates.

import numpy as np
transformed = np.log(x)

For data where measurement error grows as a constant proportion of the original value rather than by a constant absolute amount, a logarithm can compress the high range strongly and even out variance. It cannot be applied directly to zero or negative values, however, and it does not stabilize variance in every dataset.

Adding a constant c, as in log(x + c), handles zero, but the chosen constant greatly changes the shape of the low-value region. Instead of selecting a logarithm simply because it is familiar, first inspect the mean-variance relationship.

How does it differ from normalization and z-scores?

Section titled “How does it differ from normalization and z-scores?”

The three operations have different purposes.

OperationWhat it changesRepresentative result
VSTVariance that changes with the mean levelSimilar ranges of variation in low and high regions
NormalizationDifferences in overall scale across observational unitsTotals or reference sizes aligned across units
z-score standardizationLocation and scale for each variableMean 0 and standard deviation 1 for each variable

After calculation, a z-score makes the variance of each variable one, but it does not model why the original data was heteroscedastic. VST differs because it selects a nonlinear function suited to the relationship between mean and variance.

Centering or standardization can be added after VST when needed. The appropriate order and combination depend on the input properties required by the next analysis.

How does it differ from Mahalanobis distance?

Section titled “How does it differ from Mahalanobis distance?”

VST is preprocessing that changes the values in a matrix, while Mahalanobis distance is a method for measuring the distance between two rows. Both can reduce the problem of high-variance variables dominating a calculation, but they act at different stages and use different information.

Consider two variables with these means and standard deviations:

VariableMean and standard deviation
Low level10±210 \pm 2
High level1,000±2001{,}000 \pm 200

With Euclidean distance on the original values, a difference of 200 at the high level contributes much more than a difference of 2 at the low level. VST compresses distances around 1,000 more strongly so fluctuations at the two levels become similar in size. Ordinary Euclidean distance or PCA can then be applied to the transformed values.

Mahalanobis distance does not directly compress the original values. Instead, it gives a smaller weight to differences in directions with greater ordinary observed variance, and it also accounts for correlations in how multiple variables move together. If the two rows are xx and yy, and the covariance matrix of the variables is Σ\Sigma, the distance is:

dM(x,y)=(xy)TΣ1(xy)d_M(x,y)=\sqrt{(x-y)^T\Sigma^{-1}(x-y)}

The covariance matrix contains the variance of each variable on its diagonal and the correlated movement of pairs of variables off the diagonal. Mahalanobis distance therefore avoids counting the same information twice as strongly as Euclidean distance when it is repeated across two variables.

DistinctionVSTMahalanobis distance
What it changesThe value in each cellThe formula for distance between two rows
Main problem it addressesHeteroscedasticity, where variance grows with the meanScale differences across variables and correlations between variables
Required estimateThe relationship between mean and varianceThe covariance matrix across all variables
ResultA transformed data matrixDistances between rows

Mahalanobis distance does not remove the nonlinear relationship between mean and variance itself. It changes the weighting of differences based on covariance estimated from the current data. Conversely, VST generally does not incorporate correlations between variables when calculating distance.

In data such as RNA-seq, with 20,000 genes but only dozens of samples, it is difficult to estimate a 20,000×20,00020{,}000 \times 20{,}000 covariance matrix reliably. When there are more variables than samples, the covariance matrix also cannot be inverted directly. VST is therefore often applied before sample PCA or clustering. If Mahalanobis distance is needed, one option is to apply VST, reduce the dimensions with PCA, and estimate covariance in a PC space that is sufficiently small relative to the sample count.

VST is statistical preprocessing. It can be used before methods such as PCA, clustering, and regression that are sensitive to distance, variance, or linear relationships.

A result looking better after transformation does not by itself establish that the VST was appropriate. Estimating the transformation function using validation data creates data leakage. In a prediction task, determine the transformation from the training data and apply the same function to the validation and test data.

How to check whether a transformation is appropriate

Section titled “How to check whether a transformation is appropriate”
  1. Plot the mean or fitted value of the original values against the spread of residuals.
  2. Check whether the spread widens as the mean grows.
  3. Select a candidate transformation suited to the data-generating distribution or the mean-variance relationship.
  4. Draw the same plot after transformation and check whether the spread is more consistent.
  5. Check that the transformation has not introduced an important nonlinear relationship or made interpretation excessively difficult.
  6. Record the transformation function, constants, and estimation method so the treatment can be reproduced.

If a model can handle the variance structure directly, VST is not necessarily required first. For example, weighted least squares or a suitable generalized linear model can model the mean-variance relationship in the original units. Transformation is not the objective. It is one of several possible solutions.