3
$\begingroup$

this is a rather simple question but I noticed that the linear regression on 1 variable fitted with poly() gives different results if poly is not used. If I were to use poly() how can I convert back to the original variables?

For example:

First, define data

x = seq(50, 275, 25)
y = c(335, 326, 316, 313, 311, 314, 318, 328, 337, 345)

Now fit $y_i = \beta_0 + \beta_1 x_i + \beta_2 x_i^2 + \varepsilon_i$

Fit it on $x$ and $x^2$

m1 = lm(y~x+I(x^2))
s1 = summary(m1)

Now fit using the poly() function

m2 = lm(y~poly(x,2))
s2 = summary(m2)

s1 is

Call:
lm(formula = y ~ x + I(x^2))

Residuals:
     Min       1Q   Median       3Q      Max 
-2.75455 -1.20341 -0.00076  1.13182  2.78333 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept)  3.622e+02  3.268e+00  110.83 1.28e-12 ***
x           -6.674e-01  4.501e-02  -14.83 1.52e-06 ***
I(x^2)       2.236e-03  1.359e-04   16.45 7.48e-07 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.952 on 7 degrees of freedom
Multiple R-squared:  0.9785,    Adjusted R-squared:  0.9723 
F-statistic: 159.2 on 2 and 7 DF,  p-value: 1.461e-06

s2 is

Call:
lm(formula = y ~ poly(x, 2))

Residuals:
     Min       1Q   Median       3Q      Max 
-2.75455 -1.20341 -0.00076  1.13182  2.78333 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 324.3000     0.6174 525.262  < 2e-16 ***
poly(x, 2)1  13.4868     1.9524   6.908  0.00023 ***
poly(x, 2)2  32.1173     1.9524  16.450 7.48e-07 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.952 on 7 degrees of freedom
Multiple R-squared:  0.9785,    Adjusted R-squared:  0.9723 
F-statistic: 159.2 on 2 and 7 DF,  p-value: 1.461e-06

How can I convert s2 to s1?

$\endgroup$

1 Answer 1

4
$\begingroup$

The apparent discrepancy is due to not using the raw polynomials.

There is a difference between raw and orthogonal polynomials; check this CV post for a quick reference: Raw or orthogonal polynomial regression?.

Use m2 = lm(y ~ poly(x, 2, raw = TRUE)).

By default, raw = FALSE; for resorting to raw polynomials, explicitly make it TRUE; the result will match with that of what was done manually.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.