Eric Lim
Eric Lim

Reputation: 3

R does not recognize quadratic function in model formula?

Really simple question, I'm working through Pinheiro and Bates (nlme) on page 42 using the Pixel dataset.

library (nlme)

fm1Pixel <- lme(pixel ~ day + day^2, data=Pixel, random = list(Dog = ~ day, Side = ~ 1))

Looks straightforward enough, but the output simply does not recognise existence of day^2:

intervals (fm1Pixel)
Approximate 95% confidence intervals

Fixed effects
                lower         est.        upper

(Intercept) 1071.415261 1093.2153217 1115.0153825

day           -1.126045   -0.1486644    0.8287158

attr(,"label")

[1] "Fixed effects:"...

It works fine if I manually create a ^2 variable, but the model itself (also with simple lm()) does not recognise ^2...

Anyone else with the same problem?

Am I typing something wrongly?

Grateful for your help,

Eric

Upvotes: 0

Views: 164

Answers (1)

linog
linog

Reputation: 6226

You need to put your transformations in a I() element, like that:

 lme (pixel ~ day + I(day^2), data=Pixel, random = list(Dog = ~ day, Side = ~ 1))

Upvotes: 2

Related Questions