[Rd] Bug in predict(newdata=x) with poly() (PR#1258)

dmurdoch@pair.com dmurdoch@pair.com
Sat, 12 Jan 2002 16:25:35 +0100 (MET)

On Sat, 12 Jan 2002 07:49:01 +0000 (GMT), you wrote:

>predict.poly is easy. The problem (as for bs and ns) is getting it used by
>predict.lm.  Thomas Yee (I think) has made a solution available, but the
>consensus was that it could be done more elegantly at a lower level.  We
>already preserve information on contrasts and sets of levels: we need to
>preserve similar information for poly() and spline terms.

Yes, I didn't notice that predict.bs wasn't being called by

>I noticed this was still open last week, and put it on my (private) TODO

A short-term workaround would be to put code like this into
predict.lm, at the point where tt contains the terms of the fit, and
it has been determined that newdata is not missing:

  if (any(c('poly','bs','ns') %in% flatten(tt)))          
     warning("newdata not supported with 'poly', 'ns', or 'bs'")

I don't know if there's already a function like flatten in R; here's a
simple one:

flatten <- function (expr) 
  if (is.expression(expr) | is.call(expr) | is.list(expr)) {
    unlist(lapply(as.list(expr), flatten))
  } else {

There may be other functions besides poly, bs and ns that return
bases; I don't know.

Duncan Murdoch

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