在 R- 零膨胀泊松中使用 MICE 从多个估算数据集中合并估计的问题

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

我一直在尝试对我使用 mice() 来估算缺失数据的数据框运行零膨胀泊松回归。我的代码成功地运行了多重插补并合并了结果。但是,当我尝试总结汇总估计时,我无法获得模型的完整结果。零膨胀泊松模型 (zeroinfl()) 有两个组成部分:一个用于计数部分,一个用于我的数据中过多的零。我只能显示合并模型的一部分。

非常感谢任何帮助!


library(dplyr)
library(mice)
library(pscl)
library(poissonreg)
library(countimp)

# Set the seed for reproducibility
set.seed(123)

# Simulate data with one count outcome and three variables
n <- 1000
x1 <- rnorm(n)
x2 <- rbinom(n, 1, 0.5)
x3 <- rpois(n, 2)
y <- rpois(n, 1 + exp(0.5 * x1 + 0.8 * x2 + 0.3 * x3))

# Introduce missing data to the three variables
prop_missing <- 0.2
missing_x1 <- sample(c(TRUE, FALSE), size = n, prob = c(prop_missing, 1 - prop_missing), replace = TRUE)
missing_x2 <- sample(c(TRUE, FALSE), size = n, prob = c(prop_missing, 1 - prop_missing), replace = TRUE)
missing_x3 <- sample(c(TRUE, FALSE), size = n, prob = c(prop_missing, 1 - prop_missing), replace = TRUE)
x1[missing_x1] <- NA
x2[missing_x2] <- NA
x3[missing_x3] <- NA

# Create a data frame with the simulated data
dat <- data.frame(y, x1, x2, x3)

# Specify the variables to impute
imp_vars <- c("y", "x2", "x3")

# Create the imputed datasets using predictive mean matching for continuous variables and logistic regression for binary variables
imp <- mice(dat[imp_vars], m = 5)

#run intital imputation
ini <- mice( dat, m = 5, maxit = 0)
pred<-ini$predictorMatrix #set predictive matrix
pred[1,] <- c(0, 2, 2, 3) #edit predictive matrix

imp.zip <- mice(dat, m = 5, maxit = 5, method = c("","pmm","pmm","zip"), pred , seed = 1234, print = T) #run imputation with pred and specify methods

res.zinb <- with(imp.zip, zeroinfl( y ~ x1 + x2 | x3, dist = "poisson", link = "logit" ) )  #run the zeroinflated poisson regression on the imputed data
summary(pool(res.zinb)) #summarize and pool

r missing-data imputation poisson r-mice
© www.soinside.com 2019 - 2024. All rights reserved.