0

我在使用 R 中的 MICE 包时遇到问题,特别是在汇集估算数据集方面。

我正在运行多级二项式逻辑回归,其中 Level1 - 主题(参与者对不同主题的 10 个问题的回答,例如黑暗、白天)嵌套在 Level2 - 个人中。

该模型是使用 R2MLwiN 创建的,公式为 > fit1 <-runMLwiN( c(probit(T_Darkness, cons), probit(T_Day, cons), probit(T_Light, cons), probit(T_Night, cons), probit(T_Rain, cons), probit(T_Rainbows, cons), probit(T_Snow, cons), probit(T_Storms, cons), probit(T_Waterfalls, cons), probit(T_Waves, cons)) ~ 1, D=c("Mixed", "Binomial", "Binomial","Binomial","Binomial", "Binomial", "Binomial", "Binomial", "Binomial", "Binomial" ,"Binomial"), estoptions = list(EstM = 0), data=data)

不幸的是,所有 Level1(主题)响应中都缺少数据。我一直在使用mice包 ([CRAN][1]) 来乘以估算缺失值。

我可以使用公式将模型拟合到估算的数据集> fitMI <- (with(MI.Data, runMLwiN( c(probit(T_Darkness, cons), probit(T_Day, cons), probit(T_Light, cons), probit(T_Night, cons), probit(T_Rain, cons), probit(T_Rainbows, cons), probit(T_Snow, cons), probit(T_Storms, cons), probit(T_Waterfalls, cons), probit(T_Waves, cons)) ~ 1, D=c("Mixed", "Binomial", "Binomial","Binomial","Binomial", "Binomial", "Binomial", "Binomial", "Binomial", "Binomial" ,"Binomial"), estoptions = list(EstM = 0), data=data)))

但是,当我将分析与调用代码合并时,> pool(fitMI)它失败了,并出现错误:

