I want to calculate the coefficient of determination for the cross validation of my plsr-model by hand, using Residual Sum of Squares (RSS) and Total Sum of Squares (TSS). How can I extract the predicted values from the cv-model to do this?
Here’s my code:
#install.packages("plsRglm")
library(plsRglm)
data(Cornell)
XCornell<-Cornell[,1:7]
yCornell<-Cornell[,8]
cv.modpls<-cv.plsR(Y~.,data=Cornell,nt=100,K=6)
res.cv.modpls<-cvtable(summary(cv.modpls))
res6 <-plsR(Y~.,data=Cornell, nt=10, typeVC="standard", pvals.expli=TRUE,
family = quasibinomial(link = "logit"))
And here is how I would like to calculate the R2:
residuals <- yCornell - prediction
TSS <- sum((yCornell - mean(yCornell))^2)
RSS <- sum(residuals^2)
R2 <- 1 - (RSS / TSS)
I’m not sure which of the variables labeled as something like predictor is the correct one and how to call it.