I have calculated a PLS model with the "PLS" package, and I want to plot the Y variance explained. I have tried looking through the variable created, but I'm unable to find anything related to it. I can however find X variance explained and total X variance. When I use the summary function on my model I do see the numbers I want, but I am unable to find out how to extract them so that I can plot them.
The perfect scenario would be if there was a default plot containing both X and Y variance explained, but I don't think there is.
library(pls)
data <- (data containing y for Y and everything else for X)
plsmodel <- plsr(y~., ncomp=10, data=data, validation="CV", scale=TRUE, segment.type="random", method="simpls")
View(plsmodel)
summary(plsmodel)
Data: X dimension: 70 19
Y dimension: 70 1
Fit method: simpls
Number of components considered: 10
VALIDATION: RMSEP
Cross-validated using 10 random segments.
(Intercept) 1 comps 2 comps 3 comps 4 comps 5 comps 6 comps 7 comps 8 comps 9 comps 10 comps
CV 315.5 148.4 121.3 110.7 115.2 114.7 116.3 126.2 145.9 143.4 144.1
adjCV 315.5 147.9 120.2 110.4 112.9 112.8 114.1 123.2 141.4 139.2 139.8
TRAINING: % variance explained
1 comps 2 comps 3 comps 4 comps 5 comps 6 comps 7 comps 8 comps 9 comps 10 comps
X 86.88 91.50 94.95 95.98 98.19 98.79 99.08 99.28 99.52 99.74
y 79.79 87.86 89.78 92.48 93.26 93.87 94.19 94.40 94.53 94.64
It is the last line of the summary I am looking for.
You can look at the summary code like this:
pls:::summary.mvr
You can get the info like this:
# X Variance
cumsum(explvar(plsmodel))
# Y Variance
drop(R2(plsmodel, estimate = "train", intercept = FALSE)$val)