tax_scale: Mean-center and SD-scale taxa in phyloseq

View source: R/tax_scale.R

tax_scaleR Documentation

Mean-center and SD-scale taxa in phyloseq

Description

Wrapper for applying base scale function to phyloseq otu_table

Usage

tax_scale(data, center = TRUE, scale = TRUE, do = NA, keep_counts = TRUE)

Arguments

data

phyloseq or psExtra or otu_table

center

if TRUE: center each taxon by subtracting its mean

scale

if TRUE, divide each centred taxon by its standard deviation (or divide by RMS if not centred!)

do

alternative argument that overrides center and scale options! takes "both", "scale", "center" or "neither"

keep_counts

if TRUE, retain the original count data in psExtra counts slot

Examples

data("dietswap", package = "microbiome")
ps <- dietswap
ps %>%
  otu_get() %>%
  .[1:6, 1:6]

# standard use (mean center and SD scale)
tax_scale(ps) %>%
  otu_get() %>%
  .[1:6, 1:6] # Aerococcus is NaN as standard deviation = 0 (0 prevalence)

# RMS scale only (directly on otu_table)
otu_get(ps) %>%
  tax_scale(center = FALSE) %>%
  .[1:6, 1:6] # Aerococcus is NaN as standard deviation = 0 (0 prevalence)

# example using alternative `do` argument (to center only, no scaling)
tax_scale(ps, do = "center") %>%
  otu_get() %>%
  .[1:6, 1:6]

# preserves existing info
tax_transform(ps, "compositional", rank = "Genus") %>% tax_scale()

# drops other psExtra objects previously calculated with unscaled data
psxDist <- tax_agg(ps, "Genus") %>% dist_calc()
psxDist
psxDist %>% tax_scale()
tax_scale(psxDist) %>% info_get()

david-barnett/microViz documentation built on April 17, 2025, 4:25 a.m.