[R] polynom Fit

Rafael A. Irizarry ririzarr at jhsph.edu
Mon Aug 5 15:39:51 CEST 2002


On Mon, 5 Aug 2002, E.A. Welge wrote:

> Please, I'm a beginner with the R language. I'm looking for a function to
> compute a Polynomfit for simple x-y Data. Who can help?
> 
> Many Greetings
> E.A. Welge

if you want least squares look at the help files for "lm" and "poly".
poly creates a basis matrix for polynomials evaluated at x 
lm does least squares fitting.

here is an example:

x <- 1:100   #simulated data
y <- rnorm(100)
n <- 4      #degree of polynomial
fit1 <- lm(y~poly(x,degree=n)) ##fit to data
plot(x,y)  #examle plot
lines(x,fitted(fit1))


hope this helps,
rafael


> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help 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-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list