Skip to contents

Calculate the alpha diversity of each sample.

Usage

adiv_table(biom, adiv = "Shannon", md = ".all", transform = "none")

Arguments

biom

An rbiom object, such as from as_rbiom(). Any value accepted by as_rbiom() can also be given here.

adiv

Alpha diversity metric(s) to use. Options are: "OTUs", "Shannon", "Chao1", "Simpson", and/or "InvSimpson". Set adiv=".all" to use all metrics. Default: "Shannon"

Multiple/abbreviated values allowed.

md

Dataset field(s) to include in the output data frame, or '.all' to include all metadata fields. Default: '.all'

transform

Transformation to apply. Options are: c("none", "rank", "log", "log1p", "sqrt", "percent"). "rank" is useful for correcting for non-normally distributions before applying regression statistics. Default: "none"

Value

A data frame of alpha diversity values.
Each combination of sample/depth/adiv has its own row.
Column names are .sample, .depth, .adiv, and .diversity, followed by any metadata fields requested by md.

See also

Other alpha_diversity: adiv_boxplot(), adiv_corrplot(), adiv_stats()

Examples

    library(rbiom) 
    
    # Subset to 10 samples.
    biom <- slice(hmp50, 1:10)
    adiv_table(biom)
#> # A tibble: 10 × 8
#>    .sample .depth .adiv   .diversity   Age   BMI `Body Site`    Sex   
#>    <chr>    <dbl> <fct>        <dbl> <dbl> <dbl> <fct>          <fct> 
#>  1 HMP01     1660 Shannon       1.74    22    20 Buccal mucosa  Female
#>  2 HMP02     1371 Shannon       2.59    24    23 Buccal mucosa  Male  
#>  3 HMP03     1353 Shannon       2.95    28    26 Saliva         Male  
#>  4 HMP04     1895 Shannon       3.26    25    23 Saliva         Male  
#>  5 HMP05     3939 Shannon       1.46    27    24 Buccal mucosa  Female
#>  6 HMP06     4150 Shannon       3.09    32    25 Saliva         Male  
#>  7 HMP07     3283 Shannon       1.23    26    22 Buccal mucosa  Male  
#>  8 HMP08     1695 Shannon       2.51    27    26 Saliva         Female
#>  9 HMP09     2069 Shannon       3.60    33    32 Saliva         Male  
#> 10 HMP10     2509 Shannon       1.75    22    20 Anterior nares Female
    
    biom <- rarefy(biom)
    adiv_table(biom, adiv = ".all", md = NULL)
#> # A tibble: 50 × 4
#>    .sample .depth .adiv .diversity
#>    <fct>    <dbl> <fct>      <dbl>
#>  1 HMP01     1353 OTUs          44
#>  2 HMP02     1353 OTUs          75
#>  3 HMP03     1353 OTUs          75
#>  4 HMP04     1353 OTUs          79
#>  5 HMP05     1353 OTUs          44
#>  6 HMP06     1353 OTUs          80
#>  7 HMP07     1353 OTUs          42
#>  8 HMP08     1353 OTUs          59
#>  9 HMP09     1353 OTUs          97
#> 10 HMP10     1353 OTUs          25
#> # ℹ 40 more rows