Run ordinations on a distance matrix.
Usage
distmat_ord_table(dm, ord = "PCoA", k = 2L, seed = 0, cpus = n_cpus(), ...)Arguments
- dm
A
dist-class distance matrix, as returned frombdiv_distmat()orstats::dist(). Required.- ord
Method for reducing dimensionality. Options are:
"PCoA"-Principal coordinate analysis;
stats::cmdscale()."UMAP"-Uniform manifold approximation and projection;
uwot::umap()."NMDS"-Nonmetric multidimensional scaling;
vegan::metaMDS()."tSNE"-t-distributed stochastic neighbor embedding;
Rtsne::Rtsne().
Multiple/abbreviated values allowed. Default:
"PCoA"- k
Number of ordination dimensions to return. Either
2Lor3L. Default:2L- seed
Random seed for the stochastic ordinations (NMDS, tSNE, UMAP), so that they are reproducible. PCoA is deterministic. Must be a non-negative integer. Default:
0- cpus
The number of CPUs to use. Set to
NULLto use all available, or to1to disable parallel processing. This also bounds R's linear algebra library (BLAS): whencpusis less than the number of threads that library is set to use, it runs on one thread until the call returns. See the Multithreading section of rbiom-package. Does not affect results, apart from rounding in the last digits of linear algebra (around 1e-15). Default:ecodive::n_cpus()(all available cores)- ...
Additional arguments for the
ordfunction. For tSNE,perplexitydefaults to 30, or to(n - 1) / 3for fewer than 91 samples.
Value
A tibble data.frame with columns .ord, .sample,
.x, .y, and (optionally) .z. The attribute
'axes' is a tibble with one row per axis (.ord, .axis,
.label, .var, .stress): for PCoA, .var is the percent of
the variance (the positive eigenvalues) explained by that axis and
.label reads e.g. "PCoA 1 (24.3%)"; for the other ordinations
.var is NA. For NMDS, .stress is the stress of the solution
(vegan::metaMDS()'s $stress, the same on every axis); for the
other ordinations it is NA.
See also
Other ordination:
bdiv_ord_plot(),
bdiv_ord_table()
Examples
library(rbiom)
dm <- bdiv_distmat(hmp50, "bray")
ord <- distmat_ord_table(dm, "PCoA")
head(ord)
#> # Ordination: stats::cmdscale(dm, k = 2, eig = TRUE)
#> # A tibble: 6 × 4
#> .ord .sample .x .y
#> <fct> <chr> <dbl> <dbl>
#> 1 PCoA HMP01 -0.358 0.00236
#> 2 PCoA HMP02 -0.420 0.0104
#> 3 PCoA HMP03 -0.382 0.0135
#> 4 PCoA HMP04 -0.388 0.00485
#> 5 PCoA HMP05 -0.415 -0.0115
#> 6 PCoA HMP06 -0.414 -0.00703
attr(ord, 'axes')
#> # A tibble: 2 × 5
#> .ord .axis .label .var .stress
#> <fct> <chr> <chr> <dbl> <dbl>
#> 1 PCoA .x PCoA 1 (21.6%) 21.6 NA
#> 2 PCoA .y PCoA 2 (14.7%) 14.7 NA