[R] Extracting Coefficients and Such from mle2 Output
David Winsemius
dwinsemius at comcast.net
Sun Feb 1 17:45:03 CET 2009
Let me admit at this point that I am not really sure that S4 classes
is the correct classification of such "@"-using extraction processes.
The documentation refers to "formal methods" and I don't yet have
enough knowledge to know that how tightly slots and formal classes are
linked with S4 or S3.
--
David Winsemius
On Feb 1, 2009, at 10:43 AM, David Winsemius wrote:
>
> As Ben Bolker's reply hints, our difficulty was that because we were
> insufficiently knowledgeable regarding working with S4 objects such
> as "a" and summary(a) object. Both mle2 and summary(a) produce S4
> objects which need a different set of extraction technology.
> Although I did not know it last night, I have now looked at the help
> page for "slot", followed the link to the help page for "@" labeled
> "slotOp", and found that one can use "@" in much the same way one
> uses "$".
>
> > str(summary(a))
> #Formal class 'summary.mle2' [package "bbmle"] with 3 slots
> ..@ call : language mle2(minuslogl = LL, fixed = list(xhalf = 6))
> ..@ coef : num [1, 1:4] 1.93e+01 1.71 1.13e+01 1.86e-29
> .. ..- attr(*, "dimnames")=List of 2
> .. .. ..$ : chr "ymax"
> .. .. ..$ : chr [1:4] "Estimate" "Std. Error" "z value" "Pr(z)"
> ..@ m2logL: num 60.4
>
> # So ....coef in this case is a 1 by 4 matrix and ...
>
> summary(a)@coef["ymax","Std. Error"]
>
> #yields
> #[1] 1.711541
>
> So we still have access to any of the components of an S4 object
> such as a or summary(a), if we follow the trail of their respective
> structures
> --
> David Winsemius
>
>
>
> On Feb 1, 2009, at 7:50 AM, BooBoo wrote:
>
>> I had asked this question once before about a function in the NADA
>> package, and you provided this neat response:
>>
>> [Begin quote]
>>
>> An approach that may yield somewhat more self-documenting code
>> would be to examine either the fit object or the summary object
>> with str and then to access results by extracting named elements.
>> Since I don't have the package in question, let me use the lm
>> object on its help page as an example:
>>
>> ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
>> trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
>> group <- gl(2,10,20, labels=c("Ctl","Trt"))
>> weight <- c(ctl, trt)
>> lm.D9 <- lm(weight ~ group)
>>
>> str(lm.D9)
>> str(summary(lm.D9))
>> summary(lm.D9)$coefficients
>> summary(lm.D9)$coefficients["groupTrt", "Pr(>|t|)"]
>>
>> # to get the p-value
>> > summary(lm.D9)$coefficients["groupTrt","Pr(>|t|)"]
>> [1] 0.2490232
>>
>> [End quote]
>>
>> However, this does not seem to work with mle2, and the methods you
>> suggested this time don't allow me access to the "etc" (the
>> standard error and its probability for example). Is there a way to
>> do this similar to what you suggested for lm, where I can at
>> anything reported by mle2?
>>
>> Tom
>>
>>
>> David Winsemius wrote:
>>> On Jan 31, 2009, at 9:13 PM, Tom La Bone wrote:
>>>>
>>>> The mle2 function (bbmle library) gives an example something like
>>>> the
>>>> following in its help page. How do I access the coefficients,
>>>> standard
>>>> errors, etc in the summary of "a"?
>>> ?coef
>>> ?vcov
>>> eeep. Further comment on "etc" not possible at this time. Mind
>>> reading equipment malfunction.
>
> ______________________________________________
> 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.
More information about the R-help
mailing list