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 here.

  • 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
    • Why does the “explained_variance” output from the PLS-DA not decrease across components like PCA?

PLS-DA is not a PCA, as it seeks for maximal covariance between the latent components (one related to the categorical outcome Y, and one related to the X data matrix) for maximal separation of the classes indicated in Y. As a result the variance is not maximised.
In mixOmics we calculate the variance explain by each component related to each data (X or Y).

PCA on the contrary maximises the variance of the component related to the X data matrix.

>train.sol$explained_variance
$X
    comp 1     comp 2     comp 3     comp 4     comp 5
0.18812830 0.26510746 0.09529324 0.06461085 0.08046322
 
$Y
   comp 1    comp 2    comp 3    comp 4    comp 5
1.0000000 0.6355369 0.7149567 0.7287184 0.6707545
  •  How can I calculate R2 and Q2 values for sPLS-DA?

The ‘perf()’ 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) # creates a dummy matrix
res <- spls(X, Y.mat, …)
val <- perf(res, criterion = c("R2", "Q2"))
val