# Output of coef() function in R

I'm trying to model a simple system, with data:

zoom    FOV
0       48.00069715
4000    30.9484929
8000    18.73417224
12000   9.690813595
16000   4.286154297


Doing

> model.lin = lm(data = zFOV, formula = FOV ~ zoom)
> coef(model.lin)


gives a reasonable

 (Intercept)         zoom
44.069419039 -0.002717169


which I interpret as $\small FOV = 44 -0.0027*zoom$

However

> model.poly = lm(data = zFOV, formula = FOV ~ poly(zoom,2))
> coef(model.poly)


gives

   (Intercept) poly(zoom, 2)1 poly(zoom, 2)2
22.33207      -34.36977        7.07335


Which I understand to mean $\small FOV = 22.3 - 34.4 * zoom + 7.07 * zoom^2$, which gives complete garbage.

What am I misunderstanding here?

• – whuber
Sep 18, 2015 at 14:43

To get what you want, you can type

poly(zoom, 2, raw = TRUE)


Without the raw = TRUE option, R orthogonalizes and normalizes the basis polynomials. This has some advantages (e.g. in studying p values, numerical stability) but also, as you recognized, the disadvantage of complicated interpretation of coefficients.

• To get the advantages of orthogonal polynomials with simplified interpretation you need to convert coefficients from orthogonal to raw form. I gave an inelegant function to do that job here stackoverflow.com/questions/31457230/… Sep 18, 2015 at 15:05
• That is very useful! Sep 18, 2015 at 15:30

One easy way to do this is to define our own quadratic term and just use the lm function directly on that

zoom <- c(0,4000,8000,12000,16000)
FOV <- c(48.00069715,30.9484929,18.73417224,9.690813595,4.286154297)

plot(zoom,FOV)

datFr <- data.frame('FOV'=FOV,'zoom'=zoom, 'zoom2'=zoom^2)

model.lin = lm(data = datFr, formula = FOV ~ zoom+zoom2)
coefs <- coef(model.lin)

predVecX <-seq(min(zoom),max(zoom),len=100)
predVecY <- coefs+coefs*predVecX+coefs*predVecX^2

plot(zoom,FOV)
lines(predVecX,predVecY,col='red') 