I am running randomForest() to fit and evaluate models using randomForest R package. The R-squared values provided by the model do not match the observed relationship between y and predicted, and if I call predict(model, x) on the training data, that provides yet another correlation/R-squared between predicted and observed values.
Here's a minimal working example.
data(iris)
model <- randomForest(Sepal.Width~., data=iris[1:4], ntree=500)
model$rsq[500] #.5447001 #line3
model$rsq[500]^.5 #.738038 #line4
cor(model$y, model$predicted) #.7391252 #line5
#generate predictions from model on training data
preds <- predict(model, newdata=iris[1:4])
#correlate predictions with observed values
cor(preds, iris$Sepal.Width) #.9264183
I am purposefully exploring non-cross-validated results because of some prior research that (inappropriately) used Random Forest this way. They reported the results from line3, but as can be seen, there are some inconsistencies here. Additionally, in the real data I'm using for my project, the difference in values between line4 and line5 are considerably larger.