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


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

  • And 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.

enter image description here

Can you help please? I am new in this area :)

  • 2
    $\begingroup$ The term "testing $R^2$" is rarely heard of. Why don't use the mean prediction error? $\endgroup$ – Zhanxiong Jul 24 '15 at 13:45
  • 1
    $\begingroup$ The crux of the problem is that polynomial regression is not an appropriate procedure for these data. This could be determined from the training data alone by (say) applying a goodness of fit test. $\endgroup$ – whuber Jul 24 '15 at 14:34
  • $\begingroup$ Even if we forget that this is probably about times series data, polynomial regression is a very bad choice if the aim is prediction outside the domain of your predictor. $\endgroup$ – Michael M Jul 24 '15 at 14:39
  • $\begingroup$ @Zhanxiong , how do you compute this R the mean prediction error? $\endgroup$ – Géraldine Jul 24 '15 at 14:53
  • $\begingroup$ @whuber, I look only about goodness of fit test I find Chi-Squared Goodness-of-Fit Test but I don't get how to perform it here... $\endgroup$ – Géraldine Jul 24 '15 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.