I am trying to follow your example from Case Study of Multilevel sPLS-DA with Vac18 dataset Multilevel Vac18 Case Study | mixOmics. I am running the code given in the example, but I get this error in R once I run the splsda():
undergo sPLS-DA after parameter tuning
final.splsda.multilevel.vac18 ← splsda(X, Y, ncomp = optimal.ncomp,
keepX = optimal.keepX,
multilevel = design)
Error in rowSums(Y) : ‘x’ must be an array of at least two dimensions.
dim(X)
[1] 42 1000
Why am I getting this error using your example code and how do I fix it?
Here is a quick fix, but it comes with limitations. You can use the withinVariation() function externally to PLS-DA to extract the X data matrix that accounts for a multilevel design. The downside is that the tuning / perf functions for a PLSDA multilevel won’t work with that trick (as we remove unique individuals during the cross-validation process in that case). I’m not sure when we will be able to resolve that bug for time constraint reasons!
Here is the code:
data(vac18) # extract the vac18 data
# using withinVariation, externally
design <- data.frame(sample = vac18$sample) # set the multilevel design
X.multilevel <- withinVariation(vac18$genes, design = design)
dim(X.multilevel)
Y <- vac18$stimulation
optimal.ncomp = 4
optimal.keepX = c(20,70,50,80)
# here, no need to specify 'design' as the multilevel decomposition has already happened in withinVariation
final.splsda.multilevel.vac18 <- splsda(X.multilevel, Y, ncomp = optimal.ncomp,
keepX = optimal.keepX)
Explanation of the bug (for future developers): What is happening with this bug is that somehow the Y matrix during the multilevel decomposition is not a matrix anymore.
Thank you for the code. It is now working! Does mixOmics allow for covariates in the splsda() function? I have searched your website but is says no results were found.