Hi, if I see it correctly, the nls you run is a linear model. It will
probably give you the same (or virtually identical) result as

lm(dP~U0+I(U0^2)+I(U0^3)+I(U0^4)).

Your lm model, by contrast, creates orthogonal polynomials such that all
orders of the polynomials are uncorrelated with the others. That is, there
is some transformation involved to orthogonalize the polynomials. This is
the likely reason why you see differences in your nls and your lm
specification.

Daniel

-------------------------
cuncta stricte discussurus
-------------------------
-----Original Message-----
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Benoit Boulinguiez
Sent: Tuesday, December 22, 2009 12:10 PM
To: r-help@r-project.org
Subject: [R] use of lm() and poly()

Hi all,
 
I want to fit data called "metal" with a polynominal function as dP ~ a.0 +
a.1 * U0 + a.2 * U0^2 + a.3 * U0^3 + a.4 * U0^4 The data set includes, the
independant variable U0 and the dependant variable dP.
 
I've seen that the combination of lm() and poly() can do that instead of
using the nls() function.
But I don't get how to interpret the results from the linear regression, as
the coefficients do not match the ones from the nonlinear regression
 
 
#data
metal
     U0  dP
1  0.00   0
2  0.76  10
3  1.43  20
4  2.56  40
5  3.05  50
6  3.52  60
7  3.76  70
8  4.05  80
9  4.24  90
10 4.47 100
 
#linear
     d <- seq(0, 4, length.out = 200)
     for(degree in 1:4) {
       fm <- lm(dP ~ poly(U0, degree), data = metal)
       assign(paste("metal", degree, sep="."), fm)
       lines(d, predict(fm, data.frame(U0=d)), col = degree)
     }
metal.4
Call:
lm(formula = dP ~ poly(U0, degree), data = metal)
 
Coefficients:
      (Intercept)  poly(U0, degree)1  poly(U0, degree)2  poly(U0, degree)3
poly(U0, degree)4  
           52.000            100.612             19.340              7.101
2.628 
 
 
#nonlinear
fm<-nls (dP~ a.0 + a.1*U0 + a.2*U0^2 + a.3*U0^3 + a.4*U0^4, data=metal) 

Nonlinear regression model
  model:  dP ~ a.0 + a.1 * U0 + a.2 * U0^2 + a.3 * U0^3 + a.4 * U0^4 
   data:  metal 
     a.0      a.1      a.2      a.3      a.4 
 0.02408  9.81452  5.54269 -2.24657  0.36737  residual sum-of-squares: 5.843
 
Number of iterations to convergence: 2
Achieved convergence tolerance: 1.378e-06 

 
 
 
 

Regards/Cordialement

-------------
Benoit Boulinguiez
Ph.D student
Ecole de Chimie de Rennes (ENSCR) Bureau 1.20 Equipe CIP UMR CNRS 6226
"Sciences Chimiques de Rennes"
Avenue du Giniral Leclerc
CS 50837
35708 Rennes CEDEX 7
Tel 33 (0)2 23 23 80 83
Fax 33 (0)2 23 23 81 20
 <http://www.ensc-rennes.fr/> http://www.ensc-rennes.fr/ 

 

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to