Tutorials › Multi-Omics Data Integration › Log and Power Transformations for Right-Skewed Omics Measurements

Preprocessing, Scaling and Block Weighting · Tutorial 31 of 597

Log and Power Transformations for Right-Skewed Omics Measurements

Learn to choose and interpret log, log1p, and Box–Cox transformations while checking their effects on skewness and variance.

Intermediate 12 min read

What You'll Learn

  • Identify the domains and formulas of log, log1p, and Box–Cox transformations.
  • Explain why logarithms compress high values more than low values.
  • Use the Box–Cox parameter to understand different effects on distances and variance.
  • Interpret transformed measurements and coefficients on the appropriate scale.
  • Diagnose when a transformation has not improved a feature’s distribution.

Why Transform Right-Skewed Measurements?

Positive omics measurements can have a long right tail: many observations are relatively small, while a few are much larger. Such a range can make plots and summaries harder to interpret, and can cause high values to dominate analyses that depend on distances or squared deviations. A transformation changes the measurement scale, often compressing the upper tail. It does not, by itself, correct every modeling problem or make observations independent.

This tutorial compares the natural logarithm, the log1p transformation, and the Box–Cox family for positive measurements. The aim is not to find one transformation that is best for every feature. Rather, understand what each transformation does, check its consequences on the data, and keep the transformed scale in mind when interpreting results.

Definition: For a positive measurement \(x>0\), the natural-log transformation is \(g(x)=\ln(x)\). For a nonnegative measurement \(x\geq 0\), the log1p transformation is \(g(x)=\ln(1+x)\). The Box–Cox transformation, for \(x>0\), is $$ g_\lambda(x)= \begin{cases} \frac{x^\lambda-1}{\lambda}, & \lambda\ne 0,\\ \ln(x), & \lambda=0. \end{cases} $$ Here \(\lambda\) is a real-valued parameter. All three transformations are strictly increasing on their stated domains, so they preserve the ordering of observations.

The formulas use natural logarithms. Changing the units of measurement changes a log’s values by an additive constant, but can change log1p values in a more substantial way because the added 1 is tied to the unit scale. For example, a measurement of 2 in one unit is not numerically equivalent inside log1p to a measurement of 2 after converting the unit so that the numeric value becomes 20. The choice of units and any offset must therefore be documented.

What Changes: Skewness, Variance, and Distances

