Skip to content
Prev 300083 / 398506 Next

R-squared with Intercept set to 0 (zero) for linear regression in R is incorrect

What does Excel give for the following data, where the by-hand formula
you gave is obviously wrong?
   > x <- c(1, 2, 3)
   > y <- c(13.1, 11.9, 11.0)
   > M1 <- lm(y~x+0)
   > sqerr <- (y- predict(M1)) ^ 2
   > sqtot <- (y - mean(y)) ^ 2
   > 1 - sum(sqerr)/sum(sqtot)
  [1] -37.38707

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com