Skip to contents

This function normalizes the data by dividing each observation by the total library size of its sample. The resulting values represent the proportion (0 to 1) of the sample composed of that specific feature.

This is a common transformation for microbiome data, as it accounts for differences in sequencing depth across samples, allowing for comparison of community composition.

Usage

biom_relativize(biom, clone = TRUE)

Arguments

biom

An rbiom object, or any value accepted by as_rbiom().

clone

Create a copy of biom before modifying. If FALSE, biom is modified in place as a side-effect. See speed ups for use cases. Default: TRUE

Value

An rbiom object.

Details

Convert absolute counts to relative abundances (proportions) where each sample sums to 1.

Examples

    library(rbiom)
    
    biom <- hmp50[1:5]
    
    # Raw counts sum to different library sizes
    sample_sums(biom)
#> HMP01 HMP02 HMP03 HMP04 HMP05 
#>  1660  1371  1353  1895  3939 
    
    # Relativized counts sum to 1
    biom_rel <- biom_relativize(biom)
    sample_sums(biom_rel)
#> HMP01 HMP02 HMP03 HMP04 HMP05 
#>     1     1     1     1     1