[R] lm without intercept, false R-squared

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jun 27 15:44:27 CEST 2012


On Wed, Jun 27, 2012 at 4:36 AM, Christof Kluß <ckluss at email.uni-kiel.de> wrote:
>
> for example the same model with intercept R² = 0.6, without intercept R²
> = 0.9 and higher. In my definition of R², R² has to be equal or less
> without intercept
>
> I do not know what R shows, but in the summary of the model without
> intercept it does not show the R² of the regression line.
>
> When I run a regression I like to have the R² of the regression line and
> not something else. ;)
>

If we use a baseline with no intercept in the R^2 definition then
adding the intercept will always improve the R^2 or at least not make
the R^2 worse.  The following r.squared.0 function defines such an
R^2. It will agree with the R^2 produced by R when used with models
having no intercept but will give a different R^2 value for models
with an intercept.

  r.squared.0 <- function(fm) c(1 / (1 + crossprod(resid(fm)) /
crossprod(fitted(fm))))

  fm1 <- lm(demand ~ Time, BOD)
  fm0 <- lm(demand ~ Time-1, BOD)

  r.squared.0(fm0)
  r.squared.0(fm1) # adding intercept increases r.squared.0

  # for comparison
  # summary(fm0) uses same defn as r.squared.0
  # but summary(fm1) does not

  summary(fm0)$r.squared # does agree with ours
  summary(fm1)$r.squared # does not agree with ours

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list