Skip to content

poly(*,*) in lm() (PR#8972)

2 messages · jenskeienburg at gmx.de, Bjørn-Helge Mevik

#
Full_Name: Jens Keienburg
Version: 2.3.0
OS: Windows XP
Submission from: (NULL) (193.174.53.122)


I used the function lm() to calculate the coefficients of a polynome. If I used
the function poly(t,2) to denote a polynome of form 1 + x + x^2, the
coefficients are wrong. I appended an excerpt below:
[1]   -28   -32   -32   -28   -20    -8     8    28    52    80   112   148  
188   232   280   332   388   448   512
 [20]   580   652   728   808   892   980  1072  1168  1268  1372  1480  1592 
1708  1828  1952  2080  2212  2348  2488
 [39]  2632  2780  2932  3088  3248  3412  3580  3752  3928  4108  4292  4480 
4672  4868  5068  5272  5480  5692  5908
 [58]  6128  6352  6580  6812  7048  7288  7532  7780  8032  8288  8548  8812 
9080  9352  9628  9908 10192 10480 10772
 [77] 11068 11368 11672 11980 12292 12608 12928 13252 13580 13912 14248 14588
14932 15280 15632 15988 16348 16712 17080
 [96] 17452 17828 18208 18592 18980
Call:
lm(formula = p ~ poly(t, 2))

Coefficients:
(Intercept)  poly(t, 2)1  poly(t, 2)2  
       6242        55423        14903
Call:
lm(formula = p ~ 1 + t + I(t^2))

Coefficients:
(Intercept)            t       I(t^2)  
        -20          -10            2  


Best wishes,
Jens Keienburg
#
If you take a look at the manual page for poly, you will find that
poly (by default) will calculate _orthogonal_ polynomials, which are
not the same as 1, x, x^2, etc.