Transformation

Making abundances comparable and analysable

Microbiome data

  • High variability: feature abundances vary widely across samples
  • Zero-inflation: many taxa absent in most samples
  • Compositionality: only relative abundances observed; total counts per sample are arbitrary

Heteroscedasticity

Scatter plot of simulated data: relative abundance against mean relative abundance; the points spread out more and more around the rising trend line as the mean increases.

Zero-inflation

Histogram of all counts in the GlobalPatterns dataset: nearly all values are zero, with a long, thin tail of very large counts.

Compositionality

  • Sequencing measures relative abundances, not true microbial counts
  • Values are parts of a whole
  • Parts are linked by a fixed total (library size)
    • If one increases, at least one other must decrease

Absolute versus relative

Two stacked bar charts of the same two samples. Left, absolute counts: taxon A triples from sample 1 to sample 2 while B and C stay equal. Right, relative abundance: the shares of B and C shrink in sample 2 although their counts did not change.

Relative vs. quantitative profiles

Genus-level profiles of the same samples as relative (RMP, left) and quantitative (QMP, right) abundances.

RMP vs. QMP: conclusions can flip

Cell counts are lower in Crohn's disease; Bacteroides differs between groups under RMP but not QMP, while Prevotella differs under QMP but not RMP.

Compositionality is not optional

“… microbiome datasets generated by HTS are compositional because they have an arbitrary total imposed by the instrument.”

“… HTS datasets derived from microbiome studies can and should be treated as compositions at all stages of analysis.”

Goals of transformation

  • Mitigate biases in abundances
  • Make features comparable across samples
  • Meet assumptions of downstream statistical analyses

Relative abundance

Library sizes are arbitrary

\[ \text{X}_{ij} = \frac{\text{Count}_{ij}}{\sum_{k=1}^m \text{Count}_{ik}} \]

where

  • \(i\) indexes the sample,
  • \(j\) indexes the taxon,
  • \(m\) is the total number of taxa.

Log-transformed relative abundance

Library sizes are arbitrary and data zero-inflated

\[ \text{X}_{ij} = \log \left( \text{Relative abundance}_{ij} + \epsilon \right) \]

where

  • \(\epsilon\) is a small pseudocount to avoid \(\log(0)\).

Counts, proportions, logs

Three histograms of GlobalPatterns abundances: raw counts and relative abundance are both dominated by a spike at zero; the log10 of relative abundance spreads the non-zero values out.

Centered log-ratio (CLR)

Library sizes are arbitrary and values are dependent

\[ \text{CLR}(x_i) = \log\left(\frac{x_i}{g(x)}\right),\quad g(x) = \left(\prod_{j=1}^{D} x_j \right)^{1/D} \]

  • \(x_i\): abundance of bacteria \(i\)
  • \(g(x)\): geometric mean across all bacteria in the sample

Intuition

  1. Values dependent, only ratios matter

Intuition

  1. Values dependent, only ratios matter
  2. Standard statistics rely on subtraction and distance

Intuition

  1. Values dependent, only ratios matter
  2. Standard statistics rely on subtraction and distance

\[ \frac{x}{y} \;\longrightarrow\; a - b \;? \]

Intuition

  1. Values dependent, only ratios matter
  2. Standard statistics rely on subtraction and distance
    • Use log-scale

\[ \log\left(\frac{x}{y}\right) = \log(x) - \log(y) \]

Intuition

  1. Values dependent, only ratios matter
  2. Standard statistics rely on subtraction and distance
    • Use log-scale
  3. Library sizes are arbitrary

Intuition

  1. Values dependent, only ratios matter
  2. Standard statistics rely on subtraction and distance
    • Use log-scale
  3. Library sizes are arbitrary
    • Center the data

Centering

Two overlapping bell-shaped density curves: the original distribution centered near 5 and the centered version centered at 0, with an arrow labelled Centering pointing from one to the other.

Centering the logs

\[ \begin{aligned} \text{CLR}(x_i) &= \log\left(\frac{x_i}{g(x)}\right) \\[2mm] &= \log(x_i) - \log(g(x)) \end{aligned} \]

Why the geometric mean?

\[ \text{Arithmetic mean} = \frac{2 + 8 + 32}{3} = \frac{42}{3} = 14 \]

\[ \begin{aligned} \text{Geometric mean} &= \sqrt[3]{2 \cdot 8 \cdot 32} \\[2mm] &= \exp\left( \frac{\log 2 + \log 8 + \log 32}{3} \right) \\[2mm] &= 8 \end{aligned} \]

Intuition: summary

  1. Values dependent, only ratios matter
  2. Standard statistics rely on subtraction and distance
    • Use log-scale
  3. Library sizes are arbitrary
    • Center the data

Centered log-ratio (CLR)

\[ \begin{aligned} \text{CLR}(x_i) &= \log\left(\frac{x_i}{g(x)}\right) \\[2mm] &= \log(x_i) - \log(g(x)) \\[2mm] &= \log(x_i) - \frac{1}{D}\sum_{j=1}^{D}\log(x_j) \end{aligned} \]

CLR in practice

Counts versus CLR

Two histograms: raw counts dominated by a spike at zero, and CLR-transformed values centered around zero with a long right tail.

Correct transformation depends on

  1. Your research question
  2. The analysis method

Use the simplest justified approach that works

Demonstration

library(mia)
data("GlobalPatterns", package = "mia")
tse <- GlobalPatterns

tse <- transformAssay(tse, method = "relabundance")
tse <- transformAssay(tse, method = "clr", pseudocount = TRUE)
assayNames(tse)
[1] "counts"       "relabundance" "clr"         

Exercises

OMA online book, Chapter 12: Transformation

References

Gloor, Gregory B., Jean M. Macklaim, Vera Pawlowsky-Glahn, and Juan J. Egozcue. 2017. “Microbiome Datasets Are Compositional: And This Is Not Optional.” Frontiers in Microbiology 8: 2224. https://doi.org/10.3389/fmicb.2017.02224.
Vandeputte, Doris, Gunter Kathagen, Kevin D’hoe, et al. 2017. “Quantitative Microbiome Profiling Links Gut Community Variation to Microbial Load.” Nature 551 (7681): 507–11. https://doi.org/10.1038/nature24460.