The derivative describes how a smooth transformation changes small differences around a value \(x\). For the natural logarithm, \(g'(x)=1/x\); for log1p, \(g'(x)=1/(1+x)\); and for Box–Cox, \(g_\lambda'(x)=x^{\lambda-1}\). Thus logarithms compress local differences more at high values than at low values. Box–Cox distance behavior depends on \(\lambda\): its derivative decreases with \(x\) when \(\lambda<1\), is constant when \(\lambda=1\), and increases when \(\lambda>1\). In particular, \(\lambda=1\) gives \(x-1\), which preserves distances exactly.

For a variable \(X\) concentrated near a positive mean \(\mu\), a first-order Taylor approximation gives \(g(X)\approx g(\mu)+g'(\mu)(X-\mu)\). Taking variances on both sides yields the local approximation

$$ \operatorname{Var}(g(X))\approx [g'(\mu)]^2\operatorname{Var}(X). $$

This explains why a logarithm can reduce the influence of a large-scale tail or make variability more comparable across different mean levels. It is an approximation, not a guarantee that transformed variances will be equal. The distribution of \(X\), the range of its values, and the transformation parameter all matter.

Skewness is likewise not guaranteed to improve. A concave transformation such as a logarithm often shortens a right tail, but it may leave the data skewed or even produce left skew. A Box–Cox transformation with \(\lambda<1\) is concave on the positive domain; \(\lambda=1\) is linear; and \(\lambda>1\) is convex. Inspect transformed distributions and model diagnostics rather than assuming that a transformation has achieved its goal.

Worked Example: Comparing a Feature Before and After Logging

Suppose a hypothetical feature has measurements \(1,4,9,16\) in arbitrary positive units. Compare its sample variance on the original scale and the natural-log scale. Also use the moment skewness to illustrate that reduced right skew is not automatic.

The original mean is \(\bar{x}=(1+4+9+16)/4=7.5\). The sum of squared deviations is \( (-6.5)^2+(-3.5)^2+(1.5)^2+(8.5)^2=129\). Thus the sample variance is \(s^2=129/(4-1)=43.00\) squared measurement units.

The logged values are \(0,\ 1.3863,\ 2.1972,\ 2.7726\). Their mean is approximately \(1.5890\). The sum of squared deviations from this mean is approximately \(4.3368\), so their sample variance is \(s^2=4.3368/3\approx1.4456\) squared natural-log units. These two variances are on different scales and should not be compared as though they had the same units.

For a descriptive skewness check, define the empirical moment skewness as \(m_3/m_2^{3/2}\), where \(m_k\) is the average of the \(k\)th powers of deviations from the sample mean. On the original scale, \(m_2=129/4=32.25\) and \(m_3=300/4=75\), giving skewness \(75/(32.25)^{3/2}\approx0.410\). On the log scale, the same calculation gives approximately \(-0.47\). In this small hypothetical sample, logging changes modest right skew to left skew rather than reducing it. The example illustrates why the transformed data must be checked.

Choosing Among Log, Log1p, and Box–Cox

TransformationDomainWhat it does and how to interpret it
\(\ln(x)\)\(x>0\)Compresses high values relative to low ones. Differences on the log scale correspond to ratios on the original scale.
\(\ln(1+x)\)\(x\geq0\)Is defined at zero, but its effect depends on the measurement units because of the added 1.
Box–Cox \(g_\lambda(x)\)\(x>0\)Adjusts curvature through \(\lambda\); \(\lambda=0\) is the log and \(\lambda=1\) is a distance-preserving shift.

A log-scale difference has a multiplicative interpretation: \(\ln(x_2)-\ln(x_1)=\ln(x_2/x_1)\). If a fitted model uses \(\ln(x)\) as its response, a difference of \(\beta\) on that scale corresponds to a multiplicative factor of \(e^\beta\) on the original response scale, subject to the model’s other terms. For log1p, the corresponding ratio is \((1+x_2)/(1+x_1)\), not \(x_2/x_1\). A Box–Cox difference generally has no simple ratio interpretation unless \(\lambda=0\); interpretation uses the inverse transformation or a stated transformed-scale contrast.

If a Box–Cox parameter is estimated, a common approach is to choose the \(\lambda\) that makes a transformed response most compatible with a Gaussian model. For independent positive observations \(x_1,\ldots,x_n\) with a common mean and variance after transformation, the profile log-likelihood, up to constants, is

$$ \ell_p(\lambda)=-\frac{n}{2}\ln\left(\frac{\operatorname{RSS}_\lambda}{n}\right) +(\lambda-1)\sum_{i=1}^n\ln(x_i), $$

where \(\operatorname{RSS}_\lambda\) is the sum of squared deviations from the mean of the transformed observations. The second term accounts for the change of scale (the Jacobian); omitting it does not give this likelihood comparison. The estimate is the value of \(\lambda\) maximizing \(\ell_p(\lambda)\). This selection is tied to the stated Gaussian, independent-observation model. With covariates or dependence among observations, the likelihood must reflect that model rather than treating the observations as independent replicates.

Worked Example: How Box–Cox Changes Distances

For the same hypothetical values \(1,4,9,16\), compare \(\lambda=0\), \(\lambda=0.5\), and \(\lambda=1\). The \(\lambda=0\) values are the logs \(0,1.3863,2.1972,2.7726\). For \(\lambda=0.5\), \(g_{0.5}(x)=(\sqrt{x}-1)/0.5=2(\sqrt{x}-1)\), giving \(0,2,4,6\). The transformed gaps are \(2,2,2\).

For \(\lambda=1\), \(g_1(x)=x-1\), giving \(0,3,8,15\), with gaps \(3,5,7\). This transformation preserves the original gaps \(3,5,7\) exactly; the shift by 1 changes the location but not the distances. By contrast, the log gaps between successive observations are approximately \(1.3863,\ 0.8109,\ 0.5754\), which shrink as the values increase.

The sample variance at \(\lambda=0.5\) is \(20/3\approx6.6667\) squared transformed units, since the values \(0,2,4,6\) have mean 3 and squared deviations summing to 20. At \(\lambda=1\), the values \(0,3,8,15\) have mean 6.5 and squared deviations summing to 129, giving \(129/3=43.00\). The change in variance is scale-dependent; the main lesson is that Box–Cox does not always compress distances. Its behavior depends on \(\lambda\).

Worked Example: What Log1p Does Near Zero

Consider a hypothetical nonnegative feature with measurements \(0,1,9,99\). The natural logarithm cannot be applied to the zero value. Log1p gives \(\ln(1+0)=0\), \(\ln(2)\approx0.6931\), \(\ln(10)\approx2.3026\), and \(\ln(100)\approx4.6052\).

The transformed mean is approximately \(1.9002\). The squared deviations sum to approximately \(12.5465\), so the sample variance is \(12.5465/3\approx4.1822\) squared log1p units. The transformation preserves the ordering and makes the gap from 9 to 99 equal to about \(2.3026\), rather than the original gap of 90. It also distinguishes 0 from 1 by about \(0.6931\), rather than treating a zero as undefined.

The numeric result depends on the units: if the same measurements were recorded in tenths of the displayed unit, applying log1p to those rescaled numbers would not simply subtract a constant from all transformed values. Therefore, choosing log1p is a modeling decision about the measurement scale and offset, not merely a way to avoid evaluating \(\ln(0)\).

Diagnostics, Assumptions, and Common Pitfalls

Transformations are most useful when their purpose is explicit. For each feature, examine the original and transformed distributions with plots, and compare the pattern of spread across the range of fitted values or relevant groups. Check whether a long upper tail has shortened, whether a small number of observations still dominate, and whether the transformed scale is suitable for the scientific interpretation. If a model is being fitted, inspect diagnostics relevant to that model; a marginally symmetric feature does not ensure that model residuals satisfy their assumptions.

A Box–Cox likelihood choice assumes the positive measurements are modeled under the likelihood used to choose \(\lambda\). A log or log1p transformation does not require that every feature become normally distributed. Do not treat a transformation as proof of normality, equal variance, independence, or a particular measurement mechanism. If estimated parameters are used in later prediction or evaluation, estimate them using only the data appropriate to that analysis, and apply the same transformation consistently.

A common mistake is to say, “Any Box–Cox transformation compresses high values, so it must reduce right skew.” This is false: \(g_\lambda'(x)=x^{\lambda-1}\), so \(\lambda=1\) preserves distances, while \(\lambda>1\) expands local distances more at high values. Even a logarithm may overcorrect skewness, as the first worked example illustrates. The correction is to inspect the actual transformed data and choose a transformation for a stated analytical purpose.

Another pitfall is interpreting a transformed coefficient as though it were a change in the original measurement units. A coefficient for \(\ln(x)\) is a contrast on the log scale and often has a ratio interpretation after exponentiation; a log1p coefficient relates to \(1+x\). For nonlinear transformations, the inverse of a fitted transformed mean is not generally the original-scale arithmetic mean. Back-transformation and the target summary must be specified rather than assumed.

Key takeaway: Logarithms often compress right tails, but no transformation guarantees improved skewness or constant variance. The domain, units, transformation parameter, model assumptions, and scale of interpretation all matter.

Check Your Understanding

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

  1. Which transformation is defined at zero: \(\ln(x)\), log1p, or the Box–Cox family as defined here?
  2. For Box–Cox with \(\lambda=1\), what happens to pairwise distances?
  3. If a model uses \(\ln(x)\), what original-scale ratio corresponds to a log-scale difference of \(\beta\)?
  4. Why can a log1p transformation change when measurement units change?
  5. Does a decrease in sample variance after transformation prove that the transformed data are more suitable for a model? Explain.

Solutions. (1) Log1p is defined at zero; the stated log and Box–Cox domains require \(x>0\). (2) \(g_1(x)=x-1\), so every pairwise distance is preserved. (3) The ratio is \(e^\beta\), because \(\ln(x_2)-\ln(x_1)=\ln(x_2/x_1)=\beta\). (4) The added 1 is in the numeric measurement units, so rescaling \(x\) changes \(\ln(1+x)\) nonlinearly. (5) No. The variance is on a different scale; suitability depends on the analytical objective and relevant model diagnostics, not on making a variance numerically smaller.

Clinical Biostats