[R] using poly() to predict
Prof Brian Ripley
ripley at stats.ox.ac.uk
Wed Jan 14 15:38:21 CET 2015
On 14/01/2015 14:20, Stanislav Aggerwal wrote:
> This method of finding yhat as x %*% b works when I use raw polynomials:
> y<- 1+ 1*x + .5*x^2
> yfit<-b + poly(xfit,2,raw=T) %*% b[-1]
> But it doesn't work when I use orthogonal polynomials:
> yfit<-b + poly(xfit,2) %*% b[-1]
> I have a feeling that the second version needs to incorporate poly() coefs
> (alpha and norm2) somehow. If so, please tell me how.
> I do know how to use predict() for this. I just want to understand how
> poly() works.
What matters is how lm() and predict() use poly(): see ?makepredictcall
and its code.
str(fit) might also help.
> Thanks very much for any help
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Please do, and do not send HTML.
Brian D. Ripley, ripley at stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford
1 South Parks Road, Oxford OX1 3TG, UK
More information about the R-help