简体   繁体   English

来自glmer输出的优势比和置信区间

[英]Odds ratio and confidence intervals from glmer output

I have made a model that looks at a number of variables and the effect that has on pregnancy outcome. 我制作了一个模型,该模型着眼于许多变量及其对妊娠结局的影响。 The outcome is a grouped binary. 结果是分组二进制。 A mob of animals will have 34 pregnant and 3 empty, the next will have 20 pregnant and 4 empty and so on. 一群动物将有34个怀孕和3个空,接下来将有20个怀孕和4个空等等。

I have modelled this data using the glmer function where y is the pregnancy outcome (pregnant or empty). 我使用glmer函数对这些数据建模,其中y是妊娠结果(怀孕或空白)。

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

I get all the usual output with coefficients etc. but for interpretation I would like to transform this into odds ratios and confidence intervals for each of the coefficients. 我得到所有通常的系数等输出但是对于解释我想将其转换为每个系数的优势比和置信区间。

In past logistic regression models I have used the following code 在过去的逻辑回归模型中,我使用了以下代码

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

This would very nicely provide what I want, but it does not seem to work with the model I have run. 这将很好地提供我想要的东西,但它似乎不适用于我运行的模型。

Does anyone know a way that I can get this output for my model through R? 有谁知道我可以通过R为我的模型获得此输出的方式?

The only real difference is that you have to use fixef() rather than coef() to extract the fixed-effect coefficients ( coef() gives you the estimated coefficients for each group ). 唯一真正的区别是你必须使用fixef()而不是coef()来提取固定效应系数( coef()给出每组的估计系数)。

I'll illustrate with a built-in example from the lme4 package. 我将用lme4包中的内置示例进行lme4

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

Fixed-effect coefficients and confidence intervals, log-odds scale: 固定效应系数和置信区间,对数 - 赔率表:

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

(If you want faster-but-less-accurate Wald confidence intervals you can use confint(gm1,parm="beta_",method="Wald") instead; this will be equivalent to @Gorka's answer but marginally more convenient.) (如果你想要更快但更准确的Wald置信区间,你可以使用confint(gm1,parm="beta_",method="Wald") ;这相当于@ Gorka的答案,但稍微方便一些。)

Exponentiate to get odds ratios: Exponentiate得到比值比:

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

A marginally simpler/more general solution: 一个稍微简单/更通用的解决方案:

library(broom.mixed)
tidy(gm1,conf.int=TRUE,exponentiate=TRUE,effects="fixed")

for Wald intervals, or add conf.method="profile" for profile confidence intervals. 对于Wald间隔,或为配置文件置信区间添加conf.method="profile"

I believe there is another, much faster way (if you are OK with a less accurate result). 我相信还有另一种更快的方法(如果你的结果不太准确)。

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

First we get the confidence intervals for the 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 然后比值比为95%CI

print(exp(tab), digits=3)

Other option I believe is to just use package emmeans : 我认为其他选择只是使用包emmeans

library(emmeans)
data.frame(confint(pairs(emmeans(fit, ~ factor_name,type="response"))))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 绘制比值比和95%置信区间 - Plotting odds ratio's and 95% confidence intervals CLMM/CLMM2 (R) 中优势比的置信区间 - Confidence Intervals for odds ratio in CLMM/CLMM2 (R) glmer对象的预测概率的置信区间,bootMer错误 - Confidence intervals for the predicted probabilities from glmer object, error with bootMer 倾向得分匹配后二元匹配结果的优势比和 95% 置信区间 - Odds Ratio and 95% Confidence Intervals for Binary Matched Outcome after Propensity Score Matching 如何结合优势比和置信区间 - How can to combine odds ratios and the confidence intervals 使用merTools中的predictInterval()从glmer对象生成边际预测置信区间 - Generating marginal prediction confidence intervals from a glmer object using predictInterval() from merTools 如何从对数模型(glmer)中获得两组成功概率差异的轮廓置信区间? - How to obtain profile confidence intervals of the difference in probability of success between two groups from a logit model (glmer)? 使用R中的metafor包从比值比和置信区间进行荟萃分析 - Meta-analysis from odds ratios and confidence intervals, using metafor package in r 在 R 中解释来自 glmer Model 的 output 包括优势比和/或绘图数据? - Interpreting output from glmer Model in R including odds ratios and /or plotting data? Metafor 森林 plot 显示优势比的置信区间不正确 - Metafor forest plot shows incorrect confidence intervals for odds ratios
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM