Skip to content
Prev 163528 / 398506 Next

r2 for lm() with zero intercept

G'day Glenn,

On Tue, 2 Dec 2008 17:02:26 +1100
<Glenn.Newnham at csiro.au> wrote:

            
The way R does.  What else would I say. ;-)

That formula compares the variance explained by the model to the
null-model in which all covariates are removed.
I am not surprised that excel does the wrong thing; just one more
example where it misbehaves.  But I am surprised to hear that genstat
does the same, I thought that genstat was developed by
statisticians....
If you use the formula for models with an intercept on models without
an intercept then it may happen that you end up with a negative R^2.
Try to explain that to a user; that a quantity that is called R-squared
is negative.

My only gripe is that if one does something like:

	fm <- lm(Y ~ A/x - 1, data)

where A is a factor, R will handle this model as a no intercept term.
Although it has implicitly an intercept and I just choose to use this
formula since I was interested in parameterisation implied by this
formula.

But, you can always be subversive and say something like

	attributes(fm$terms)$intercept <- 1

before calling summary(fm) if you want to use the formula for models
with intercept.  Of course, in future versions (and past if you use an
older one), it would be advisable to study summary.lm first to see if
this trick will work; in R 2.8.0 it does.

Cheers,

	Berwin