Re: R-alpha: R 0.14 : summary(lm(...)) dies 'terribly'

Peter Dalgaard BSA (pd@kubism.ku.dk)
02 Dec 1996 11:43:29 +0100


To: Martin Maechler <maechler@stat.math.ethz.ch>
Subject: Re: R-alpha: R 0.14 :  summary(lm(...))  dies 'terribly'
From: Peter Dalgaard BSA <pd@kubism.ku.dk>
Date: 02 Dec 1996 11:43:29 +0100
In-Reply-To: Martin Maechler's message of Mon, 2 Dec 96 10:45:45 +0100
Message-Id: <x2afrxfcq6.fsf@bush.kubism.ku.dk>

Martin Maechler <maechler@stat.math.ethz.ch> writes:

> Residual standard error: 0.6964 on 18 degrees of freedom
> Multiple R-Squared: 0.07308,  Adjusted R-squared: -0.02991 
> F-statistic: 1.419 on 1 and 18 degrees of freedom,  p-value: 0.249 
> 
> -------------
> Look at the last 2 lines! -- something seems terrbly wrong  (R2.adj < 0 !)

Nothing particularly wrong with R2.adj < 0 (except that it shows
weakness of the terminology) -- it's the relative reduction of
residual variance, which might *increase* if the predictors are poor
enough. However, it should happen if and only if the F-statistic is <
1, so something *is* rotten. The behavior is consistent with
accidentally using N rather than N - 1 DF for the empty model, and lo
and behold:

[from summary.lm]
        if (p != attr(z$terms, "intercept")) {
                ans$r.squared <- mss/(mss + rss)
                ans$adj.r.squared <- 1 - (1 - ans$r.squared) * (n/(n - p))
                ans$fstatistic <- c((mss/(p - 1))/(rss/(n - p)), p - 1, n - p)
                names(ans$fstatistic) <- c("value", "numdf", "dendf")
        }
  
Whoops. ans$adj.r.squared should read ... * (n - 1) / (n - p)

BTW. Shouldn't there be special handling of the no-intercept case?
Yes. Make that 
... * (n - attr(z$terms, "intercept")) / (n - p)

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-