[R] LMER docuentation could be improved WAS: Re: getting parts returned by lmer
John Sorkin
jsorkin at grecc.umaryland.edu
Mon May 3 22:44:06 CEST 2010
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 man page should explain how to extract pertinent 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. 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.
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 th...{{dropped:6}}
More information about the R-help
mailing list