[R] use of lm() and poly()

Benoit Boulinguiez benoit.boulinguiez at ensc-rennes.fr
Wed Dec 23 11:08:54 CET 2009



I guess, I would somehow feel interested that someone out of my field is
trying to use the tool I daily manipulate to widen his knowledge or dig
further in his own field, though I might at some point recommend him to get
back to the basis for some concrete concepts that he wouldn't understand
sharply enough. I hope reading "Practical Regression and Anova using R" by
J.J. Faraway will help sharpening out a bit my knowledge's.
For sure though, I'd sound less scornful than you.

BTW, thank you Daniel for pointing out that I was using orthogonal
polynomials instead of regular ones.


Regards/Cordialement


Benoit Boulinguiez 


-----Message d'origine-----
De : Bert Gunter [mailto:gunter.berton at gene.com] 
Envoyé : mardi 22 décembre 2009 18:26
À : 'Benoit Boulinguiez'; r-help at r-project.org
Objet : RE: [R] use of lm() and poly()

Get some statistical consulting help or read up on these topics -- any good
textbook on regression should contain the necessary material. This has
nothing to do with nonlinear regression, so you are confused about the basic
ideas. It has nothing to do with R.

If you don't understand how the statistical tools work, you shouldn't be
using them (without help, anyway). Would you feel comfortable about me
playing in your chemistry lab based on my year of college chemistry ~45
years ago?

Bert Gunter
Genentech Nonclinical Biostatistics
 
 -----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Benoit Boulinguiez
Sent: Tuesday, December 22, 2009 9:10 AM
To: r-help at 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]]




More information about the R-help mailing list