Extract contribution weight from PLSDA

Dear Mixo Team
I’m interested to obtain the weight of each loadings in respective Class of my PLSDA model
I’ve encountered an issue for extracting feature weight from the PLSDA:

VIP.plot<-plotLoadings(splsda.mushroom, 
             comp = 1,
             method = 'mean', 
             plot = TRUE,
             contrib = 'max')

provide the desired plot
while

Weight <- (plotLoadings(splsda.mushroom, method = "mean", plot = FALSE,contrib = "max"))

gives an error:

'names' attribute [1] must be the same length as the vector [0]

Thanks for your help
G.

I am not sure, but your code os dfferent from the first one. You have the line in parenthesis. Did you try without it?

Sorry for the mistake,
but these parentheses have no influence on this error:

contrib.1 <- plotLoadings(splsda.mushroom, comp = 1, method = "mean", plot = FALSE, contrib = "max")
Error in names(contrib.df) <- block : 
  'names' attribute [1] must be the same length as the vector [0]

hi @guikoool ,
that is weird indeed. If the plot = TRUE is not working either, we would need to debug this (alas we have no software developer at the moment).
You can directly extract the loading weights from the selectVar() function (the output may also give some indications on what is potentially going wrong in the output or the way sPLS-DA has been run).

Kim-Anh

Thanks for your reply
“selectVar” and “vip” as weel as “plotloading” (if plot = TRUE) works well
Still, the main advantage of “plotloadings” function is the “groupcontrib” column compare to “vip’” or “selectvar”. It was my interest to extract this specific column.
G.

@guikoool I had a look at your code again and my feeling is that you dont need to put plot = TRUE.

Here is an example for a SPLSDA

data(liver.toxicity)
X = as.matrix(liver.toxicity$gene)
Y = as.factor(paste0('treatment_' ,liver.toxicity$treatment[, 4]))

splsda.liver = splsda(X, Y, ncomp = 2, keepX = c(20, 20))

# contribution on comp 1, based on the median.
# Colors indicate the group in which the median expression is maximal
output = plotLoadings(splsda.liver, comp = 1, method = 'median', contrib = "max")
output

Without reproducible code and data from you, we won’t be able to help further

Kim-Anh

Dear Kim
you’re right, removing the “plot” argument solved the issue!!
Thanks again
G.