On Fri, 19 Oct 2007, Ralf Goertz wrote: = > Thanks to Thomas Lumley there is another convincing example. But still > I've got a problem with it: > >> x<-c(2,3,4);y<-c(2,3,3) > >> 1-2*var(residuals(lm(y~x+1)))/sum((y-mean(y))^2) > > [1] 0.75 > > That's okay, but neither > >> 1-3*var(residuals(lm(y~x+0)))/sum((y-0)^2) > [1] 0.97076 > > nor > >> 1-2*var(residuals(lm(y~x+0)))/sum((y-0)^2) > [1] 0.9805066 > > give the result of summary(lm(y~x+0)), which is 0.9796. >
You want R> 1-sum(residuals(lm(y~x+0))^2)/sum((y-0)^2) [1] 0.9796238 It isn't var(residuals)*(n-1) but sum(residuals^2) that you want. They are not the same in a zero-intercept model, because the residuals need not have mean zero. -thomas Thomas Lumley Assoc. Professor, Biostatistics [EMAIL PROTECTED] University of Washington, Seattle ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.