[R] lme

Douglas Bates bates at stat.wisc.edu
Thu Jul 1 17:54:24 CEST 1999

"Peter B. Mandeville" <mandevip at uaslp.mx> writes:

> I am using rw0641. 

Thanks for identifying that.  Can you also tell us which version of
the lme library you are using?

> In my continuing quest to understand repeated measures analysis, I again
> return to lme. I exported the Potthoff and Roy data Orthodont.dat from
> S-PLUS 4.5 to avoid capture errors and ran the examples in the R help. I
> imported the data.frame with

> 	data <- read.table("Orthodont.dat",header=T)
> 	attach(data)

Those data are also available with the lme library for R.  Just use

It seems in some of your later descriptions that you are using the
data and the documentation from S-PLUS 4.0.  MathSoft incorporated
version 2.1 of the NLME library into S-PLUS 4.0.  After that Jose
Pinheiro and I did extensive revisions on the library - essentially
rewriting it from scratch - and modified many of the estimation
routines and results.  We hope that the version in NLME 3.0 for S-PLUS
is a substantial improvement over that in NLME 2.1.

The lme_3.0 package for R has the same code base as NLME 3.0 for
S-PLUS.  Not everything in 2.1 works exactly the same in 3.0.  Not
everything in NLME 3.0 for S-PLUS works in lme_3.0 for R.  I'll try to
explain some of the differences below.

> and created the objects
> 	Orthodont.fit1 <- lme(fixed=distance~age,random=~age)
> 	Orthodont.fit2 <- lme(fixed=distance~age*Sex,random=~age)
> which appear to be the R equivalent of the objects created in Pinheiro and
> Bates 1995 (lme and nlme).

I expect that they may be different from those in the 1995 document.
They should be equivalent to the objects created using the NLME 3.0
library in S-PLUS.  The NLME 3.0 library is described at

> The code
> 	fm1 <- lmList(distance~age|Subject,data)
> generated the error message
> 	Error: couldn't find function "restart"

We work from the same code base for the S-PLUS 3.4 and the R versions
of the libraries even though we call it NLME 3.0 for S-PLUS and
lme-3.0 for R.  The lme_3.0 name is to indicate that we do not, at
present, offer capabilities for nonlinear mixed-effects models in R.

The restart function is available in S-PLUS and will be available in
version 0.65 of R.  Since it is not far off for R we did not rewrite
the lmList code for the lme_3.0 library.  The lmList function should
run with R-0.65.1

> The code
> 	plot(Orthodont.fit1)
> generated the error message
> 	Error: couldn't find function "xyplot"

Again, we make extensive use of the trellis graphics functions in
S-PLUS for the display of grouped data and for assessing model fits.
At present trellis-like capabilities in R are rather limited.  I have
done a bit of playing around with coplot to try to emulate xyplot but
I have not been terribly successful.  Trellis graphics in S-PLUS is a
powerful but very complicated system.  Emulating it is not easy.

> I suppose that a graph such as appears in Pinheiro and Bates 1995 (lme and
> nlme) and in S-PLUS4 : Guide to Statistics is generated by the plot method?
> The code given in S-PLUS4 : Guide to Statistics page 285 does generate the
> graph.
> 	plot(age,distance,type="n",xlab="Age (years)",ylab="Distance (mm)")
> 	points(age[Sex=="0"],distance[Sex=="0"],type="p",pch=0)
> 	points(Age[Sex=="1"],distance[Sex=="1"],type="p",pch=5)
> 	for(i in unique(Subject))
> lines(Age[Subject==i],distance[Subject==i],type="l",lty=2)

That was the way that we produced the graphs before switching to
trellis.  You can use those kinds of calls in R.

> The function numIter doesn't function
> 	Orthodont.fit1$numIter
> produces

That's a difference between the optimizers used in S-PLUS's ms
function and the nlm function in R.  The nlm function does not return
the number of iterations or, if it does, we didn't pick up that

> Most distressing is the fact that
> 	summary(Orthodont.fit2)
> produces the same fixed effects values
> 	(Intercept) 	16.340625
> 	Age		0.784375
> 	Sex		1.032102
> 	Age.Sex		-0.0304830
> as Pinheiro and Bates 1995 (lme and nlme) but everything else is very
> distinct.

The results can be different because of changes in the ways that the
standard errors, degrees of freedom, and p-values are calculated.  We
expect that the results in the current version (NLME 3.0 for S-PLUS
and lme_3.0 for R) are more reliable.

There is an EXAMPLES file with the library that contains an analysis
of these data in R.  Did you check that?  If you get answers that are
different from that then I would be concerned.
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list