Error in pool(with(tempData, runMLwiN(c(probit(T_Darkness, cons), probit(T_Day, : Object has no coef() method.

我不确定为什么说没有系数,因为对单个 MI 数据集的分析提供了固定部分(系数)和随机部分(协方差)

任何有关出现问题的帮助将不胜感激。

我应该警告您,这是我第一次尝试使用 R 和多级建模。另外我知道有一个 MlwiN 软件包 ([REALCOM][2]) 可以做到这一点,但我没有使用 MLwiN 软件的背景。

谢谢约翰尼

更新 - R 可重现的例子

使用的库

库(R2MLwin)

图书馆(小鼠)

数据子集`

T_Darkness <- c(0, 1, 0, 0, 0, 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不适用, 0, 0)

T_Rainbows <- c(1, 1, 1, 1, 0, 1, 0, 1, 0, 1, NA, 1, 1, 0, 0, 1, 0, NA, 0, 1, 0, NA, 0 , 1, 0, 0, 0, 0, 0, NA, 0, 0, 0, NA, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0 , 1, 1, 1, 1, NA, 1, 0, 1, NA, 0, 0, 1, 0, 1, 1, 1, 0, 1)

T_Snow <- c(0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, NA, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 , 1, 1, 0, 0, 0, NA, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 , 不适用, 0, 0, 1, 不适用, 1, 0, 1, 1, 0, 0, 0, 0, 0, 不适用, 0, 0, 0)

T_Storms <- c(0, 0, 0, 1, 1, 1, 0, 1, 0, 1, NA, 0, 0, 0, 0, 1, 0, NA, 0, 0, 1, 0, 0 , 不适用, 1, 1, 不适用, 0, 0, 不适用, 0, 1, 0, 不适用, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0 , 0, 0, 1, 0, 不适用, 1, 0, 不适用, 0, 0, 0, 1, 1, 0, 1, 不适用, 不适用, 1)

T_Waterfalls <- c(0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 1, 0, 0 , 0, 0, 0, 0, 0, NA, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, NA, 0, 0, 0, 0, 0 , 不适用, 0, 1, 0, 不适用, 1, 0, 1, 0, 0, 0, 不适用, 0, 0, 0, 不适用, 不适用, 0)

T_Waves <- c(0, 1, 0, 1, 1, 0, 1, NA, 0, 0, NA, 0, 0, 0, NA, 1, 0, 0, 0, 0, 1, 0, NA , 0, 不适用, 0, 0, 不适用, 0, 0, 0, 0, 0, 0, 不适用, 1, 0, 0, 0, 1, 0, 0, 不适用, 0, 1, 0, 0, 0 , 0, 0, 1, 1, 不适用, 1, 1, 不适用, 0, 0, 0, 不适用, 0, 0, 0, 不适用, 0, 0)

数据 <- 数据帧(T_Darkness、T_Day、T_Light、T_Night、T_Rain、T_Rainbows、T_Snow、T_Storms、T_Waterfalls、T_Waves)

数据$cons <- 1

`

使用小鼠估算的数据

MI.Data <- 老鼠(数据,m=5,maxit=50,meth='pmm',seed=500)

4

1 回答 1

0

这似乎是由于未正确找到 R2MLwiN 中的某些模型提取方法,这应该已在最近发布的 0.8-2 版本的软件包中得到修复。用这个运行你的例子会给我以下结果:

> pool(fitMI)
Call: pool(object = fitMI)

Pooled coefficients:
  FP_Intercept_T_Darkness        FP_Intercept_T_Day      FP_Intercept_T_Light      FP_Intercept_T_Night       FP_Intercept_T_Rain 
            -0.9687210917             -1.0720602274             -0.9584792256             -1.1816471815             -0.7082406878 
  FP_Intercept_T_Rainbows       FP_Intercept_T_Snow     FP_Intercept_T_Storms FP_Intercept_T_Waterfalls      FP_Intercept_T_Waves 
            -0.0455361903             -0.7537600398             -0.3883027434             -1.2365225554             -0.6423609257 
          RP1_var_bcons_1   RP1_cov_bcons_1_bcons_2           RP1_var_bcons_2   RP1_cov_bcons_1_bcons_3   RP1_cov_bcons_2_bcons_3 
             1.0000000000              0.0508168936              1.0000000000              0.2744663656              0.1625871509 
          RP1_var_bcons_3   RP1_cov_bcons_1_bcons_4   RP1_cov_bcons_2_bcons_4   RP1_cov_bcons_3_bcons_4           RP1_var_bcons_4 
             1.0000000000              0.0013987361              0.0576194786              0.0201622359              1.0000000000 
  RP1_cov_bcons_1_bcons_5   RP1_cov_bcons_2_bcons_5   RP1_cov_bcons_3_bcons_5   RP1_cov_bcons_4_bcons_5           RP1_var_bcons_5 
            -0.0220604800              0.1620389074              0.0956511647             -0.0242812764              1.0000000000 
  RP1_cov_bcons_1_bcons_6   RP1_cov_bcons_2_bcons_6   RP1_cov_bcons_3_bcons_6   RP1_cov_bcons_4_bcons_6   RP1_cov_bcons_5_bcons_6 
             0.2644620836              0.0555731133              0.1911445856              0.2584619522              0.1523280591 
          RP1_var_bcons_6   RP1_cov_bcons_1_bcons_7   RP1_cov_bcons_2_bcons_7   RP1_cov_bcons_3_bcons_7   RP1_cov_bcons_4_bcons_7 
             1.0000000000              0.1877118051              0.0872156173              0.2800109982              0.1433261335 
  RP1_cov_bcons_5_bcons_7   RP1_cov_bcons_6_bcons_7           RP1_var_bcons_7   RP1_cov_bcons_1_bcons_8   RP1_cov_bcons_2_bcons_8 
            -0.0006230903              0.1582182944              1.0000000000             -0.0749104023              0.1435756236 
  RP1_cov_bcons_3_bcons_8   RP1_cov_bcons_4_bcons_8   RP1_cov_bcons_5_bcons_8   RP1_cov_bcons_6_bcons_8   RP1_cov_bcons_7_bcons_8 
             0.0537744537              0.2291038185              0.2553031743              0.2716509402              0.1914017051 
          RP1_var_bcons_8   RP1_cov_bcons_1_bcons_9   RP1_cov_bcons_2_bcons_9   RP1_cov_bcons_3_bcons_9   RP1_cov_bcons_4_bcons_9 
             1.0000000000              0.1936145425              0.2835071683              0.0144172618              0.3326070011 
  RP1_cov_bcons_5_bcons_9   RP1_cov_bcons_6_bcons_9   RP1_cov_bcons_7_bcons_9   RP1_cov_bcons_8_bcons_9           RP1_var_bcons_9 
             0.1372590512              0.2854030728              0.0750594735              0.2545967996              1.0000000000 
 RP1_cov_bcons_1_bcons_10  RP1_cov_bcons_2_bcons_10  RP1_cov_bcons_3_bcons_10  RP1_cov_bcons_4_bcons_10  RP1_cov_bcons_5_bcons_10 
             0.3137466609              0.3498021364              0.2846792042              0.1126367375              0.2416045219 
 RP1_cov_bcons_6_bcons_10  RP1_cov_bcons_7_bcons_10  RP1_cov_bcons_8_bcons_10  RP1_cov_bcons_9_bcons_10          RP1_var_bcons_10 
             0.2137401104              0.1849118918              0.2134640366              0.6101759672              1.0000000000 

Fraction of information about the coefficients missing due to nonresponse: 
  FP_Intercept_T_Darkness        FP_Intercept_T_Day      FP_Intercept_T_Light      FP_Intercept_T_Night       FP_Intercept_T_Rain 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367 
  FP_Intercept_T_Rainbows       FP_Intercept_T_Snow     FP_Intercept_T_Storms FP_Intercept_T_Waterfalls      FP_Intercept_T_Waves 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367 
          RP1_var_bcons_1   RP1_cov_bcons_1_bcons_2           RP1_var_bcons_2   RP1_cov_bcons_1_bcons_3   RP1_cov_bcons_2_bcons_3 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367 
          RP1_var_bcons_3   RP1_cov_bcons_1_bcons_4   RP1_cov_bcons_2_bcons_4   RP1_cov_bcons_3_bcons_4           RP1_var_bcons_4 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367 
  RP1_cov_bcons_1_bcons_5   RP1_cov_bcons_2_bcons_5   RP1_cov_bcons_3_bcons_5   RP1_cov_bcons_4_bcons_5           RP1_var_bcons_5 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367 
  RP1_cov_bcons_1_bcons_6   RP1_cov_bcons_2_bcons_6   RP1_cov_bcons_3_bcons_6   RP1_cov_bcons_4_bcons_6   RP1_cov_bcons_5_bcons_6 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367 
          RP1_var_bcons_6   RP1_cov_bcons_1_bcons_7   RP1_cov_bcons_2_bcons_7   RP1_cov_bcons_3_bcons_7   RP1_cov_bcons_4_bcons_7 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367 
  RP1_cov_bcons_5_bcons_7   RP1_cov_bcons_6_bcons_7           RP1_var_bcons_7   RP1_cov_bcons_1_bcons_8   RP1_cov_bcons_2_bcons_8 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367 
  RP1_cov_bcons_3_bcons_8   RP1_cov_bcons_4_bcons_8   RP1_cov_bcons_5_bcons_8   RP1_cov_bcons_6_bcons_8   RP1_cov_bcons_7_bcons_8 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367 
          RP1_var_bcons_8   RP1_cov_bcons_1_bcons_9   RP1_cov_bcons_2_bcons_9   RP1_cov_bcons_3_bcons_9   RP1_cov_bcons_4_bcons_9 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367 
  RP1_cov_bcons_5_bcons_9   RP1_cov_bcons_6_bcons_9   RP1_cov_bcons_7_bcons_9   RP1_cov_bcons_8_bcons_9           RP1_var_bcons_9 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367 
 RP1_cov_bcons_1_bcons_10  RP1_cov_bcons_2_bcons_10  RP1_cov_bcons_3_bcons_10  RP1_cov_bcons_4_bcons_10  RP1_cov_bcons_5_bcons_10 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367 
 RP1_cov_bcons_6_bcons_10  RP1_cov_bcons_7_bcons_10  RP1_cov_bcons_8_bcons_10  RP1_cov_bcons_9_bcons_10          RP1_var_bcons_10 
                0.5714367                 0.5714367                 0.5714367                 0.5714367                 0.5714367
于 2016-04-14T10:52:44.870 回答