Odds ratio and confidence intervals from the result

I made a model that considers a number of variables and the effect that has on the outcome of pregnancy. The result is a grouped binary. The crowd of animals will have 34 pregnant and 3 empty, the next will have 20 pregnant and 4 empty and so on.

I modeled this data using the glmer function, where y is the outcome of the pregnancy and is empty.

 mclus5 <- glmer(y~adg + breed + bw_start + year + (1|farm), data=dat, family=binomial) 

I get all the usual output with odds, etc., but for interpretation, I would like to convert this to odds ratios and confidence intervals for each odds.

In past log reg models, I used the following code

 round(exp(cbind(OR=coef(mclus5),confint(mclus5))),3) 

Then it would be very nice, but it does not seem to work with the model I was running.

Does anyone know how I can get this output for my model through R?

thanks

+5
source share
3 answers

The only real difference is that to extract fixed effect coefficients, you need to use fixef() rather than coef() so that (t21> gives estimated coefficients for each group).

I will illustrate with the built-in example from the lme4 package.

 library("lme4") gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd), data = cbpp, family = binomial) 

Fixed effect coefficients and confidence intervals, logarithm scale:

 cc <- confint(gm1,parm="beta_") ## slow (~ 11 seconds) ctab <- cbind(est=fixef(gm1),cc) 

(If you need faster and less accurate Wald confidence intervals, you can use confint(gm1,parm="beta_",method="Wald") instead, this will be equivalent to @Gorka's answer, but a little more convenient.)

Exponential to get odds odds:

 rtab <- exp(ctab) print(rtab,digits=3) ## est 2.5 % 97.5 % ## (Intercept) 0.247 0.149 0.388 ## period2 0.371 0.199 0.665 ## period3 0.324 0.165 0.600 ## period4 0.206 0.082 0.449 
+9
source

I believe there is another, much faster way (if you are fine with a less accurate result).

From: http://www.ats.ucla.edu/stat/r/dae/melogit.htm

First we get confidence intervals for estimates

 se <- sqrt(diag(vcov(mclus5))) # table of estimates with 95% CI tab <- cbind(Est = fixef(mclus5), LL = fixef(mclus5) - 1.96 * se, UL = fixef(mclus5) + 1.96 * se) 

Then the odds ratios with 95% CI

 print(exp(tab), digits=3) 
+4
source

Another option, I believe, is simply to use the lsmeans package:

 library(lsmeans) data.frame(confint(pairs(lsmeans(fit, ~ factor_name,type="response")))) 
+1
source

Source: https://habr.com/ru/post/1204886/


All Articles