[R] LMER docuentation could be improved WAS: Re: getting parts returned by lmer

Ista Zahn istazahn at gmail.com
Tue May 4 00:19:58 CEST 2010


Dear John,
The R documentation is of course not "perfect", but it is (in my
estimation) quite good. See more specific responses below, keeping in
mind that I'm actually pretty ignorant of this things myslef.

On Mon, May 3, 2010 at 4:44 PM, John Sorkin <jsorkin at grecc.umaryland.edu> wrote:
> Many thanks to both David and Ista. I think that my question regarding extracting items returned from  lmer points out a weakness of R, viz. less than perfect documentation. I know that R is written by volunteers, all of whom I cherish, yet having to ask the listserve for a question as basic as how to extract items from a function is an unfortunate happenstance, especially after one spends time reading the man page for the function.

The answer _is_ there in the documentation. The help page for lmer says

"Value
An object of class "mer", for which many methods are available. See
there for details. "

Clicking the link (in the html version) or executing ?'mer-class' at
the command prompt takes you to the page that describes the extraction
functions for objects of this class.

The man page should explain how to extract pertinent information!

Yes, it should, and it does (or at least it links you to that information).

There is even a prior standard, i.e. use names(), get the names of the
returned objects than access an item using $item notation, e.g.
fit1$coefficients for lm.

There are two current standards for R programming -- S3 and S4. lme4
follows S4 standards (I think the "4" in lme4 might actually be meant
to indicate this...). S4 objects are generally not accessed using the
$item notation.

Does anyone know whom can be asked to moify the man page? Can the
maintainer of lmer modify the function so it follows previous
standards? I ask these questions in the spirit of improving R.

I great deal of effort has gone into programming lmer to make use of
S4 classes. The author is unlikely to have any interest in porting it
back to S3.

Hope this clarifies things a bit,
Ista

> John
>
>
>
>
> John David Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)>>> Ista Zahn <istazahn at gmail.com> 5/3/2010 10:26 AM >>>
> Hi John,
> David's advice is probably sufficient, but I thought I would just add
> the following example, showing how to find out what extractor
> functions have been defined for a particular s4 class:
>
> class(fm2) #find out the class of fm2 ("mer")
> showMethods(classes="mer") # find out what methods are defined for
> objects of class "mer". Notice that one of the defined methods is
> "coef". Notice also that methods "fixef" and "ranef" are also defined.
>
> fixef(fm2) #extract fixed effect coefficients
> ranef(fm2) #extract random effects coefficients
>
> coef(fm2) #extract "coefficients" (sum of fixed and random effects).
>
> On Mon, May 3, 2010 at 10:16 AM, David Winsemius <dwinsemius at comcast.net> wrote:
>>
>> On May 3, 2010, at 9:41 AM, John Sorkin wrote:
>>
>>> R 2.10.0
>>> windows XP
>>>
>>> I am trying to get the coefficients returned from lmer. Normally I would
>>> use the names function to get the objects returned by the function. This
>>> does not work in lmer, but it does for lm:
>>
>> When you read the help page for lmer it refers your to the description of
>> "mer"-class where that help page tells you that it is an S4 object and
>> offers a wide variety of extractor method functions, including a coef
>> function. The str function would have shown you the slot names, but at your
>> level of knowledge, it would probably be safer to work with the
>> extractor/accessor functions. (I speak from sad experience. The authors of
>> that package know a lot more than either of us.)
>>
>> --
>> David.
>>>
>>> <- lmer(Reaction ~ Days + (1|Subject) + (0+Days|Subject), sleepstudy)
>>>>
>>>> names(fm2)
>>>
>>> NULL
>>>
>>>> fitlm <- lm(Reaction ~ Days, sleepstudy)
>>>> names(fitlm)
>>>
>>> [1] "coefficients"  "residuals"     "effects"       "rank"
>>> [5] "fitted.values" "assign"        "qr"            "df.residual"
>>> [9] "xlevels"       "call"          "terms"         "model"
>>>
>>> How does one know what is returned by lmer, and how does one access the
>>> various parts? I looked at the code for lmer, but at least on my level of R
>>> sophistication, the nature of the data returned in not clear.
>>>
>>> Thanks,
>>> John
>>>
>>>
>>> John David Sorkin M.D., Ph.D.
>>> Chief, Biostatistics and Informatics
>>> University of Maryland School of Medicine Division of Gerontology
>>> Baltimore VA Medical Center
>>> 10 North Greene Street
>>> GRECC (BT/18/GR)
>>> Baltimore, MD 21201-1524
>>> (Phone) 410-605-7119
>>> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>>>
>>> Confidentiality Statement:
>>> This email message, including any attachments, is for th...{{dropped:6}}
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Ista Zahn
> Graduate student
> University of Rochester
> Department of Clinical and Social Psychology
> http://yourpsyche.org
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:16}}



More information about the R-help mailing list