[R-sig-ME] Multi-level models Odds ratio
Andy Fugard (Work)
andy.fugard at sbg.ac.at
Thu Apr 8 12:48:30 CEST 2010
Here's another example, borrowed from the help for "lmer":
> gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
family = binomial, data = cbpp)
As you say, coef works:
> coef(gm1)
$herd
(Intercept) period2 period3 period4
1 -0.8085096 -0.9923347 -1.128675 -1.580374
2 -1.6974292 -0.9923347 -1.128675 -1.580374
3 -0.9922697 -0.9923347 -1.128675 -1.580374
4 -1.3592525 -0.9923347 -1.128675 -1.580374
5 -1.5885461 -0.9923347 -1.128675 -1.580374
6 -1.7987950 -0.9923347 -1.128675 -1.580374
7 -0.5091313 -0.9923347 -1.128675 -1.580374
8 -0.7991613 -0.9923347 -1.128675 -1.580374
9 -1.6361848 -0.9923347 -1.128675 -1.580374
10 -1.9394614 -0.9923347 -1.128675 -1.580374
11 -1.4831632 -0.9923347 -1.128675 -1.580374
12 -1.4633469 -0.9923347 -1.128675 -1.580374
13 -2.0884474 -0.9923347 -1.128675 -1.580374
14 -0.4278151 -0.9923347 -1.128675 -1.580374
15 -1.9290041 -0.9923347 -1.128675 -1.580374
But note the "$herd" bit. Since this model has a varying intercept by
herd, you get a column in the resulting data frame called "herd".
So you could try, for this example:
> exp(coef(gm1)$herd)
(Intercept) period2 period3 period4
1 0.4455216 0.3707102 0.3234614 0.2058981
2 0.1831538 0.3707102 0.3234614 0.2058981
3 0.3707343 0.3707102 0.3234614 0.2058981
4 0.2568527 0.3707102 0.3234614 0.2058981
5 0.2042223 0.3707102 0.3234614 0.2058981
6 0.1654982 0.3707102 0.3234614 0.2058981
7 0.6010174 0.3707102 0.3234614 0.2058981
8 0.4497060 0.3707102 0.3234614 0.2058981
9 0.1947215 0.3707102 0.3234614 0.2058981
10 0.1437814 0.3707102 0.3234614 0.2058981
11 0.2269188 0.3707102 0.3234614 0.2058981
12 0.2314603 0.3707102 0.3234614 0.2058981
13 0.1238793 0.3707102 0.3234614 0.2058981
14 0.6519320 0.3707102 0.3234614 0.2058981
15 0.1452928 0.3707102 0.3234614 0.2058981
Since the slopes don't vary by herd, you might also want just the fixed
effects:
> exp(fixef(gm1))
(Intercept) period2 period3 period4
0.2469585 0.3707102 0.3234614 0.2058981
HTH,
Andy
E T wrote:
> If I use the command coef(model) this extracts the coefficients in the
> model, however if I try exp(coef(model)) I receive an error:
>
> Error in exp(coef(model)) : Non-numeric argument to mathematical function
>
> I could manually get the exp of each factor in my model..... but as I have a
> large model (and also have numerous other models to produce), I was
> wondering if there was an automated method
>
> Regards
>
> Et
>
> On Thu, Apr 8, 2010 at 11:27 AM, E T <2nuzzbot at gmail.com> wrote:
>
>> odds.ratios = exp(coefs(model))
>>
>> Thanks, however unfortunately when I try the above command I receive the
>> following error:
>>
>> Error: could not find function "coefs"
>>
>> Regards
>>
>> Et
>>
>>
>>
>>
>> On Wed, Apr 7, 2010 at 5:47 PM, Daniel Ezra Johnson <
>> danielezrajohnson at gmail.com> wrote:
>>
>>> something like odds.ratios = exp(coefs(model))
>>>
>>>
>>> On Apr 7, 2010, at 12:28 PM, E T <2nuzzbot at gmail.com> wrote:
>>>
>>> Hi all,
>>>> Apologies for the simplicity of my question.... however any advice is
>>>> greatly appreciated. Thanks
>>>>
>>>> Is there a specific command available to obtain the odds ratios produced
>>>> from a multilevel logistic model?
>>>>
>>>> I have estimated a multi-level logistic model using the lme4 package. I
>>>> can
>>>> obtain results using the 'summary' command, however I would like to
>>>> obtain
>>>> the computed odds ratios.
>>>> (Similar to the output that can be produced for logistic GLM using the
>>>> logistic.display command from the epicalc package).
>>>>
>>>> [[alternative HTML version deleted]]
>>>>
>>>> _______________________________________________
>>>> R-sig-mixed-models at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>>>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
--
Andy Fugard, Postdoctoral researcher, ESF LogICCC project
"Modeling human inference within the framework of probability logic"
Department of Psychology, University of Salzburg, Austria
http://www.andyfugard.info
More information about the R-sig-mixed-models
mailing list