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

Marc Schwartz mschwartz at medanalytics.com
Wed May 7 15:02:04 CEST 2003


>-----Original Message-----
>From: r-help-bounces at stat.math.ethz.ch 
>[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of MARTIN
Ludovic
>Sent: Wednesday, May 07, 2003 7:02 AM
>To: r-help at stat.math.ethz.ch
>Subject: [R] [R ] Query : problems with the arithmetic 
>operator "^" withfunction "lme" and "lmList"
>
>
>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:
> 
>> fm2Oxboys.lis<-lmList(height~age+age^2,Oxboys)
>> fm2Oxboys.lis
>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.


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




More information about the R-help mailing list