R-alpha: fix for 'old' summary.lm bug

Martin Maechler (maechler@stat.math.ethz.ch)
Tue, 26 Mar 96 18:50:57 +0100


Date: Tue, 26 Mar 96 18:50:57 +0100
Message-Id: <9603261750.AA01910@>
From: Martin Maechler <maechler@stat.math.ethz.ch>
To: R-testers@stat.math.ethz.ch
Subject: R-alpha: fix for 'old'  summary.lm  bug

This fixes the "long standing" bug of summary.lm :

(but lm(.) breaks in 0.3, because  qr(.) breaks because  
	'storage.mode <-' breaks ...
Try it out with  0.2
(or just believe me....)

- Martin

--- src/rrc/lm.~1~	Fri Feb 23 04:32:28 1996
+++ src/rrc/lm	Tue Mar 26 18:45:40 1996
@@ -173,16 +173,14 @@
 	r <- resid(z)
 	f <- fitted(z)
 	w <- weights(z)
-	if(is.null(z$intercept)) {
-		stop("no intercept component")
-	}
-	else {
-		if(z$intercept) {
+  if (is.null(z$terms)) {
+    stop("invalid 'lm' object:  no terms component")
+  } else {
+    if (attr(z$terms,"intercept")) {
 			if(is.null(w)) {
 				rss <- sum(r^2)
 				mss <- sum((f-mean(f))^2)
-			}
-			else {
+      } else {
 				wok <- (w!=0)
 				u <- (sqrt(w)/sqrt(sum(w)))[wok]
 				r <- sqrt(w)*r[wok]
@@ -190,8 +188,7 @@
 				rss <- sum(r^2)
 				mss <- sum((f - sum(f*u)*u)^2)
 			}
-		}
-		else {
+    } else { #- no intercept
 			rss <- sum(r^2)
 			mss <- sum(f^2)
 		}
@@ -206,8 +203,8 @@
 	ans <- z[c("call","terms")]
 	ans$residuals <- r
 	ans$coefficients <- cbind(est, se, tval, 2*(1-pt(abs(tval),n-p)))
-	dimnames(ans$coefficients) <- list(
-		names(z$coefficients)[z$qr$pivot[p1]],
+  dimnames(ans$coefficients) <- 
+    list(names(z$coefficients)[z$qr$pivot[p1]],
 		c("Estimate", "Std.Error","t Value", "Pr(>|t|)"))
 	ans$sigma <- sqrt(resvar)
 	ans$df <- c(p, n-p, ncol(z$qr$qr))
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-