Just a short reminder / question -- We've had one posting>> Date: Sun, 17 Aug 1997 19:51:20 -0700 >> From: Kung-Sik Chan <kchan@stat.uiowa.edu> >> To: r-help@stat.math.ethz.ch >> Subject: R-beta: bug reportwith a predict.default that would "work" with (some) lm objects, and I think it was said that predict.lm "is being" written (Peter Dalgaard, Ross Ihaka ?) because it was urgently needed. We haven't seen any code posting since, and I just wondered about the current state of the affair. Maybe some predict.lm(.) could be posted in order to be discussed and polished ... -- Martin =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Martin Maechler <maechler@stat.math.ethz.ch> writes:> > Just a short reminder / question -- > > We've had one posting > >> Date: Sun, 17 Aug 1997 19:51:20 -0700 > >> From: Kung-Sik Chan <kchan@stat.uiowa.edu> > >> To: r-help@stat.math.ethz.ch > >> Subject: R-beta: bug report > > with a predict.default that would "work" with (some) lm objects, > and I think it was said that predict.lm "is being" written > (Peter Dalgaard, Ross Ihaka ?) > because it was urgently needed. > > We haven't seen any code posting since, and I just wondered about the > current state of the affair. > > Maybe some predict.lm(.) could be posted in order to be discussed and > polished ...I think Ross has the version that is closest to the real thing... -- 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-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Here is my (incomplete) version. This will work for full-rank models, and I suspect also for singular models (the comment is just a reminder to myself that I was thinking about this). I set out to change the underlying structure so that case names would be propagated through to to the fitted values. This doesn't happen at the moment because they are not handled within "model.matrix". A quick fix would be to replace dimnames(x) below by row.names(mf). There is no computation of standard errors below, but the present version has something like the right computation. Sorry that this is just a hint, but I'm really under pressure at present. Anyone got any (applied) exam questions on linear models or glms handy? Ross predict.lm <- function (fit, newdata) { mf <- model.frame(formula(fit), data = newdata) # recreate the design matrix x <- model.matrix(terms(fit), mf) # grab the coefficients (order is correct?) b <- coef(fit) b[is.na(b)] <- 0 # compute predictions p <- x %*% b # attach name information if(is.matrix(b)) { dimnames(p) <- list(dimnames(x)[[1]], dimnames(b)[[2]]) } else { p <- as.vector(p) names(p) <- dimnames(x)[[1]] } p } =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-