Skip to content
Prev 32 / 20628 Next

Timings with SAMM, lme4, nlme

I also meant to cc: the list on this response.  Obviously I need to
work on my email skills.

---------- Forwarded message ----------
From: Douglas Bates <bates at stat.wisc.edu>
Date: Feb 1, 2007 12:39 PM
Subject: Re: [R-sig-ME] Timings with SAMM, lme4, nlme
To: Kevin Wright <kw.statr at gmail.com>
On 2/1/07, Kevin Wright <kw.statr at gmail.com> wrote:
Thanks for sending the timings, Kevin.  As Harold Doran mentioned in
his reply to you, it is best to use the control options niterEM = 0
and gradient = FALSE when fitting lmer models to large data sets. The
theory of how to calculate the gradient and how to create the ECME
step for a linear mixed model is some of the most beautiful
mathematics that I have ever done.  Unfortunately it is not very
practical mathematics because one of those calculations is the
equivalent of several hundred function evaluations on models with
large data sets.  It is much better to just let the optimizer work out
an approximation to the gradient and to skip the EM or ECME iterations
altogether.

I repeated your timings on R-forge.R-project.org, an Opteron-based
server running Debian Linux.  I enclose the results.  Once you get rid
of the ECME iterations and the gradient calculations lmer and lmer2
are in the same ballpark with a slight advantage to lmer on most of
the models.  Both functions took about a minute or less to fit models
with up to 20000 random effects to about 25000 observations, which is
not bad at all.

As you know, not all these models can be fit by lme and, as the
timings show, lme is much slower on the models that it can fit.  This
is not surprising, there has been close to a decade's worth of
development of the computational methods since lme was initially
designed.
I'm not sure if I have access to SAMM to check the timings.  Is SAMM
proprietary?  My recollection is that it is proprietary and that it is
Windows-only.  Either one of those characteristics is the kiss of
death for my wanting to use it.

Are you sure that SAMM is fitting a model with partially-crossed
random effects?  If you are only considering students and schools as
grouping factors for the random effects there will be little
difference between assuming nested random effects and correcting for
the partial crossing.  This is because there are very few students in
this study who attend more than one school.  If you considered
teachers as well as students and schools as grouping factors then you
could more easily discern the difference in model fits taking into
account the crossing or assuming that each student:teacher:school
combination is unique.
-------------- next part --------------
Random.effects        lmer   lmer2   lme
(yrs|id)+(yrs|sch)   51.203 62.640   NA
(yrs|id)+(1|sch)     14.497 22.533   NA
(1|id)+(yrs|sch)     13.449  5.188   NA
(1|id)+(1|sch)        2.540  2.056   NA
(yrs|id)              6.409  9.992 84.037
(1|id)                0.628  1.020  5.637
(yrs|sch)             0.860  0.533  3.544
(1|sch)               0.544  0.472  2.404
-------------- next part --------------
library(lme4)
data(star, package = 'mlmRev')
system.time(lmer(math ~ gr + sx + eth + cltype + (yrs|id) + (yrs|sch),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer(math ~ gr + sx + eth + cltype + (yrs|id) + (1|sch),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer(math ~ gr + sx + eth + cltype + (1|id) + (yrs|sch),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer(math ~ gr + sx + eth + cltype + (1|id) + (1|sch),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer(math ~ gr + sx + eth + cltype + (yrs|sch),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer(math ~ gr + sx + eth + cltype + (1|sch),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer(math ~ gr + sx + eth + cltype + (yrs|id),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer(math ~ gr + sx + eth + cltype + (1|id),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer2(math ~ gr + sx + eth + cltype + (yrs|id) + (yrs|sch),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer2(math ~ gr + sx + eth + cltype + (yrs|id) + (1|sch),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer2(math ~ gr + sx + eth + cltype + (1|id) + (yrs|sch),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer2(math ~ gr + sx + eth + cltype + (1|id) + (1|sch),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer2(math ~ gr + sx + eth + cltype + (yrs|sch),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer2(math ~ gr + sx + eth + cltype + (1|sch),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer2(math ~ gr + sx + eth + cltype + (yrs|id),
                 star, control = list(niterEM = 0, gradient = FALSE)))
system.time(lmer2(math ~ gr + sx + eth + cltype + (1|id),
                 star, control = list(niterEM = 0, gradient = FALSE)))
-------------- next part --------------
library(nlme)
data(star, package = 'mlmRev')
system.time(lme(math ~ gr + sx + eth + cltype, star, random = ~yrs|sch, na.action = na.omit))
system.time(lme(math ~ gr + sx + eth + cltype, star, random = ~1|sch, na.action = na.omit))
system.time(lme(math ~ gr + sx + eth + cltype, star, random = ~yrs|id, na.action = na.omit))
system.time(lme(math ~ gr + sx + eth + cltype, star, random = ~1|id, na.action = na.omit))
-------------- next part --------------

R version 2.5.0 Under development (unstable) (2007-01-31 r40628)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]
user  system elapsed 
  3.544   0.168   3.713
user  system elapsed 
  2.404   0.128   2.532
user  system elapsed 
 84.037   1.588  85.672
user  system elapsed 
  5.637   0.124   5.759
user  system elapsed 
 97.006   2.064  99.109 
-------------- next part --------------

R version 2.5.0 Under development (unstable) (2007-01-31 r40628)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]
Loading required package: Matrix
Loading required package: lattice
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
 51.203   6.944  58.218
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
 14.497   0.172  14.669
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
 13.449   0.140  13.624
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
  2.540   0.080   2.623
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
  0.860   0.064   0.925
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
  0.544   0.060   0.606
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
  6.409   0.392   6.802
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
  0.628   0.084   0.711
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
 62.640   4.204  66.843
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
 22.533   0.944  23.492
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
  5.188   0.216   5.406
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
  2.056   0.032   2.089
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
  0.533   0.032   0.565
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
  0.472   0.016   0.486
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
  9.992   0.348  10.364
+                  star, control = list(niterEM = 0, gradient = FALSE)))
   user  system elapsed 
  1.020   0.024   1.046
user  system elapsed 
204.576  13.948 218.748
Message-ID: <40e66e0b0702020545k70f87c12j3aba64866645034c@mail.gmail.com>
In-Reply-To: <40e66e0b0702011039p42add396t5d04c1a3efe73b8c@mail.gmail.com>