I am trying to create a linear regression model. I split my data into training and testing data, and built a model. The $R^2$ value on the training data is 0.840. Then I ran the model on the test data. When I calculate the $R^2$, I get 0.982:
y.predicted <- predict(lm1, newdata=test) y.actual <- donation_test$yval errors <- (y.actual - y.predicted) 1 - sum(errors^2)/sum(y.actual^2)  0.9823576
What I am doing wrong? It seems very unlikely that my model fits my test data better than my training data.