如何在R中的mids对象上运行分层的glm.nb?

问题描述

我从MICE输出一个mids对象,我需要对其运行一系列分层的负二项式模型(glm.nb())。分层变量(“压力”)本身是估算值。下面的代码将glm.nb()函数中的数据作为子集。

这是运行分层模型的正确方法吗?

library("mice") # For MI
library("MASS") # For glm.nb()

set.seed(09212020)

df <- data.frame("ethnicity" = sample(1:4,50,replace = TRUE),"education" = sample(1:4,"age" = sample(50:90,"pressure" = sample(0:12,"outcome_rate" = sample(0:6,"exposure_quart" = sample(1:4,replace=TRUE,prob=c(0.1,0.2,0.65,0.05)))


# Insert NAs for MICE
df <- as.data.frame(lapply(df,function(cc) cc[ sample(c(TRUE,NA),prob = c(0.85,0.15),size = length(cc),replace = TRUE) ]))

# Run MICE
imp <- mice(data = df,m = 2,maxit = 1)

# Attempt to run stratified model on the mids object
# This is the portion I'm seeking to have confirmed/updated
m1 <- with(imp,(glm.nb(outcome_rate ~ exposure_quart + ethnicity + education + age + pressure,subset = imp$imp$pressure < 9)))

m1

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)