Skip to content
Prev 22389 / 398502 Next

polynom Fit

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

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