[R] PBIB datataset

Douglas Bates bates at stat.wisc.edu
Mon Dec 20 23:37:56 CET 2004


(Ted Harding) wrote:
> On 20-Dec-04 Douglas Bates wrote:
> 
>>This is a new version of SASmixed that was uploaded a couple of days 
>>ago.  I changed it so that the fits are done with the lme4 version of 
>>lme.  It should be faster and more reliable than the version of lme in 
>>the nlme package.
>>
>>This version of SASmixed has a vignette that provides comparative 
>>analyses in lme for the examples in "SAS System for Mixed Models".  The
>>specification of models in the new lme is occasionally different from 
>>the older specification.  Don't pay too much attention to the textual 
>>descriptions - look at the examples in the appendices.  I haven't 
>>finished rewriting the textual description from an old, old version.
>>
>>Those who (like me) cringe at the way that models with crossed random 
>>effects needed to be specified in the old lme may find it interesting 
>>that the Demand example now specifies the model fit as
>>Demand> fm1Demand <- lme(log(d) ~ log(y) + log(rd) + log(rt) +
>>     log(rs), data = Demand, random = list(State = ~1, Year = ~1))
>>
>>[...]
>>
>>The lme4 and nlme packages should not be loaded simultaneously.
>>Use one or the other but not both.
> 
> 
> Doug,
> Thanks a lot for these clarifications. This still leaves me with
> a question or two.
> 
> Suppose I want (as I do) to work through Pinheiro & Bates, example
> by example. Some datasets are here (lme4), others there (SASmixed,
> nlme), etc.
> 
> Does this mean I need to start afresh, loading just the package
> with the dataset currently of interest?
> 
> I'm a touch confused about the distribution (a) of datasets,
> (b) of the R functions needed to analyse them according to
> Pinheiro & Bates, over the packages! If I load the package
> containing dataset A, will it include the functions used in
> P&B for that dataset? Or might I need to load another one
> as well? and, if so, might I encounter the sort of clash
> you hint at above?
> 
> (I know I could probably check it in detail in each case as
> it arises, but I guess you know your way arond all this better
> than someone who hasn't been there yet).
> 
> With thanks (and congratulations on what looks like a very
> well conceived book on the topic),
> Ted.

If you want to work through P&B you should use the nlme package. The 
only data set mentioned in the book and not available in the nlme 
package is PBIB which, as you have discovered, is in SASmixed.  The data 
sets in SASmixed (and in the lme4 package) are data frames (as opposed 
to groupedData objects).  That is, these data sets don't depend upon 
classes defined in the package.  Hence you could attach the SASmixed 
package, save the PBIB data set to a file, restart R, attach the nlme 
package and then load the PBIB data from the file that you just saved. 
Then you would have a complete set of data sets for use with the nlme 
package.

By the way, you can save yourself some typing by checking the 'scripts' 
directory in the installed package.  It contains R scripts to reproduce 
(most of) the analyses in our book.

The reason that I have to say "most of" is because the examples in the 
book were done with S-PLUS (version 3.4, I believe) and sometimes the 
results in R are different from those in S-PLUS.   These models are fit 
using numerical optimizers and the numerical optimizer code in S-PLUS is 
different from the optimizer code in R.  On this particular set of 
problems the optimizer used by ms() function in S-PLUS tends to perform 
better than the optimizers in either the nlm() or optim() functions in R.

After we finished that book I continued to work on computational methods 
for linear mixed effects models.  The lme4 package is the fruit of that 
development.  Superficially the lme function in the lme4 package looks 
very much like the one in the nlme package but internally they are very 
different.  The most obvious difference is the use of S4 classes and 
methods in lme4, as opposed to the S3 classes and methods in nlme. 
However, there are many, many other differences in the representation 
and the computational methods.

The lme4 package will eventually replace the nlme package but currently 
it does not implement nlme or gls or gnls functions so I don't want to 
replace the nlme package.  Because both these packages define an lme 
function and classes but the classes are incompatible, R will get very 
confused if you load both packages in the same session.

As mentioned above, the design of the lme function in the lme4 package 
is very different from that in the nlme package.  It is more general in 
some ways and less general in others.  The big gains are the ability to 
handle crossed and partially crossed random effects in a much cleaner 
way than could be done in the nlme package.  The lme4 package uses a 
(well actually two but I plan to reduce it to one) sparse matrix 
representation of the lme model and data that makes it possible to fit 
such models faster and more reliably than in the past.




More information about the R-help mailing list