Refitting a sPLS model and negative loadings

I am trying to fit a sPLS model to my data (regression mode). I use spls with a larger number of components and then I use perf to select the best parameter. It seems that 1 component is sufficient (judging from the Q2 values). Now I should re-fit the model using this number: if I do so, and I try to use plotVar, I get the following message error:

Error: Each element of 'comp' must be positive <= 1.
3.
stop("Each element of 'comp' must be positive <= ", min(object$ncomp), ".", call. = FALSE)
2.
mixOmics::plotVar(pls.results, legend = TRUE, title = "Variable plot") at multivariate_analysis.R#166
1.
plot.pls(res.spls.simple, perf.spls.simple)

What am I doing wrong?

Is there a way to automatically re-fit the model using the best value of ncomp? Moreover, if I want to compute for instance the Q2 or any other metric, why can I do that only on the results of perf and not spls? Thanks.

Hi @lorenzoF92,

Please note that plotVar requires at least 2 components. When 1 component is sufficient, we don’t typically shy away from using 2 for better visualisation.

Q2 (and other performance) metrics are calculated during cross-validation (i.e. when we have train and test data). A spls model does not perform cross-validation. Hence, it is not possible to calculate such metrics.

Hope it helps,

Al

1 Like

Okay, thanks. One last thing: is it possible to automatically refit the entire model using the selected best parameters (like sk-learn does)?