0

I have the following data:

Point chart showing polynomial curve

Which looks quadratic. If I fit a quadratic curve using I() I get coefficients that make sense:

> modelI = lm(
   formula = Y ~ I(X^2) + I(X),
   data = df
 )

> modelI
 
 Call:
 lm(formula = Y ~ I(X^2) + I(X), data = df)
 
 Coefficients:
 (Intercept)       I(X^2)         I(X)  
   4.822e-02   -4.426e-05    3.229e-05  

I fitted a quadratic curve using the same data in Excel, and got exactly the same coefficients, so this is probably correct. However, when I do the same using poly, I get completely wrong coefficients:

> modelPoly = lm(
   formula = Y ~ poly(X, degree = 2),
   data = df
 )

> modelPoly

 Call:
 lm(formula = Y ~ poly(X, degree = 2), data = df)
 
 Coefficients:
          (Intercept)  poly(X, degree = 2)1  poly(X, degree = 2)2  
             0.048067              0.002358             -0.004766  

Why is this please?

GMSL
  • 355
  • 2
  • 11
  • 3
    I suspect because `poly` uses orthogonal contrasts by default. But without data, I can't test the idea. [This post](https://stackoverflow.com/help/minimal-reproducible-example) will help you construct a *minimum reproducible example*. What happens if you try `raw=TRUE` in your call to `poly`? – Limey Sep 06 '21 at 12:37
  • Using `raw = TRUE` fixes the issue thanks. – GMSL Sep 06 '21 at 12:48
  • Your data looks extremely suspicious. For regression analysis, it is assumed that x values have no uncertainty and all uncertainty is in the y values. In your data the opposite seems to be the case. – Roland Sep 06 '21 at 12:56

1 Answers1

1

As @Limey comments on the post, the problem was orthagonal polynomials. Using raw = TRUE in poly() fixed the issue.

GMSL
  • 355
  • 2
  • 11