Skip to contents

add_ord() adds the first n dimensions of a dimensionality reduction method performed on a given dissimilarity matrix as new variables to the sample table of a tidytacos object.

Usage

add_ord(ta, distance = "bray", method = "pcoa", dims = 2, binary = FALSE, ...)

Arguments

ta

A tidytacos object.

distance

The distance indices to use, see vegan::vegdist().

method

The ordination method to use to calculate coordinates. Choices are pcoa, tsne, umap.

dims

The amount of dimensions to reduce the dissimilarities to.

binary

Perform presence/absence standardisation before distance computation or not.

...

Additional arguments to pass to the ordination function: either stats::cmdscale(), Rtsne::Rtsne() or umap::umap().

Value

A tidytacos object with the ordination coordinates added.

Details

This function calculates the dissimilarities between samples followed by an ordination analysis. It will then add the first n dimensions to the sample table of a tidytacos object named "ord1", "ord2", ... This function will also add relative abundances if not present using add_rel_abundance().

Examples

# Initiate counts matrix
x <- matrix(
  c(1500, 1300, 280, 356, 456, 678),
  ncol = 3
)
rownames(x) <- c("taxon1", "taxon2")
colnames(x) <- c("sample1", "sample2", "sample3")

# Convert to tidytacos object
data <- create_tidytacos(x,
  taxa_are_columns = FALSE
)

# Add pcoa
data <- data %>%
  add_ord()

# The variances of the ordination dimensions can be accessed with
data$ord_variances
#> [1] 1.000000e+00 7.325738e-16 0.000000e+00