wrap-ord: Wrappers for lossy ordination methods

wrap-ordR Documentation

Wrappers for lossy ordination methods

Description

These ⁠*_ord⁠ functions wrap core R functions with modifications for use with 'tbl_ord' methods. Some parameters are hidden from the user and set to settings required for these methods, some matrix outputs are given row or column names to be used by them, and new '*_ord' S3 class attributes are added to enable them.

Usage

eigen_ord(x, symmetric = isSymmetric.matrix(x))

svd_ord(x, nu = min(dim(x)), nv = min(dim(x)))

cmdscale_ord(d, k = 2, add = FALSE)

cancor_ord(x, y, xcenter = TRUE, ycenter = TRUE, scores = FALSE)

Arguments

x

a numeric or complex matrix whose spectral decomposition is to be computed. Logical matrices are coerced to numeric.

symmetric

if TRUE, the matrix is assumed to be symmetric (or Hermitian if complex) and only its lower triangle (diagonal included) is used. If symmetric is not specified, isSymmetric(x) is used.

nu

the number of left singular vectors to be computed. This must between 0 and n = nrow(x).

nv

the number of right singular vectors to be computed. This must be between 0 and p = ncol(x).

d

a distance structure such as that returned by dist or a full symmetric matrix containing the dissimilarities.

k

the maximum dimension of the space which the data are to be represented in; must be in \{1, 2, \ldots, n-1\}.

add

logical indicating if an additive constant c* should be computed, and added to the non-diagonal dissimilarities such that the modified dissimilarities are Euclidean.

y

numeric matrix (n \times p_2), containing the y coordinates.

xcenter

logical or numeric vector of length p_1, describing any centering to be done on the x values before the analysis. If TRUE (default), subtract the column means. If FALSE, do not adjust the columns. Otherwise, a vector of values to be subtracted from the columns.

ycenter

analogous to xcenter, but for the y values.

scores

Logical; whether to return canonical scores and structure correlations.

Details

The following table summarizes the wrapped functions:

Original function Hide params New params Add names New class
base::eigen() Yes No Yes Yes
base::svd() Yes No Yes Yes
stats::cmdscale() Yes No No Yes
stats::cancor() No Yes No Yes

By default, cancor_ord() returns the same data as stats::cancor(): the canonical correlations (cor), the canonical coefficients (⁠$xcoef⁠ and ⁠$ycoef⁠), and the variable means (⁠$xcenter⁠, ⁠$ycenter⁠). If scores = TRUE, then cancor_ord() also returns the scores ⁠$xscores⁠ and ⁠$yscores⁠ calculated from the (appropriately centered) data and the coefficients and the intraset structure correlations ⁠$xstructure⁠ and ⁠$ystructure⁠ between these and the data. These modifications are inspired by the cancor() function in candisc, though two caveats should be noted: First, the canonical coefficients (hence the canonical scores) are scaled by n - 1 compared to these, though the intraset structure correlations are the same. Second, the interset structure correlations are not returned, as these may be obtained by conferring inertia unto the intraset ones.

Value

Objects slightly modified from the outputs of the original functions, with new '*-ord' classes.

Examples

# glass composition data from one furnace
glass_banias <- subset(
  glass,
  Context == "L.15;B.166",
  select = c("SiO2", "Na2O", "CaO", "Al2O3", "MgO", "K2O")
)
# eigendecomposition of a covariance matrix
(glass_cov <- cov(glass_banias))
eigen_ord(glass_cov)
# singular value decomposition of a data matrix
svd_ord(glass_banias)
# classical multidimensional scaling of a distance matrix
cmdscale_ord(dist(glass_banias))

# canonical correlation analysis with trace components
glass_banias_minor <- subset(
  glass,
  Context == "L.15;B.166",
  select = c("TiO2", "FeO", "MnO", "P2O5", "Cl", "SO3")
)
# impute half of detection threshold
glass_banias_minor$TiO2[[1L]] <- 0.5
cancor_ord(glass_banias, glass_banias_minor)

# calculate canonical scores and structure correlations
glass_cca <-
  cancor_ord(glass_banias[, 1:3], glass_banias_minor[, 1:3], scores = TRUE)
# scores
glass_cca$xscores
# intraset correlations
glass_cca$xstructure
# interset correlations
glass_cca$xstructure %*% diag(glass_cca$cor)

corybrunson/ordr documentation built on Feb. 15, 2024, 9:28 p.m.