[R] poly() in lm() leads to wrong coefficients (but correct residuals)
Andreas Neumann
Andreas.Neumann at em.uni-karlsruhe.de
Wed Jun 29 18:19:07 CEST 2005
Dear all,
I am using poly() in lm() in the following form.
1> DelsDPWOS.lm3 <- lm(DelsPDWOS[,1] ~ poly(DelsPDWOS[,4],3))
2> DelsDPWOS.I.lm3 <- lm(DelsPDWOS[,1] ~ poly(I(DelsPDWOS[,4]),3))
3> DelsDPWOS.2.lm3 <-
lm(DelsPDWOS[,1]~DelsPDWOS[,4]+I(DelsPDWOS[,4]^2)+I(DelsPDWOS[,4]^3))
1 and 2 lead to identical but wrong results. 3 is correct. Surprisingly
(to me) the residuals are the same (correct) in all cases although the
coefficients of 1 (and 2) are wrong and do not in any way match the
stated regression polynomial. (summaries below)
QUESTION:
Is there a correct way to use poly() in lm() since version 3 becomes quite
tedious if used more often especially with higher order polynomials?
I am using R Version 1.9.0 (2004-04-12).
Thank you for your time,
Andreas Neumann
SUMMARIES:
> summary(DelsDPWOS.lm3)
Call:
lm(formula = DelsPDWOS[, 1] ~ poly(DelsPDWOS[, 4], 3))
Residuals:
1 2 3 4 5 6 7 8
-0.11414 0.12756 -0.21060 0.04636 -0.03244 0.16030 0.04290 -0.03944
9
0.01949
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.33333 0.04861 27.430 1.21e-06 ***
poly(DelsPDWOS[, 4], 3)1 -1.27464 0.14583 -8.741 0.000325 ***
poly(DelsPDWOS[, 4], 3)2 0.27483 0.14583 1.885 0.118175
poly(DelsPDWOS[, 4], 3)3 0.11590 0.14583 0.795 0.462774
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
Residual standard error: 0.1458 on 5 degrees of freedom
Multiple R-Squared: 0.9416, Adjusted R-squared: 0.9065
F-statistic: 26.86 on 3 and 5 DF, p-value: 0.001645
> summary(DelsDPWOS.2.lm3)
Call:
lm(formula = DelsPDWOS[, 1] ~ DelsPDWOS[, 4] + I(DelsPDWOS[,
4]^2) + I(DelsPDWOS[, 4]^3))
Residuals:
1 2 3 4 5 6 7 8
-0.11414 0.12756 -0.21060 0.04636 -0.03244 0.16030 0.04290 -0.03944
9
0.01949
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.486 7.242 -0.205 0.846
DelsPDWOS[, 4] 8.640 14.161 0.610 0.568
I(DelsPDWOS[, 4]^2) -6.526 8.799 -0.742 0.492
I(DelsPDWOS[, 4]^3) 1.375 1.730 0.795 0.463
Residual standard error: 0.1458 on 5 degrees of freedom
Multiple R-Squared: 0.9416, Adjusted R-squared: 0.9065
F-statistic: 26.86 on 3 and 5 DF, p-value: 0.001645
More information about the R-help
mailing list