[R-sig-ME] Extracting means and SEs from an lmer object

Douglas Bates bates at stat.wisc.edu
Thu Feb 9 17:45:56 CET 2012


On Mon, Feb 6, 2012 at 5:29 PM, Kevin Wright <kw.stat at gmail.com> wrote:
> Doug,

> Relating to your comment below, there are getting to be quite a few R
> packages that fit mixed models in various forms.

> I have found myself often wishing that there was a generic 'fixef' and
> 'ranef' in the 'stats' package (similar to 'coef') to make it easier to work
> with different methods for these extractors.  The different class systems
> (S3, S4), different packages, and ever-changing R core (e.g. mandatory
> namespaces) have forced me to write and re-write multiple times the methods
> for fixef and ranef to support different packages.

> Any thoughts on this?

In lme4Eigen S3 methods are used even for S4 classes when method
dispatch is on the first argument only, which is the case for most
standard generics.  This avoids the problem of reconciling S4 generics
and S3 generics, which can get very complicated if more than one
package defines an S4 generic from the same S3 generic.  The majority
of the S3 generics are in the stats package, which is fine because the
stats package is usually attached.  As the nlme package is a
recommended package, it is assumed to be available but not always
loaded or attached.  I have opted for importing the S3 generics for
"fixef" and "ranef" and "VarCorr" from the nlme package but not
depending on the nlme package, which makes life too complicated.  The
generic is imported then exported and the method is declared in the
NAMESPACE file.  In other words, the NAMESPACE file has

importFrom(nlme, fixef)
export(fixef)
S3method(fixef,merMod)

and the same for ranef and VarCorr.  Right now that is the way that I
would recommend other package authors to handle the situation.  I'm
not sure if loading two such packages will give complaints about
masking the names - it may.

Eventually it might be best to move these generics to the stats
package.  Due to my own error I cannot currently change either the
stats package or the nlme package so I will need to wait for Martin to
return from vacation before making any changes.



>> The problem may be due to MEMSS bringing in other packages that mask
>> the definition of fixef in lme4.  It works for me (see enclosed) if I
>> use
>> data(Orthodont, package="MEMSS")
>> instead.
>
>




More information about the R-sig-mixed-models mailing list