Simplified version of pls::mvr, using computationally faster versions of PCA and PLS.

mvr(
  X,
  Y,
  ncomp,
  method = c("PCA", "PLS"),
  center = TRUE,
  sparse = FALSE,
  scale = FALSE,
  DRinfo = FALSE,
  keepComps = seq_len(ncomp)
)

Arguments

X

Matrix (dense or sparse).

Y

Matrix.

ncomp

Integer.

method

Character.

center

Logic.

sparse

Not used; kept for backward compatibility.

scale

Logic.

DRinfo

Logic. Whether to return dimension reduction information from PCA or PLS. Disable to save memory.

keepComps

Integer vector. Numbers of components for which to return regression coefficients. The default returns all, 1:ncomp. Use keepComps = ncomp to return only the final coefficients and save memory.

Value

A list containing

coefficients

Array of regression coefficients with dimensions features x responses x length(keepComps). The third dimension is named "<k> comps", so coefficients[, , paste(ncomp, "comps")] selects the coefficients for ncomp components.

Xmeans
Ymeans
ncomp
method

Details

A sparse X (for example a dgCMatrix) stays sparse: centring and scaling are applied implicitly, without a dense copy of X. PLS uses the kernel algorithm of pls::kernelpls.fit.

Examples

set.seed(1)
X <- matrix(rnorm(100 * 20), 100, 20)
Y <- X[, 1:3] %*% matrix(rnorm(9), 3, 3) + matrix(rnorm(300, sd = 0.1), 100, 3)
fit <- mvr(X, Y, ncomp = 3, method = "PLS")
dim(fit$coefficients)