wrap-ord {ordr} | R 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 |
nu |
the number of left singular vectors to be computed.
This must between |
nv |
the number of right singular vectors to be computed.
This must be between |
d |
a distance structure such as that returned by |
k |
the maximum dimension of the space which the data are to be
represented in; must be in |
add |
logical indicating if an additive constant |
y |
numeric matrix ( |
xcenter |
logical or numeric vector of length |
ycenter |
analogous to |
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)