Numerical outputs

  • Regarding the graph provided by plotVar, how Can I get the correlation coordinate for individual variable?

Illustrating on the nutrimouse example, the code below provides the answer.

nutri.res <- rcc(X, Y, ncomp = 3, lambda1 = 0.064, lambda2 = 0.008)
bisect = nutri.res$variates$X[, 1:3] + nutri.res$variates$Y[, 1:3]
cord.X = cor(nutri.res$X, bisect, use = "pairwise")
cord.Y = cor(nutri.res$Y, bisect, use = "pairwise")
simMat = as.matrix(cord.X %*% t(cord.Y))
  • How to access the predicted class when using predict() on the result of (s)plsda?

See the script given at http://perso.math.univ-toulouse.fr/mixomics/methods/spls-da/

  • How can I get information about the part of variance explained by PLS components?

This information is not directly in the output of the functions but can be calculated as in the following:

X  ## quantitative
Y  ## vector indicating class membership
ncomp = 3
plsda.res = plsda(X, Y, ncomp = ncomp)
Rd.YvsU = cor(as.numeric(as.factor(Y)), plsda.res$variates$X[, 1:ncomp])
Rd.YvsU = apply(Rd.YvsU^2, 2, sum)
Rd.Y = cbind(Rd.YvsU, cumsum(Rd.YvsU))
colnames(Rd.Y) = c("Proportion", "Cumulative")
Rd.Y   ## percent of variance explained by each component
  • How can I calculate the coefficients of the linear combinations when using PLS?

The following code enable to do this:

data(linnerud)
X <- linnerud$exercise
Y <- linnerud$physiological[, 1:2]
linn.pls <- pls(X, Y, ncomp = 3)
pred <- predict(linn.pls, X[1:2, ])
pred$B.hat
  •  How can I calculate R2 and Q2 values for sPLS-DA?

The ‘valid’ function does not produce these values for objects of class ‘splsda’, nevertheless you can obtain these values by the following code:

X <- ... # X data
Y <- ... # Y data (factor or discrete data)
Y.mat <- unmap(Y)
res <- spls(X, Y.mat, …)
val <- valid(res, criterion = c("R2", "Q2"))
val