10 Transformation
Data transformations are common in (microbial) ecology (Legendre and Gallagher 2001). They are used to mitigate technical biases in the data, to obtain more interpretable values, to enhance the comparability of samples/features or to make data compatible with the assumptions of certain statistical methods.
Examples include transforming feature counts into relative abundances (i.e., “normalizing as proportions”), or with compositionality-aware transformations such as the centered log-ratio transformation (clr).
10.1 Why transform the data
Transformations are important in working with microbiome data due to various unique characteristics of sequencing data. For example, the above mentioned examples of feature transformations are commonly used with microbiome data following the inherently proportional nature of sequencing reads: due to the nature of sequencing technology, read counts of taxa do not represent real counts of microbes in the original sample, and raw counts of taxa per sample are thus not comparable between samples.
This compositionality means that a change in the absolute abundance of one taxon will lead to apparent variations in the relative abundances of other taxa in the same sample (Figure 10.1). If neglected, such properties may cause significant bias in the results of statistical tests. The above-mentioned transformation processes are one method developed to overcome these issues by making taxon abundances comparable across samples.
In addition to this compositionality, other special characteristics of microbiome sequencing data are high variability and zero-inflation. High variability means that abundance of taxa often varies by several orders of magnitude from sample to sample. Zero-inflation means that typically more than 70% of the taxa-per-sample values are zeros, which could be due to either physical absence (structural zeros) or insufficient sequencing coverage (sampling zeros).
10.2 Common methods
Let us now summarize some commonly used transformations in microbiome data science; further details and benchmarks are available in the references.
alr: The additive log ratio transformation (Aitchison 1986) is part of a broader Aitchison family of transformations with ‘clr’ and ‘rclr’. Compared to them the biggest difference is that it selects a single feature or component as a reference and expresses all other features as log-ratios relative to it. Greenacre et al. (2021) provides guidance on choosing an appropriate reference feature.
binning: Zero-aware quantile binning (Medearis et al. 2026). A useful transformation for discretizing raw abundance data to control noise, while still retaining some information. Selection of proper
nbinsshould be tuned as a hyperparameter, when modeling.clr: Centered log ratio transformation (Aitchison 1986) is used to reduce data skewness and compositionality bias in relative abundances, while bringing the data onto a logarithmic scale. This transformation is frequently applied in microbial ecology as it enhances comparability of relative differences between samples (Gloor et al. 2017). However, the resulting transformed values are difficult to interpret directly, and it can only be applied to positive values, not zeros. A usual solution for making values non-zero is to add a pseudocount, which adds another type of bias in the data as true taxon absences are not taken into account. This is mitigated by the method of robust clr transformation (see rclr below).
hellinger: Hellinger transformation (Legendre and Gallagher 2001) is equal to the square root of relative abundances. This ecological transformation can be useful when the focus is on how species proportions vary across samples, rather than on absolute counts.
log, log2, log10: Logarithmic transformations, used e.g. to reduce data skewness. With compositional data, the clr (or rclr) transformation is often preferred.
pa: Presence/Absence transformation ignores abundances and only indicates whether the given feature is detected above the given threshold (default: 0). This simple transformation is relatively widely used in ecological research, whenever we have reasons to be interested in which taxa are present in which samples more so than their abundances. An example of such case is the process of inferring microbial ecological association networks from covariation of taxa across samples. Here, microbes that are rarely seen in the same samples are expected to have a negative ecological association (either competitive exclusion with each other or different ecological niche preferences). Conversely, looking for negative correlations in their relative abundances would not be a meaningful measure of ecological associations. Moreover, it has been used in machine learning classification models with a good performance (Giliberti et al. 2022; Karwowska et al. 2025).
rank: Rank transformation replaces each feature abundance value by its rank. It is similar to relative rank transformation (rrank) which uses relative ranks. This has use, for instance, in non-parametric statistics.
rclr: The robust clr (rclr) is similar to regular clr (see above) but allows data with zeros and avoids the need to add pseudocount (Keshavan et al. 2010; Martino et al. 2019).
relabundance: Relative transformation, also known as normalizing as proportions, total sum scaling (TSS) and compositional transformation. This converts counts into proportions (on the scale [0, 1]) that sum up to 1. Much of the currently available taxonomic abundance data from high-throughput assays (16S, metagenomic sequencing) is compositional by nature, even if the data is provided as “counts” (Gloor et al. 2017).
standardize: Standardize (or z-score) transformation scales data to zero mean and unit variance. This is used to bring features (or samples) to more comparable levels in terms of mean and scale of the values. This can enhance visualization and interpretation of the data.
Other available transformations include chi-square (
chi.square) (Legendre and Gallagher 2001), frequency transformation (frequency), and make margin sum of squares equal to one (normalize).
Transformations on abundance assays can be performed with the transformAssay() function from the mia package, keeping both the original and the transformed assay(s) in the data object. The function applies sample-wise or column-wise transformation when MARGIN = 'cols', feature-wise or row-wise transformation when MARGIN = 'rows'. A complete list of available transformations and parameters is available in the function help.
A pseudocount is a small non-negative value (e.g., 1) added to the normalized data to avoid taking the logarithm of zero. Its value can have a significant impact on the results when applying a logarithm transformation to normalized data, as the logarithm transformation is a nonlinear operation that can fundamentally change the data distribution (Costea et al. 2014).
The pseudocount should be chosen consistently across all normalization methods being compared, for example, by setting it to a value smaller than the minimum abundance value before transformation. Some tools, like ANCOMBC (Lin and Peddada 2020), take into account the effect of the pseudocount by performing sensitivity tests using multiple pseudocount values. See Chapter 15.
10.3 In practice
Below, we apply relative transformation to the counts table.
# Load example data
library(mia)
data("Tengeler2020", package = "mia")
tse <- Tengeler2020
# Transform counts assay to relative abundances
tse <- transformAssay(tse, assay.type = "counts", method = "relabundance")Get the values in the resulting assay, and view the first five rows and columns of it.
assay(tse, "relabundance")[1:5, 1:5]
## A110 A111 A12 A13 A14
## Bacteroides 0.47393 0.28657 0.00000 0.22459 0.27397
## Bacteroides_1 0.32230 0.00000 0.16664 0.07080 0.08503
## Parabacteroides 0.00000 0.02390 0.00000 0.01400 0.02283
## Bacteroides_2 0.00000 0.04709 0.00000 0.14019 0.10376
## Akkermansia 0.03057 0.04659 0.07539 0.01489 0.01323In the ‘pa’ transformation, the abundance table is converted to a presence/absence table that ignores abundances and only indicates whether the given feature is detected in the sample.
tse <- transformAssay(tse, method = "pa")
assay(tse, "pa")[1:5, 1:5]
## A110 A111 A12 A13 A14
## Bacteroides 1 1 0 1 1
## Bacteroides_1 1 0 1 1 1
## Parabacteroides 0 1 0 1 1
## Bacteroides_2 0 1 0 1 1
## Akkermansia 1 1 1 1 1You can now view the names of all assays in your data object with:
assayNames(tse)
## [1] "counts" "relabundance" "pa"A common question is whether the centered log-ratio (clr) transformation should be applied directly to raw counts or if a prior transformation, such as conversion to relative abundances, is necessary.
In theory, the clr transformation is scale-invariant, meaning it does not matter whether it is applied to raw or relative abundances, as long as the relative scale of abundances remains the same. However, in practice, there are some differences due to the introduction of a pseudocount, which can introduce bias.
There is no single correct answer, but the following considerations may help:
Data imputation should typically be applied to raw abundances, regardless of the microbial profiling pipeline used or whether the obtained abundances are counts or relative abundances.
Once a pseudocount has been added, it makes no difference whether one first converts to relative abundances before applying clr or applies clr directly to the adjusted counts.
Since applying clr directly to raw counts is the simpler approach, it is generally recommended.
One might also consider using robust clr instead.
tse <- transformAssay(
x = tse,
assay.type = "counts",
method = "clr",
pseudocount = 0.5,
name = "clr"
)To incorporate phylogenetic information, one can apply the phylogenetic isometric log-ratio (philr) transformation (Egozcue et al. 2003; Silverman et al. 2017). Unlike standard transformations, philr accounts for the genetic relationships between taxonomic features. This is important because closely related species often share similar properties, which traditional transformations fail to capture.
tse <- transformAssay(
tse,
method = "philr", MARGIN = "rows", pseudocount = 0.5
)Unlike other transformations, philr outputs a table where rows represent nodes of phylogeny. These new features do not match the features of TreeSummarizedExperiment which is why this new dataset is stored into altExp.
altExp(tse, "philr")
## class: TreeSummarizedExperiment
## dim: 149 27
## metadata(0):
## assays(1): philr
## rownames(149): node_1 node_2 ... node_148 node_149
## rowData names(0):
## colnames(27): A110 A111 ... A38 A39
## colData names(4): patient_status cohort patient_status_vs_cohort
## sample_name
## reducedDimNames(0):
## mainExpName: NULL
## altExpNames(0):
## rowLinks: NULL
## rowTree: NULL
## colLinks: NULL
## colTree: NULL10.4 Choosing a transformation
The most suitable transformation depends on the research question and the analysis method, and there is no single best choice. The table below lists common choices that are supported by benchmarking studies or widely used in the field, with links to the chapters where they are applied. They are reasonable starting points rather than strict rules.
| Analysis | Common choice | Rationale |
|---|---|---|
| Alpha diversity | Counts, rarefied if sequencing depths differ (Section 12.2.3); relative abundances when counts are not available | Richness depends on sequencing depth (Schloss 2024a), and richness estimators such as Chao1 need counts. Shannon and Simpson indices depend only on the proportions, so they give the same result with relative abundances, such as the profiles from MetaPhlAn (Beghini et al. 2021), which are commonly used and do not include counts. |
| Beta diversity and ordination | Relative abundances with Bray-Curtis; clr or rclr with Euclidean distance (Aitchison distance); presence/absence with Jaccard | Each dissimilarity assumes a specific transformation; see the table in Chapter 13. |
| Differential abundance | Relative abundances, analyzed with a non-parametric test or, after log transformation, with linear regression | This has performed well in benchmarks on real data (Nearing et al. 2022; Yang and Chen 2022; Gamboa-Tuz et al. 2025; Pelto et al. 2025); see Section 15.2. |
| Correlation and cross-association, e.g. taxa vs. metabolites | clr, or rclr when there are many zeros | Log-ratios reduce the spurious correlations caused by compositionality (Gloor et al. 2017); see Chapter 17. |
| Heatmaps | clr, then standardization of each feature (Z-transformation) | Puts features with very different abundances on a comparable scale; see Section 11.2. |
| Supervised machine learning | Relative abundances or presence/absence | Simple transformations often perform as well as or better than compositional ones (Giliberti et al. 2022; Yerke et al. 2024; Karwowska et al. 2025); see the machine learning chapter in OMA extras. |
The transformation also determines how the values are interpreted:
- Relative abundance is the proportion of a feature in a sample, which is easy to interpret but depends on the other features in the sample.
- clr is the logarithm of a feature’s abundance relative to the geometric mean of all features in the sample. A positive value means that the feature is more abundant than an average feature in that sample. Because the reference is sample-specific, differences between samples are relative rather than absolute (Gloor et al. 2017).
- rclr is interpreted like clr, but it is computed from the non-zero values only, and zeros are kept as missing values.
- Presence/absence only tells whether a feature was detected, which makes it robust to differences in sequencing depth and to noise in the abundances.
For choosing the taxonomic level of the analysis, see Section 9.3.
10.5 Rarefaction
The number of taxa we observe in a sample depends strongly on how deeply the sample was sequenced. Sequencing depth (or library size, see Section 7.2.1) refers to the number of reads obtained for a sample. In practice, sequencing depth often varies substantially between samples, even within the same study.
A common way to visualize this relationship is with a rarefaction curve (Sanders 1968; Hurlbert 1971), which shows how the number of observed features increases as a function of the number of reads sampled (Figure 10.2).
library(mia)
library(vegan)
data("GlobalPatterns", package = "mia")
tse <- GlobalPatterns
mat <- tse |>
assay("counts") |>
t()
rarecurve(
mat,
step = 1000, label = FALSE,
xlab = "Number of reads", ylab = "Number of observed taxa"
)
If a sample has not been sequenced deeply enough for its curve to approach saturation, its observed richness will be artificially low. This is not a biological signal: it is a measurement artifact caused by limited sampling.
This becomes problematic when samples are sequenced at different depths. Samples with larger library sizes tend to show more observed taxa simply because more reads were collected, not because their microbial communities are truly more diverse. Consequently, variation in sequencing depth can bias commonly used alpha and beta diversity metrics (Schloss 2024a).
To inspect the depth variation in the data, we can compute and visualize total counts per sample (Figure 10.3).
library(miaViz)
tse <- addQC(tse, assay.type = "counts")
plotBoxplot(tse, col.var = "total", x = "SampleType") +
scale_y_continuous(labels = scales::comma) +
labs(x = "Sample type", y = "Library size")
We can also quantify the spread in sequencing depth:
This dataset shows up to a 40-fold difference in sequencing depth across samples.
To mitigate bias from uneven sequencing depths, rarefaction has been proposed (Sanders 1968; Hurlbert 1971) and recently re-evaluated (Schloss 2024a, 2024b). Rarefaction standardizes sequencing depth by randomly subsampling reads so that all retained samples have the same total number of reads.
Conceptually, the workflow is:
- Choose a rarefaction depth (often the minimum library size across samples, here 58,688).
- Discard samples with fewer reads than this depth.
- For each remaining sample, randomly subsample exactly that many reads.
In mia, rarefaction can be applied directly to an assay:
tse_rarefy <- rarefyAssay(
tse,
assay.type = "counts"
)
tse_rarefy
## class: TreeSummarizedExperiment
## dim: 12760 26
## metadata(0):
## assays(2): counts subsampled
## rownames(12760): 549322 522457 ... 200359 271582
## rowData names(7): Kingdom Phylum ... Genus Species
## colnames(26): CL3 CC1 ... Even2 Even3
## colData names(17): X.SampleID Primer ... q75 q100
## reducedDimNames(0):
## mainExpName: NULL
## altExpNames(0):
## rowLinks: a LinkDataFrame (12760 rows)
## rowTree: 1 phylo tree(s) (19216 leaves)
## colLinks: NULL
## colTree: NULLThere has been a long-lasting controversy surrounding the use of rarefaction in microbial ecology. The main concern is that subsampling would omit data (McMurdie and Holmes 2014; Schloss 2024b), which is why rarefaction is generally discouraged for differential abundance testing performed on a single rarefied table (McMurdie and Holmes 2014).
However, this concern is reduced when rarefaction is treated as a repeated resampling step rather than a one-off subsample. By rarefying to the minimum library size and repeating the procedure many times, we compute the diversity metric (e.g., alpha or beta diversity) for each iteration and average across iterations, yielding a stable estimate at a common sequencing effort (Schloss 2024a, 2024b). Patrick Schloss has demonstrated that this repeated rarefaction procedure is “the only method that could control for variation in uneven sequencing effort when measuring commonly used alpha and beta diversity metrics” (Schloss 2024a). The relative benefits of rarefaction and of robust Aitchison PCA and other compositional data analysis methods in controlling for uneven sequencing effort are currently being debated (Schloss 2026).
Section 12.2.3 demonstrates rarefaction for calculating alpha diversity, and Section 13.4.2 extends the approach to beta diversity.
Microbiome data is characterized by the following features:
- Compositionality
- High variability
- Zero-inflation
OSCA book provides additional information on normalization from the perspective of single-cell analysis.
10.6 Exercises
We use the Tengeler2020 dataset.
Solve the exercises in order, as each exercise continues from the previous one. Try to solve each exercise yourself before opening the solution.

