I have a problem to determine my R-Squared value. I do a polynomial regression:
fit3 <- lm(value ~ date + I(date^2)+ I(date^3),data=training)
I have a R-Squared value (0.9416) when I do
summary(fit3)
But when I try to compute it in the testing dataset my R-Squared value is -84.20259. I don't understand why because when I plot it the results look goods.
I use 2 methods.
First one
pred.lin <- predict(fit3, newdata=testing) actual <- testing$value SS.total <- sum((actual - mean(actual))^2) SS.residual <- sum((actual - pred.lin)^2) SS.regression <- sum((actual - mean(actual))^2)
test.rsq <- 1 - SS.residual/SS.total
test.rsqAnd the second method is:
1 - sum((actual-pred.lin)^2)/sum((actual-mean(actual))^2)
Here the graph the points are the real data and the curve the model. The blue points are the testing dataset.
Can you help please? I am new in this area :)

plot(fit3)and study the four graphs it produces. – whuber Jul 24 '15 at 14:58