[Rd] Bug in predict(newdata=x) with poly() (PR#1258)
ripley@stats.ox.ac.uk
ripley@stats.ox.ac.uk
Sat, 12 Jan 2002 08:49:39 +0100 (MET)
This is long-term known in S: there have been examples in V&R for years.
The S solution is predict.gam.
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.
I noticed this was still open last week, and put it on my (private) TODO
list.
On Sat, 12 Jan 2002 murdoch@stats.uwo.ca wrote:
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>
--
Brian D. Ripley, ripley@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._