Reputation: 8856
I'm just wondering how to access the percentage of variation explained and cross-validated test error after using a PCR regression. I've looked at the documentation for summary.mvr, but I think I must be missing something. Is there an easy way to do it? For example:
library(MASS)
boston = Boston
pcr.fit = pcr(crim ~ ., data = boston, scale = TRUE, validation = "CV")
summary(pcr.fit)
Data: X dimension: 506 13
Y dimension: 506 1
Fit method: svdpc
Number of components considered: 13
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
CV 8.61 7.174 7.178 6.722 6.703 6.717 6.727 6.729 6.603 6.611
adjCV 8.61 7.173 7.177 6.719 6.699 6.715 6.723 6.724 6.598 6.607
10 comps 11 comps 12 comps 13 comps
CV 6.624 6.643 6.569 6.498
adjCV 6.619 6.635 6.561 6.490
TRAINING: % variance explained
1 comps 2 comps 3 comps 4 comps 5 comps 6 comps 7 comps 8 comps 9 comps 10 comps
X 47.70 60.36 69.67 76.45 82.99 88.00 91.14 93.45 95.40 97.04
crim 30.69 30.87 39.27 39.61 39.61 39.86 40.14 42.47 42.55 42.78
11 comps 12 comps 13 comps
X 98.46 99.52 100.0
crim 43.04 44.13 45.4
I would simply just like to access the percentage of variation explained for the predictors and crim. Is there an easy way to do this?
Thank you for all your help!
Vincent
Upvotes: 1
Views: 939
Reputation: 4154
For anyone else who stumbles upon this question, here's the command (post pcr command as in the initial question) that worked for me to plot the number of components against the total explained variation.
validationplot(pcr.fit, val.type = "R2")
Upvotes: 0
Reputation: 21443
To get the percentage of variation explained for each predictors, you can use:
cumsun(explvar(pcr.fit))
For the cross-validated test errors, you can maybe look at the MSEP
function.
Also if in this case you can use getS3method("summary","mvr")
to see the code of the summary function and figure out how to get the values you need from there.
Upvotes: 1