拟合几个零膨胀的negbin模型并得到汇总结果

问题描述 投票:0回答:0

我有一个包含患者数据的数据集。一些患者在医院有多次住院,但为了观察是独立的(我尝试了一个多层次模型,但这个数据不可能)我创建了一个数据集,对于每个有多次住院的患者只有一次住宿是随机选择的。像这样,我为这些患者创建了 100 个随机停留的数据集。我的因变量是一个计数变量,零膨胀负二项式模型最适合。 我已经设法在每个数据集上运行回归模型(数据集由变量“样本”标识),但我不知道如何获得所有这 100 个回归的汇总结果。我想获得每个预测变量的计数模型和零膨胀模型的汇总结果。

我创建了这样的组合数据集:

set.seed(12345)

Combined_randcase <- bind_rows(replicate(100, cohort_1 %>% group_by(patient) %>%
                                  slice_sample(n=1, replace = TRUE), simplify=F), .id="sample")

Combined_randcase <- data.frame(as.list(Combined_randcase))

我在每个数据集上运行 ZINB 回归模型,按“样本”分组,像这样(使用

broom
包):

regr_comb_randcase.zeroinfl = Combined_randcase %>% 
nest_by(sample) %>% 
mutate(model = list(zeroinfl(formula = cm_number ~ after_wm + age + gender_male + ref_mode_police + ref_lg_invol + ref_reas_selfharm + ref_reas_aggrpers + comm_limited + duration_days + diagnosis_personality + diagnosis_psychosis + diagnosis_mania + diagnosis_substance + intoxication | age + gender_male + ref_mode_police + ref_lg_invol + ref_reas_selfharm + ref_reas_aggrpers + comm_limited + duration_days + diagnosis_personality + diagnosis_psychosis + diagnosis_mania + diagnosis_substance + intoxication, data = cohort_1, na.action = na.exclude, dist = "negbin"))) 
%>%
  summarise(tidy(model)) 

这就是我试图获得汇总结果的方式:

models.zeroinfl <- regr_comb_randcase.zeroinfl$model

pool_results.zeroinfl <- pool(regr_comb_randcase.zeroinfl)

运行第二行时,报错:

Error: No tidy method for objects of class character

对于另一个逻辑回归模型,我使用

jtools
包和这段代码成功地做到了这一点:

regr_comb_randcase.log = Combined_randcase %>% 
group_by(sample) %>% 
do(model = glm(cm ~ after_wm + age + gender_male +ref_mode_police + ref_lg_invol + ref_reas_selfharm + ref_reas_aggrpers + comm_limited + duration_days + diagnosis_personality + diagnosis_psychosis + diagnosis_mania + diagnosis_substance + intoxication, data = ., family = binomial()))

models <- regr_comb_randcase.log$model

pool_results <- pool(models)

summary(pool_results)

数据集:

dput(cohort_1_example)

我可以找到有关使用线性和逻辑模型执行此操作的信息,但找不到有关零膨胀 negbin 模型的信息。也许这就是为什么 tidy 不起作用?非常感谢任何帮助。

r count regression pool
© www.soinside.com 2019 - 2024. All rights reserved.