本文介绍了有没有办法获得“边际效应"?来自"glmer"对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用glmer估计随机效应logit模型,我想报告自变量的边际效应.对于glm模型,包mfx可帮助计算边际效应. glmer对象是否有任何包装或功能?

I am estimating random effects logit model using glmer and I would like to report Marginal Effects for the independent variables. For glm models, package mfx helps compute marginal effects. Is there any package or function for glmer objects?

感谢您的帮助.

下面提供了一个可重现的示例

A reproducible example is given below

mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv")
mydata$rank <- factor(mydata$rank) #creating ranks
id <- rep(1:ceiling(nrow(mydata)/2), times=c(2)) #creating ID variable
mydata <- cbind(mydata,data.frame(id,stringsAsFactors=FALSE)) 
set.seed(12345)
mydata$ran <- runif(nrow(mydata),0,1) #creating a random variable

library(lme4)
cfelr <- glmer(admit ~ (1 | id) + rank + gpa + ran + gre, data=mydata ,family = binomial)
summary(cfelr)

推荐答案

以下是使用margins()软件包的方法:

Here's an approach using the margins() package:

library(margins)
library(lme4)

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

m <- margins(gm1, data = cbpp)
m

这篇关于有没有办法获得“边际效应"?来自"glmer"对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 08:47