[R] Strange R squared, possible error
Gabor Grothendieck
ggrothendieck at gmail.com
Fri Mar 18 01:38:21 CET 2011
On Thu, Mar 17, 2011 at 8:22 PM, Berwin A Turlach
<berwin at maths.uwa.edu.au> wrote:
> G'day Gabor,
>
> On Thu, 17 Mar 2011 11:36:38 -0400
> Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
>
>> The idea is that if you have a positive quantity that can be broken
>> down into two nonnegative quantities: X = X1 + X2 then it makes sense
>> to ask what proportion X1 is of X. For example: 10 = 6 + 4 and 6 is
>> .6 of the total.
>>
>> Now, in the case of a model with an intercept its a mathematical fact
>> that the variance of the response equals the variance of the fitted
>> model plus the variance of the residuals. Thus it makes sense to ask
>> what fraction of the variance of the response is represented by the
>> variance of the fitted model (this fraction is R^2).
>>
>> But if there is no intercept then that mathematical fact breaks down.
>> That is, its no longer true that the variance of the response equals
>> the variance of the fitted model plus the variance of the residuals.
> [...]
>
> Do you have any reference to back this up, as I am somewhat surprised.
>
> I know that if there is no intercept in the model, then the residuals
> may not add to zero, but we are still doing least-squares, i.e. the
> fitted values are orthogonal to the residual vector and the variance of
> the response is the sum of the variance of the fitted model plus the
> variance of the residuals.
>
> Or am I missing something?
>
Try it on an example to convince yourself:
> fm <- lm(demand ~ Time, BOD)
> var(fitted(fm)) + var(resid(fm)) - var(BOD$demand)
[1] 3.552714e-15
>
> fm0 <- lm(demand ~ Time - 1, BOD)
> var(fitted(fm0)) + var(resid(fm0)) - var(BOD$demand)
[1] 59.28969
--
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