我正在运行从UCLA下载的数据集
read.dta("https://stats.idre.ucla.edu/stat/data/ologit.dta")
,并在自变量中随机分配一些缺失值:pared,public和gpa。然后,我使用鼠标生成估算值,并对具有估算值的5个完整数据集进行有序逻辑回归。
DAT.imp=mice(DAT,print=FALSE)
DAT.fit.mice.plr = with(DAT.imp, polr(apply ~ pared + public + gpa))
summary(DAT.fit.mice.plr)
但是错误消息显示如下:
Error in as.data.frame.default(x) :
cannot coerce class ""polr"" to a data.frame
这是一个问题,因为pool()函数无法运行不属于lm的模型吗? 我是否应该通过polr()分别为5个估算数据集运行模型并手动合并它们? 预先感谢您的任何答复。
答案 0 :(得分:0)
这应该做到:
data_noimp <- read.dta("https://stats.idre.ucla.edu/stat/data/ologit.dta")
data_noimp[c(1, 15, 20, 200), 2] <- NA
data_noimp[c(1, 30, 50, 150), 3] <- NA
data_noimp[c(1, 50, 70, 250), 4] <- NA
data_imp = mice(data_noimp, print=FALSE, m = 5)
mod <- with(data_imp, polr(apply ~ pared + public + gpa, Hess = TRUE))
summary(pool(mod))
> summary(pool(mod))
est se t df
pared 1.107674490 0.2713236 4.08248505 344.4757
public -0.006703536 0.3009678 -0.02227326 370.4461
gpa 0.641763808 0.2623608 2.44611162 380.4930
unlikely|somewhat likely 2.295188221 0.7848823 2.92424510 382.4064
somewhat likely|very likely 4.402820363 0.8108302 5.43001523 382.6683
Pr(>|t|) lo 95 hi 95 nmis
pared 5.543550e-05 0.5740151 1.6413339 4
public 9.822420e-01 -0.5985232 0.5851162 4
gpa 1.489271e-02 0.1259052 1.1576224 4
unlikely|somewhat likely 3.658528e-03 0.7519630 3.8384135 NA
somewhat likely|very likely 1.003383e-07 2.8085801 5.9970606 NA
fmi lambda
pared 0.03853733 0.03297131
public 0.02549015 0.02024303
gpa 0.01899782 0.01385485
unlikely|somewhat likely 0.01754762 0.01242275
somewhat likely|very likely 0.01734109 0.01221865
答案 1 :(得分:0)
我尝试安装具有依赖关系的软件包的最新版本:
install.packages(c("mice", "MASS"), dep = TRUE)
取得了结果
> summary(pool(mod))
estimate std.error statistic df p.value
pared 1.088364240 0.2675445 4.0679748 388.8699 5.744000e-05
public -0.007057661 0.3020328 -0.0233672 376.9368 9.813694e-01
gpa 0.628030991 0.2610602 2.4056945 387.3003 1.660783e-02
unlikely|somewhat likely 2.250628213 0.7816727 2.8792461 386.0658 4.206607e-03
somewhat likely|very likely 4.353582378 0.8076085 5.3907086 385.6545 1.219831e-07
和
> pool(mod)
Class: mipo m = 5
estimate ubar b t dfcom df
pared 1.088364240 0.07111586 0.0003868321 0.07158006 395 388.8699
public -0.007057661 0.08973729 0.0012387621 0.09122381 395 376.9368
gpa 0.628030991 0.06759665 0.0004631305 0.06815241 395 387.3003
unlikely|somewhat likely 2.250628213 0.60530521 0.0047558921 0.61101228 395 386.0658
somewhat likely|very likely 4.353582378 0.64589464 0.0052807731 0.65223157 395 385.6545
riv lambda fmi
pared 0.006527356 0.006485026 0.01155566
public 0.016565181 0.016295247 0.02147350
gpa 0.008221658 0.008154614 0.01323709
unlikely|somewhat likely 0.009428418 0.009340353 0.01443286
somewhat likely|very likely 0.009811086 0.009715764 0.01481172
略有不同。报告的统计信息也略有不同。我不确定它是正确的(仅由于插补)。但是代码运行良好,没有错误。