Skip to content

[R ] Query : problems with the arithmetic operator "^" with function "lme" and "lmList"

2 messages · MARTIN  Ludovic, Marc Schwartz

#
Dear all,

I've got a problem in including square variables in lme and lmlist 
functions. I've tried to work on Oxboys data of Pinheiro and 
Bates'book, which consist of the heights of 26 boys, each mesured on 
nine different occasions :

 > Oxboys
Grouped Data: height ~ age | Subject
    Subject     age height Occasion
1         1 -1.0000 140.50        1
2         1 -0.7479 143.40        2
3         1 -0.4630 144.80        3
4         1 -0.1643 147.10        4
5         1 -0.0027 147.70        5
...

A quadratic model in "age" would be fit with lmList
(height~age+age^2,Oxboys).

We obtain:
Call:
  Model: height ~ age + age^2 | Subject 
   Data: Oxboys 

Coefficients:
   (Intercept)      age
10    130.2616 3.722915
26    137.9927 5.588783
25    139.2105 4.024081
9     138.1369 6.009057
2     142.8584 5.440176
...
19    164.5761 9.065620
4     165.0724 9.360561

Degrees of freedom: 234 total; 182 residual
Residual standard error: 0.6598878

They are not coefficients associated with the covariate "age^2" ! 
However, the model called is " Height~age+age^2 | Subject " .

I would be grateful if anyone could help me.

Cordially,

Martin Ludovic.
#
Ludovic
Respecify your model formula as:

fm2Oxboys.lis<-lmList(height ~ age + I(age^2),Oxboys)

Note the use of I() around the "age^2", which enables R to interpret
the transformation of age squared properly.

See:

?formula and ?I

Hope that helps.

Marc Schwartz