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

murdoch@stats.uwo.ca murdoch@stats.uwo.ca
Sat, 12 Jan 2002 02:08:05 +0100 (MET)


Bug in predict.lm & poly

The predict function doesn't work when used with poly and newdata.

For example, I'd expect the following code to work, and plot a fitted
cubic to the nearly straight line:

 x <- 1:10
 y <- x + rnorm(10)/100
 plot(x,y)
 fit <- lm(y ~ poly(x,3))
 newx <- seq(1,10,len=100)
 lines(newx,predict(fit,newdata=data.frame(x=newx)))

However, the plotted line is way off the data.  The problem is that
poly(x,3) doesn't agree with poly(newx,3) at equal values of x, so
predict applies the fitted coefficients to the wrong values.

To fix this we need a predict.poly procedure analogous to the
predict.ns() and predict.bs() procedures. This doesn't look easy to
write.

Duncan Murdoch

--please do not edit the information below--

Version:
 platform = i386-pc-mingw32
 arch = x86
 os = Win32
 system = x86, Win32
 status = 
 major = 1
 minor = 4.0
 year = 2001
 month = 12
 day = 19
 language = R

Windows 98 4.10 (build 1998)  

Search Path:
 .GlobalEnv, package:ctest, Autoloads, package:base


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._