MICE包中的错误

时间:2018-02-01 13:52:16

标签: r r-mice

抱歉,我是statsr的新手,所以我的术语可能不对。我试图通过链式鼠标进行链式方程式的多重插补。 当我运行它时,我立即得到错误:

  

'cor中的错误(xobs [,keep,drop = FALSE],use =“all.obs”):'x'是   空“

我已经尝试删除有问题的变量,但是当进程到达下一个缺少数据的变量时,错误就会跳起来。等等。 我非常感谢任何帮助或见解。谢谢!

我希望这是数据的相关格式:

structure(list(V1_A = c("Nama", "Kung", "Thonga", "Lozi", "Mbundu", 
"Suku"), ord = 1:6, socname = c("Nama Hottentot", "Kung Bushmen", 
"Thonga", "Lozi", "Mbundu", "Suku"), focus = c("GeiKhauan tribe", 
"Nyai Nyae region", "Ronga subtribe", "Ruling Luyana", "Bailundo subtribe", 
"Feshi territory lineage center"), hraf = c("FX13", "FX10", "FT06", 
"FQ09", "FP13", NA), v1 = c(4L, 2L, 4L, 4L, NA, 4L), v3 = c(1L, 
1L, 6L, 5L, 6L, 6L), v4 = c(6L, 6L, 5L, 5L, 5L, 4L), v5 = c(5L, 
1L, 3L, 4L, 4L, 3L), v6 = c(7L, 8L, 3L, 7L, 7L, 1L), v7 = c(1L, 
1L, 2L, 3L, 2L, 2L), v8 = c(NA, NA, 2L, 2L, 2L, 2L), v9 = c(4L, 
4L, 3L, 3L, 3L, 3L), v10 = c(3L, 3L, 3L, 4L, 2L, 4L), v11 = c(3L, 
5L, 2L, 2L, 2L, 3L), v12 = c(1L, 6L, 5L, 5L, 1L, 6L), v13 = c(2L, 
1L, 1L, 1L, 1L, 1L), v15 = c(2L, 2L, 4L, 4L, 4L, 1L), v19 = c(1L, 
1L, 7L, 12L, 7L, 2L), v20 = c(1L, 1L, 2L, 2L, 2L, 2L), v21 = c(1L, 
1L, 1L, 3L, 1L, 2L), v22 = c(1L, 1L, 3L, 4L, 3L, 1L), v34 = c(4L, 
4L, 5L, NA, NA, 6L), v35 = c(2L, 2L, 4L, 2L, 2L, 3L), v36 = c(3L, 
1L, 4L, 4L, 3L, 3L), v61 = c(1L, 1L, 5L, 3L, 6L, 5L), v62 = c(4L, 
4L, 4L, 4L, 4L, 4L), v63 = c(3L, 1L, 1L, 5L, 3L, 2L), v64 = c(1L, 
1L, 6L, 4L, 4L, 4L), v65 = c(3L, 3L, 6L, 6L, 6L, 7L), v66 = c(1L, 
1L, 1L, 2L, 3L, 1L), v67 = c(3L, 3L, 8L, 8L, 6L, 8L), v68 = c(2L, 
8L, 12L, 3L, 3L, 9L), v72 = c(5L, 4L, 5L, 3L, 5L, 4L), v75 = c(4L, 
3L, 4L, 4L, 3L, 3L), v93 = c(1L, 1L, 5L, 6L, 8L, 5L), v94 = c(0L, 
0L, 10L, 3L, 3L, 0L), v95 = c(0L, 0L, 0L, 2L, 0L, 0L), v96 = c(0L, 
0L, 0L, 0L, 0L, 0L), v97 = c(0L, 0L, 0L, 0L, 0L, 0L), v98 = c(0L, 
0L, 0L, 0L, 0L, 0L), v144 = c(-1L, 1L, 1L, -1L, NA, 1L), v150 = c(1L, 
1L, 4L, 3L, 5L, 4L), v151 = c(1L, 1L, 4L, 5L, 4L, 4L), v152 = c(2L, 
1L, 1L, 4L, 2L, 1L), v153 = c(4L, 1L, 4L, 3L, 4L, 4L), v154 = c(2L, 
1L, 1L, 1L, 1L, 1L), v155 = c(1L, 1L, 3L, 1L, 4L, 4L), v181 = c(18L, 
22L, 33L, 23L, 15L, NA), v182 = c(1L, 1L, 1L, 1L, 1L, NA), v186 = c(21L, 
21L, 24L, 23L, 18L, NA), v187 = c(27L, 25L, 27L, 25L, 19L, NA
), v188 = c(13L, 15L, 19L, 18L, 17L, NA), v189 = c(133L, 470L, 
570L, 954L, 1354L, NA), v192 = c(34L, 95L, 129L, 210L, 235L, 
NA), v193 = c(0L, 0L, 17L, 0L, 0L, NA), v194 = c(9L, 7L, 7L, 
7L, 5L, NA), v195 = c(1L, 1L, 2L, 12L, 1L, NA), v196 = c(12L, 
7L, 7L, 6L, 4L, NA), v197 = c(7L, 6L, 7L, 4L, 2L, NA), v198 = c(1L, 
1L, 1L, 12L, 12L, NA), v199 = c(0L, 0L, 0L, 0L, 0L, NA), v200 = c(1L, 
1L, 1L, 1L, 1L, 1L), v201 = c(1L, 1L, 2L, 2L, 2L, 3L), v203 = c(1L, 
8L, 0L, 1L, 1L, 1L), v204 = c(3L, 2L, 1L, 2L, 1L, 2L), v205 = c(1L, 
0L, 1L, 1L, 1L, 1L), v206 = c(5L, 0L, 3L, 2L, 2L, 0L), v207 = c(0L, 
0L, 5L, 4L, 5L, 6L), v232 = c(1L, 1L, 3L, 5L, 3L, 3L), v233 = c(1L, 
1L, 6L, 6L, 6L, 5L), v234 = c(1L, 1L, 7L, 3L, 7L, 7L), v236 = c(2L, 
3L, 2L, 2L, 3L, 3L), v237 = c(2L, 1L, 3L, 4L, 3L, 4L), v241 = c(0L, 
0L, 5L, 0L, 0L, 5L), v242 = c(2L, 2L, 3L, NA, 2L, 2L), v243 = c(1L, 
1L, 1L, 1L, 1L, 1L), v244 = c(7L, 1L, 7L, 7L, 7L, 3L), v245 = c(2L, 
1L, 2L, 2L, 1L, 1L), v246 = c(4L, 1L, 6L, 7L, 6L, 6L), v254 = c(9L, 
9L, 3L, 3L, 3L, 3L), v255 = c(9L, 9L, 9L, 9L, 9L, NA), v256 = c(9L, 
9L, 9L, 9L, 9L, NA), v257 = c(9L, 9L, 9L, 9L, 9L, 9L), v258 = c(9L, 
9L, 9L, 9L, 9L, NA), v259 = c(9L, 9L, 9L, 9L, 9L, 9L), v260 = c(6L, 
5L, 6L, 5L, 6L, NA), v261 = c(1L, 1L, 1L, 1L, 1L, 1L), v262 = c(1L, 
9L, 1L, 2L, 2L, 4L), v263 = c(3L, 9L, 1L, 1L, 1L, NA), v264 = c(9L, 
9L, 5L, 5L, 5L, 5L), v268 = c(9L, 9L, 9L, 9L, 9L, NA), v270 = c(2L, 
1L, 4L, 4L, 4L, 4L), v271 = c(9L, 9L, 9L, 9L, 9L, 9L), v283 = c(2L, 
2L, 2L, 2L, 2L, 5L), v284 = c(2L, 2L, 2L, 2L, 2L, 2L), v285 = c(NA, 
NA, 2L, 2L, 2L, 3L), v286 = c(2L, 2L, 4L, 4L, 4L, 8L), v287 = c(7L, 
8L, 8L, 8L, 8L, 8L), v288 = c(NA, 1L, NA, 5L, NA, NA), v289 = c(NA, 
2L, NA, 2L, NA, NA), v291 = c(NA, 5L, NA, 8L, NA, NA), v292 = c(NA, 
8L, NA, 8L, NA, NA), v457 = c(4L, 7L, 3L, NA, NA, NA), v458 = c(4L, 
7L, 3L, NA, NA, NA), v459 = c(4L, 7L, 3L, 4L, NA, 7L), v460 = c(4L, 
7L, 3L, NA, NA, NA), v533 = c(2L, 2L, 4L, 0L, 4L, 4L), v534 = c(2L, 
2L, 3L, 2L, 3L, 0L), v535 = c(4L, 2L, 4L, 0L, 4L, 4L), v536 = c(4L, 
3L, 4L, 3L, 4L, 0L), v537 = c(3L, 3L, 3L, 0L, 4L, 4L), v538 = c(3L, 
3L, 3L, 3L, 4L, 0L), v539 = c(3L, 4L, 4L, 0L, 4L, 4L), v540 = c(3L, 
3L, 4L, 3L, 3L, 0L), v541 = c(4L, 4L, 6L, 0L, 6L, 6L), v542 = c(3L, 
3L, 4L, 4L, 5L, 0L), v543 = c(5L, 5L, 5L, 0L, 5L, 3L), v544 = c(5L, 
4L, 5L, 4L, 2L, 0L), v545 = c(6L, 4L, 2L, 0L, 5L, 7L), v546 = c(6L, 
6L, 3L, 6L, 5L, 0L), v547 = c(3L, 4L, 3L, 0L, 5L, 2L), v548 = c(2L, 
2L, 3L, 4L, 5L, 0L), v549 = c(3L, 3L, 3L, 0L, 3L, 3L), v550 = c(3L, 
3L, 3L, 3L, 3L, 0L), v551 = c(5L, 5L, 5L, 0L, 5L, 5L), v552 = c(5L, 
5L, 2L, 5L, 5L, 0L), v553 = c(3L, 3L, 4L, 0L, 4L, 4L), v554 = c(2L, 
3L, 4L, 3L, 4L, 0L), v555 = c(4L, 2L, 5L, 0L, 5L, 6L), v556 = c(4L, 
2L, 4L, 4L, 3L, 0L), v557 = c(2L, 2L, 4L, 0L, 5L, 3L), v558 = c(2L, 
2L, 2L, 4L, 5L, 0L), v559 = c(3L, 6L, 6L, 0L, 6L, 3L), v560 = c(3L, 
3L, 3L, 3L, 6L, 0L), v561 = c(2L, 2L, 1L, NA, NA, 1L), v563 = c(2L, 
2L, 2L, NA, NA, 1L), v564 = c(1L, 1L, 1L, NA, NA, NA), v565 = c(1L, 
1L, 1L, NA, NA, 1L), v566 = c(1L, 1L, 1L, NA, NA, NA), v567 = c(1L, 
1L, 1L, NA, NA, NA), v573 = c(1L, 1L, 2L, NA, NA, 1L), v574 = c(1L, 
1L, 1L, NA, NA, 1L), v575 = c(1L, 1L, 2L, NA, NA, 1L), v576 = c(1L, 
NA, NA, NA, 3L, NA), v577 = c(1L, NA, 3L, NA, 2L, NA), v578 = c(1L, 
NA, 2L, NA, 3L, NA), v579 = c(1L, NA, 3L, NA, 4L, NA), v580 = c(2L, 
NA, 3L, NA, NA, NA), v581 = c(2L, NA, 2L, NA, 2L, NA), v582 = c(2L, 
NA, 1L, NA, 2L, NA), v584 = c(1L, NA, 1L, NA, 1L, NA), v587 = c(3L, 
NA, 2L, NA, 2L, NA), v588 = c(NA, NA, 2L, NA, 2L, NA), v599 = c(7L, 
NA, 7L, NA, 7L, NA), v617 = c(1L, NA, 2L, NA, 2L, NA), v622 = c(2L, 
NA, 1L, NA, 1L, NA), v623 = c(4L, NA, 2L, NA, 1L, NA), v633 = c(3L, 
NA, 3L, NA, 3L, NA), v635 = c(3L, NA, 2L, NA, 3L, NA), v652 = c(2L, 
2L, 4L, NA, 2L, 3L), v653 = c(1L, 1L, 1L, NA, 1L, 1L), v654 = c(4L, 
4L, 3L, NA, 3L, 2L), v655 = c(3L, 1L, 1L, NA, 3L, 3L), v656 = c(1L, 
1L, 3L, NA, 1L, 3L), v665 = c(2L, 2L, 2L, NA, 2L, 2L), v671 = c(6L, 
5L, 6L, NA, 3L, 5L), v672 = c(3L, 3L, 3L, 1L, 1L, 3L), v676 = c(3L, 
3L, 2L, 3L, 3L, NA), v678 = c(2L, 1L, 3L, 2L, 2L, 2L), v679 = c(2L, 
1L, 2L, 2L, 2L, 1L), v681 = c(1L, NA, 1L, NA, 2L, NA), v693 = c(2L, 
NA, 1L, NA, 2L, NA), v694 = c(5L, NA, 3L, NA, 1L, NA), v695 = c(1L, 
NA, 2L, NA, 4L, NA), v708 = c(1L, NA, 1L, NA, 1L, NA), v731 = c(3L, 
NA, 4L, NA, 4L, NA), v757 = c(NA, 1L, NA, 2L, NA, 2L), v767 = c(NA, 
3L, NA, 2L, NA, 3L), v768 = c(NA, 4L, NA, 3L, NA, 2L), v773 = c(NA, 
3L, NA, 3L, NA, 2L), v774 = c(NA, 4L, NA, 2L, NA, 3L), v788 = c(NA, 
2L, NA, 2L, NA, 2L), v790 = c(NA, 3L, NA, 1L, NA, 3L), v791 = c(NA, 
1L, NA, 1L, NA, 1L), v792 = c(NA, 1L, NA, 2L, NA, 3L), v814 = c(0L, 
0L, 75L, 35L, 60L, 55L), v815 = c(35L, 0L, 5L, 25L, 25L, 5L), 
    v816 = c(0L, 0L, 5L, 25L, 5L, 5L), v817 = c(30L, 25L, 5L, 
    5L, 5L, 5L), v818 = c(30L, 75L, 5L, 5L, 5L, 25L), v819 = c(5L, 
    0L, 5L, 5L, 0L, 5L), v820 = c(2L, 1L, 6L, 7L, 6L, 6L), v821 = c(NA, 
    NA, 85L, 60L, 65L, 80L), v822 = c(50L, NA, 0L, 0L, 6L, NA
    ), v823 = c(NA, NA, 5L, 19L, 0L, 25L), v824 = c(0L, 0L, 0L, 
    0L, 0L, 0L), v825 = c(25L, 25L, 75L, 56L, 57L, NA), v826 = c(26L, 
    19L, 71L, 30L, 43L, 70L), v833 = c(4L, 7L, 3L, 1L, 3L, 3L
    ), v835 = c(2L, 1L, 3L, 4L, 3L, 4L), v840 = c("FX13", "FX10", 
    "FT06", "FQ09e", "FP13e", NA), v843 = c("A01a", "A02a", "A03a", 
    "A03f", "A04a", "A05a"), v854 = c(1L, 1L, 1L, 1L, 1L, 1L), 
    v855 = c(7L, 7L, 2L, 2L, 2L, 2L), v856 = c(1L, 1L, 1L, 1L, 
    1L, 1L), v858 = c(6L, 1L, 8L, 11L, 8L, 8L), v859 = c(11L, 
    2L, 10L, 8L, 10L, 10L), v869 = c(0L, 0L, 0L, 0L, 0L, 0L), 
    v879 = c(0L, 1L, NA, NA, 0L, NA), v880 = c(1L, 0L, NA, NA, 
    0L, NA), v881 = c(0L, 0L, NA, NA, 1L, NA), v882 = c(0L, 0L, 
    NA, NA, 0L, NA), v884 = c(0L, 0L, NA, NA, 1L, NA), v898 = c(1L, 
    NA, NA, NA, NA, NA), v913 = c(2L, 2L, 2L, 2L, 1L, NA), v915 = c(1L, 
    1L, 1L, 1L, 2L, NA), v921 = c(12L, 20L, 16L, 21L, 19L, 18L
    ), v922 = c(4L, 8L, 8L, 8L, 7L, 8L), v924 = c(5L, 4L, 4L, 
    6L, 4L, 2L), v926 = c(3L, 8L, 4L, 7L, 8L, 8L), v928 = c(3L, 
    4L, 4L, 6L, 4L, 2L), v929 = c(1L, 5L, 3L, 7L, 8L, 8L), v930 = c(0L, 
    0L, 0L, 0L, 0L, 0L), v931 = c(NA, NA, 8L, NA, NA, 8L), v932 = c(NA, 
    NA, 1L, NA, NA, 2L), v966 = c(0L, NA, 1L, NA, NA, 6L), v1007 = c(3L, 
    3L, NA, NA, NA, NA), v1008 = c(0L, 0L, NA, NA, NA, NA), v1011 = c(1L, 
    1L, NA, NA, NA, NA), v1012 = c(2L, 1L, NA, NA, NA, NA), v1013 = c(2L, 
    1L, NA, NA, NA, NA), v1014 = c(2L, 2L, NA, NA, NA, NA), v1015 = c(1L, 
    0L, NA, NA, NA, NA), v1016 = c(0L, 0L, NA, NA, NA, NA), v1017 = c(0L, 
    2L, NA, NA, NA, NA), v1018 = c(1L, 0L, NA, NA, NA, NA), v1019 = c(4L, 
    3L, NA, NA, NA, NA), v1020 = c(3L, 3L, NA, NA, NA, NA), v1021 = c(1L, 
    2L, NA, NA, NA, NA), v1022 = c(0L, 0L, NA, NA, NA, NA), v1023 = c(0L, 
    0L, NA, NA, NA, NA), v1026 = c(0L, 0L, NA, NA, NA, NA), v1027 = c(1L, 
    0L, NA, NA, NA, NA), v1028 = c(0L, 0L, NA, NA, NA, NA), v1029 = c(0L, 
    0L, NA, NA, NA, NA), v1030 = c(0L, 0L, NA, NA, NA, NA), v1032 = c(1L, 
    1L, NA, NA, NA, NA), v1033 = c(0L, 0L, NA, NA, NA, NA), v1034 = c(0L, 
    0L, NA, NA, NA, NA), v1035 = c(0L, 0L, NA, NA, NA, NA), v1036 = c(1L, 
    0L, NA, NA, NA, NA), v1037 = c(1L, 1L, NA, NA, NA, NA), v1038 = c(1L, 
    1L, NA, NA, NA, NA), v1047 = c(1L, 0L, NA, NA, NA, NA), v1048 = c(1L, 
    0L, NA, NA, NA, NA), v1049 = c(0L, 1L, NA, NA, NA, NA), v1050 = c(0L, 
    0L, NA, NA, NA, NA), v1054 = c(0L, 0L, NA, NA, NA, NA), v1055 = c(1L, 
    0L, NA, NA, NA, NA), v1056 = c(0L, 0L, NA, NA, NA, NA), v1059 = c(0L, 
    0L, NA, NA, NA, NA), v1123 = c(0L, 0L, 14L, 15L, 14L, 24L
    ), v1125 = c(0L, 0L, 1L, 1L, 1L, 1L), v1127 = c(0L, 0L, 1L, 
    1L, 1L, 1L), v1128 = c(0L, 0L, 1L, 4L, 4L, 1L), v1132 = c(4L, 
    2L, 5L, 6L, 2L, 0L), v1188 = c(3L, 3L, 7L, 3L, 2L, 3L), v1189 = c(0L, 
    0L, 1L, 0L, 0L, 0L), v1253 = c(1L, 1L, 1L, 1L, 1L, 2L), v1254 = c(1L, 
    2L, 1L, 2L, 2L, 2L), v1255 = c(1L, 3L, 3L, 3L, 3L, 3L), v1256 = c(1L, 
    1L, 2L, 2L, 1L, 2L), v1257 = c(1L, 1L, 1L, 3L, 3L, 3L), v1258 = c(1L, 
    1L, 1L, 2L, 3L, 3L), v1259 = c(2L, 1L, 2L, 3L, 2L, 3L), v1260 = c(8L, 
    10L, 11L, 16L, 15L, 18L), v1262 = c(2L, 3L, 2L, 2L, 2L, NA
    ), v1263 = c(3L, 4L, 3L, 1L, 3L, NA), v1352 = c(0L, 0L, 1L, 
    NA, NA, 0L), v1354 = c(0L, 0L, NA, NA, NA, 0L), v1355 = c(0L, 
    0L, 0L, NA, NA, 0L), v1362 = c(0L, 0L, NA, NA, NA, NA), v1458 = c(0L, 
    0L, NA, NA, NA, NA), v1489 = c(0L, 0L, 1L, NA, NA, 2L), v1666 = c(NA, 
    1L, NA, NA, NA, 7L), v1683 = c(NA, 3L, 4L, NA, 1L, NA), v1684 = c(2L, 
    4L, NA, NA, 1L, NA), v1685 = c(3L, 4L, 4L, 1L, 1L, 1L), v1686 = c(1L, 
    8L, 3L, 1L, 1L, 1L), v1687 = c(1L, 5L, 8L, 1L, 8L, 1L), v1688 = c(8L, 
    1L, 8L, 4L, 8L, 8L), v1692 = c(2L, 2L, 2L, 1L, 2L, 1L), v1693 = c(1L, 
    2L, 1L, 2L, NA, 1L), v1694 = c(3L, 3L, 2L, 1L, 3L, 1L), v1695 = c(2L, 
    3L, 3L, 3L, NA, 1L), v1697 = c(1L, 1L, 1L, 1L, 2L, 3L), v1698 = c(1L, 
    1L, 1L, 1L, 1L, 1L), v1699 = c(1L, 1L, 1L, 1L, 1L, 1L), v1700 = c(1L, 
    1L, 1L, 1L, 1L, 3L), v1701 = c(1L, 1L, 2L, 1L, 2L, 2L), v1702 = c(1L, 
    1L, 1L, 1L, 1L, 1L), v1703 = c(1L, 1L, 1L, 1L, 1L, 2L), v1704 = c(1L, 
    1L, 1L, 1L, 1L, 3L), v1705 = c(1L, 1L, 3L, 3L, 3L, 1L), v1706 = c(1L, 
    1L, 1L, 3L, 2L, 1L), v1707 = c(1L, 2L, 3L, 3L, 3L, 3L), v1708 = c(1L, 
    1L, 2L, 3L, 1L, 1L), v1709 = c(1L, 1L, 1L, 3L, 3L, 1L), v1745 = c(NA, 
    0L, 3L, 3L, NA, 1L), v1767 = c(NA, 2L, 1L, NA, NA, NA), v1779 = c(NA, 
    NA, 3L, 1L, NA, 1L), v1780 = c(NA, NA, 3L, 3L, NA, NA), v1850 = c(1L, 
    1L, 1L, 1L, 1L, NA), v1851 = c(1L, 7L, 1L, 1L, 1L, NA), v1852 = c(1L, 
    1L, 1L, 1L, 1L, NA), v1853 = c(1L, 2L, 1L, 1L, 1L, NA), v1854 = c(1L, 
    1L, 1L, 1L, 1L, NA), v1855 = c(1L, 2L, 1L, 1L, 1L, NA), v1856 = c(1L, 
    1L, 1L, 1L, 1L, NA), v1857 = c(1L, 1L, 1L, 1L, 1L, NA), v1858 = c(1L, 
    1L, 1L, 1L, 1L, 1L), v1889 = c(0L, 0L, 1L, 0L, 0L, 0L), v1890 = c(0L, 
    0L, 0L, 0L, 0L, 0L), v1892 = c(1L, 0L, 1L, 0L, 0L, 0L), v1893 = c(0L, 
    0L, 0L, 0L, 0L, 0L), v1895 = c(1L, 0L, 1L, 0L, 1L, 0L), v1896 = c(0L, 
    0L, 0L, 0L, 0L, 0L), v1898 = c(1L, 0L, 1L, 0L, 1L, 0L), v1899 = c(0L, 
    0L, 0L, 0L, 0L, 1L), v1900 = c(2L, 2L, 2L, 2L, 2L, 2L), v1901 = c(2L, 
    2L, 2L, 2L, 2L, 2L), v1902 = c(2L, 2L, 2L, 2L, 2L, 2L), v1903 = c(2L, 
    2L, 2L, 2L, 2L, 2L), v1913 = c(11.155, 35.425, 86.95, 69.79, 
    128.05, 165.89), v2001 = c(1L, 1L, 1L, 1L, 1L, 1L), v2002 = c(1L, 
    1L, 1L, 1L, 1L, 1L), v2003 = c(3L, 2L, 2L, 2L, 1L, 1L), v2004 = c(3L, 
    3L, 3L, 3L, 3L, 3L), v2005 = c(2L, 2L, 2L, 2L, 1L, 1L), v2006 = c(2L, 
    1L, 2L, 2L, 2L, 1L), v2007 = c(1L, 3L, 3L, 2L, 2L, 2L), v2013 = c(1L, 
    1L, 2L, 2L, 2L, 2L), v2039 = c(NA, 1L, NA, NA, NA, NA), v2106 = c(NA_integer_, 
    NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_
    ), v2126 = c(1L, 1L, 1L, 1L, 1L, 1L), v2127 = c(1L, 1L, 1L, 
    1L, 1L, 1L), v2128 = c(1L, 0L, 1L, 0L, 0L, 0L), v2129 = c(1L, 
    1L, 1L, 1L, 1L, 1L), v2130 = c(1L, 1L, 1L, 1L, 1L, 1L), v2131 = c(1L, 
    0L, 1L, 1L, 1L, 1L), v2132 = c(1L, 1L, 1L, 1L, 1L, 1L), v2133 = c(1L, 
    1L, 1L, 1L, 1L, 1L), v2134 = c(1L, 0L, 1L, 1L, 0L, 0L), v2135 = c(0L, 
    0L, 1L, 1L, 1L, 1L), v2136 = c(0L, 0L, 1L, 1L, 1L, 1L), v2137 = c(0L, 
    0L, 1L, 1L, 1L, 1L), v2138 = c(0L, 0L, 1L, 1L, 1L, 1L), v2139 = c(0L, 
    0L, 1L, 1L, 1L, 1L), v2140 = c(1L, 1L, 1L, NA, 1L, 1L), v2141 = c(1L, 
    0L, 1L, 1L, 1L, 0L), v2142 = c(1L, 0L, 1L, 1L, 0L, 0L), v2143 = c(1L, 
    1L, 1L, 1L, 1L, 1L), v2144 = c(1L, 1L, 1L, 1L, 1L, 1L), v2145 = c(1L, 
    1L, NA, 1L, NA, 0L), v2146 = c(1L, 0L, 1L, NA, 1L, 1L), v2147 = c(1L, 
    0L, 1L, NA, 0L, 0L), v2148 = c(1L, 1L, 1L, 1L, 1L, 1L), v2149 = c(NA, 
    0L, 0L, 0L, 1L, NA), v2150 = c(1L, 1L, 1L, 1L, 1L, 1L), v2151 = c(NA, 
    0L, 1L, 1L, 1L, 1L), v2152 = c(1L, 1L, 1L, 1L, 1L, 1L), v2153 = c(1L, 
    1L, 0L, 1L, 1L, 1L), v2154 = c(0L, 0L, NA, 0L, 1L, NA), v2155 = c(0L, 
    0L, NA, 1L, NA, 1L), v2156 = c(1L, 0L, 1L, 0L, 1L, 0L), v2157 = c(1L, 
    0L, 1L, 1L, 1L, 1L), v2158 = c(1L, 0L, 0L, 1L, 1L, 1L), v2159 = c(1L, 
    0L, 1L, 1L, 1L, 1L), v2160 = c(1L, 1L, 1L, 1L, 1L, 1L), v2161 = c(1L, 
    1L, 0L, 1L, 1L, NA), v2162 = c(1L, 1L, 1L, 1L, 0L, 0L), v2163 = c(1L, 
    0L, 1L, 1L, 1L, 1L), v2164 = c(1L, 1L, 1L, 1L, 1L, 1L), v2165 = c(1L, 
    1L, 1L, 1L, 0L, NA), v2166 = c(1L, 0L, 0L, 0L, 0L, 0L), v2167 = c(1L, 
    0L, 1L, 0L, 1L, 1L), v2169 = c(1L, 1L, 1L, 1L, 1L, 1L), v2171 = c(1L, 
    1L, 1L, 1L, NA, 1L), v2173 = c(1L, 1L, 1L, 1L, 1L, NA), v2174 = c(0L, 
    0L, 1L, 1L, 1L, 0L), v2175 = c(1L, 1L, 1L, 1L, 1L, 1L), v2177 = c(13L, 
    14L, 17L, 18L, 18L, 21L), v2178 = c(-0.42, -0.4, 0.1, 0.46, 
    0.31, 0.69), v2180 = c(NA, NA, 0L, NA, NA, NA), v2181 = c(NA, 
    NA, 0L, NA, 2L, NA), bio.1 = c(196, 215, 226, 229, 197, 225
    ), bio.10 = c(243, 251, 256, 256, 210, 232), bio.11 = c(138, 
    158, 190, 191, 174, 214), bio.12 = c(279, 454, 790, 971, 
    1283, 1681), bio.13 = c(70, 126, 160, 218, 241, 231), bio.14 = c(0, 
    0, 16, 0, 0, 12), bio.15 = c(107, 109, 68, 106, 84, 56), 
    bio.16 = c(196, 298, 386, 620, 625, 658), bio.17 = c(1, 0, 
    54, 0, 2, 75), bio.18 = c(150, 142, 386, 143, 337, 579), 
    bio.19 = c(1, 0, 54, 5, 18, 75), bio.2 = c(170, 158, 104, 
    149, 128, 115), bio.3 = c(58, 56, 57, 56, 62, 77), bio.4 = c(4166, 
    3903, 2560, 2600, 1439, 708), bio.5 = c(329, 335, 306, 354, 
    290, 287), bio.6 = c(37, 55, 125, 92, 85, 139), bio.7 = c(292, 
    280, 181, 262, 205, 148), bio.8 = c(235, 249, 256, 240, 203, 
    226), bio.9 = c(138, 158, 190, 192, 177, 214), continent = c("Africa", 
    "Africa", "Africa", "Africa", "Africa", "Africa"), ecoregion = c("Kalahari Xeric Savanna", 
    "Kalahari Acacia-Baikiaea Woodland", "Maputaland Coastal Forest", 
    "Zambezian Flooded Grassland", "Angolan Miombo Woodland", 
    "Southern Congolian Forest-Savanna Mosaic"), koeppengei = c("BWh", 
    "BSh", "Aw", "Aw", "BSh", "Aw"), lati = c(-23.31667, -19.8, 
    -25.966667, -15.19374, -12.2, -6.125174), long = c(17.08333, 
    20.56667, 32.583333, 23.00351, 15.86667, 18.15378), meanalt = c(1430.615, 
    1160.31510416667, 24.7480916030534, 1015.40633245383, 1501.58333333333, 
    847.565573770492), mht.name = c("Deserts and xeric shrublands", 
    "Tropical and subtropical grasslands, savannas, and shrublands", 
    "Tropical and subtropical moist broadleaf forests", "Flooded grasslands", 
    "Tropical and subtropical grasslands, savannas, and shrublands", 
    "Tropical and subtropical grasslands, savannas, and shrublands"
    ), mnnpp = c(-1.08114663311421, -0.73944547744944, -1.11362452325029, 
    0.140172087096408, 0.74204476271665, 0.583531521680504), 
    region = c("Southern Africa", "Southern Africa", "Eastern Africa", 
    "Eastern Africa", "Middle Africa", "Middle Africa"), religious_edifice = c("Absent", 
    "Absent", "Absent", "Absent", "Absent", "Absent")), .Names = c("V1_A", 
"ord", "socname", "focus", "hraf", "v1", "v3", "v4", "v5", "v6", 
"v7", "v8", "v9", "v10", "v11", "v12", "v13", "v15", "v19", "v20", 
"v21", "v22", "v34", "v35", "v36", "v61", "v62", "v63", "v64", 
"v65", "v66", "v67", "v68", "v72", "v75", "v93", "v94", "v95", 
"v96", "v97", "v98", "v144", "v150", "v151", "v152", "v153", 
"v154", "v155", "v181", "v182", "v186", "v187", "v188", "v189", 
"v192", "v193", "v194", "v195", "v196", "v197", "v198", "v199", 
"v200", "v201", "v203", "v204", "v205", "v206", "v207", "v232", 
"v233", "v234", "v236", "v237", "v241", "v242", "v243", "v244", 
"v245", "v246", "v254", "v255", "v256", "v257", "v258", "v259", 
"v260", "v261", "v262", "v263", "v264", "v268", "v270", "v271", 
"v283", "v284", "v285", "v286", "v287", "v288", "v289", "v291", 
"v292", "v457", "v458", "v459", "v460", "v533", "v534", "v535", 
"v536", "v537", "v538", "v539", "v540", "v541", "v542", "v543", 
"v544", "v545", "v546", "v547", "v548", "v549", "v550", "v551", 
"v552", "v553", "v554", "v555", "v556", "v557", "v558", "v559", 
"v560", "v561", "v563", "v564", "v565", "v566", "v567", "v573", 
"v574", "v575", "v576", "v577", "v578", "v579", "v580", "v581", 
"v582", "v584", "v587", "v588", "v599", "v617", "v622", "v623", 
"v633", "v635", "v652", "v653", "v654", "v655", "v656", "v665", 
"v671", "v672", "v676", "v678", "v679", "v681", "v693", "v694", 
"v695", "v708", "v731", "v757", "v767", "v768", "v773", "v774", 
"v788", "v790", "v791", "v792", "v814", "v815", "v816", "v817", 
"v818", "v819", "v820", "v821", "v822", "v823", "v824", "v825", 
"v826", "v833", "v835", "v840", "v843", "v854", "v855", "v856", 
"v858", "v859", "v869", "v879", "v880", "v881", "v882", "v884", 
"v898", "v913", "v915", "v921", "v922", "v924", "v926", "v928", 
"v929", "v930", "v931", "v932", "v966", "v1007", "v1008", "v1011", 
"v1012", "v1013", "v1014", "v1015", "v1016", "v1017", "v1018", 
"v1019", "v1020", "v1021", "v1022", "v1023", "v1026", "v1027", 
"v1028", "v1029", "v1030", "v1032", "v1033", "v1034", "v1035", 
"v1036", "v1037", "v1038", "v1047", "v1048", "v1049", "v1050", 
"v1054", "v1055", "v1056", "v1059", "v1123", "v1125", "v1127", 
"v1128", "v1132", "v1188", "v1189", "v1253", "v1254", "v1255", 
"v1256", "v1257", "v1258", "v1259", "v1260", "v1262", "v1263", 
"v1352", "v1354", "v1355", "v1362", "v1458", "v1489", "v1666", 
"v1683", "v1684", "v1685", "v1686", "v1687", "v1688", "v1692", 
"v1693", "v1694", "v1695", "v1697", "v1698", "v1699", "v1700", 
"v1701", "v1702", "v1703", "v1704", "v1705", "v1706", "v1707", 
"v1708", "v1709", "v1745", "v1767", "v1779", "v1780", "v1850", 
"v1851", "v1852", "v1853", "v1854", "v1855", "v1856", "v1857", 
"v1858", "v1889", "v1890", "v1892", "v1893", "v1895", "v1896", 
"v1898", "v1899", "v1900", "v1901", "v1902", "v1903", "v1913", 
"v2001", "v2002", "v2003", "v2004", "v2005", "v2006", "v2007", 
"v2013", "v2039", "v2106", "v2126", "v2127", "v2128", "v2129", 
"v2130", "v2131", "v2132", "v2133", "v2134", "v2135", "v2136", 
"v2137", "v2138", "v2139", "v2140", "v2141", "v2142", "v2143", 
"v2144", "v2145", "v2146", "v2147", "v2148", "v2149", "v2150", 
"v2151", "v2152", "v2153", "v2154", "v2155", "v2156", "v2157", 
"v2158", "v2159", "v2160", "v2161", "v2162", "v2163", "v2164", 
"v2165", "v2166", "v2167", "v2169", "v2171", "v2173", "v2174", 
"v2175", "v2177", "v2178", "v2180", "v2181", "bio.1", "bio.10", 
"bio.11", "bio.12", "bio.13", "bio.14", "bio.15", "bio.16", "bio.17", 
"bio.18", "bio.19", "bio.2", "bio.3", "bio.4", "bio.5", "bio.6", 
"bio.7", "bio.8", "bio.9", "continent", "ecoregion", "koeppengei", 
"lati", "long", "meanalt", "mht.name", "mnnpp", "region", "religious_edifice"
), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"
))

以下是代码:

library(lattice)
library(mice)
init = mice(SCCS4, maxit=0) 
meth = init$method
predM = init$predictorMatrix

predM[, c("V1_A")]=0
predM[, c("ord")]=0
predM[, c("socname")]=0
predM[, c("focus")]=0
predM[, c("hraf")]=0

meth[c("continent")]=""
meth[c("ecoregion")]=""
meth[c("koeppengei")]=""
meth[c("lati")]=""
meth[c("long")]=""
meth[c("meanalt")]=""
meth[c("mht.name")]=""
meth[c("mnnpp")]=""
meth[c("region")]=""
meth[c("v285")]=""
meth[c("v288")]=""
meth[c("v289")]=""
meth[c("v291")]=""
meth[c("v292")]=""
meth[c("v582")]=""
meth[c("v587")]=""
meth[c("v588")]=""
meth[c("v617")]=""
meth[c("v695")]=""
meth[c("v708")]=""
meth[c("v788")]=""
meth[c("v840")]=""
meth[c("v843")]=""
meth[c("v1007")]=""
meth[c("v1008")]=""
meth[c("v1011")]=""
meth[c("v1012")]=""
meth[c("v1013")]=""
meth[c("v1014")]=""
meth[c("v1015")]=""
meth[c("v1016")]=""
meth[c("v1017")]=""
meth[c("v1018")]=""
meth[c("v1019")]=""
meth[c("v1020")]=""
meth[c("v1021")]=""
meth[c("v1022")]=""
meth[c("v1023")]=""
meth[c("v1026")]=""
meth[c("v1027")]=""
meth[c("v1028")]=""
meth[c("v1029")]=""
meth[c("v1030")]=""
meth[c("v1032")]=""
meth[c("v1033")]=""
meth[c("v1034")]=""
meth[c("v1035")]=""
meth[c("v1036")]=""
meth[c("v1037")]=""
meth[c("v1038")]=""
meth[c("v1047")]=""
meth[c("v1048")]=""
meth[c("v1049")]=""
meth[c("v1050")]=""
meth[c("v1054")]=""
meth[c("v1055")]=""
meth[c("v1056")]=""
meth[c("v1059")]=""
meth[c("v1352")]=""
meth[c("v1354")]=""
meth[c("v1355")]=""
meth[c("v1362")]=""
meth[c("v1458")]=""
meth[c("v1489")]=""
meth[c("v1779")]=""
meth[c("v1780")]=""
meth[c("v2129")]=""

imputed = mice(SCCS4, method=meth, predictorMatrix=predM, m=5)

 iter imp variable
  1   1  v1Error in cor(xobs[, keep, drop = FALSE], use = "all.obs") : 'x' is empty

@qdread - 我相信这是源代码(使用getAnywhere(mice))。

function (data, m = 5, method = vector("character", length = ncol(data)), 
    predictorMatrix = (1 - diag(1, ncol(data))), where = is.na(data), 
    visitSequence = NULL, form = vector("character", length = ncol(data)), 
    post = vector("character", length = ncol(data)), defaultMethod = c("pmm", 
        "logreg", "polyreg", "polr"), maxit = 5, diagnostics = TRUE, 
    printFlag = TRUE, seed = NA, imputationMethod = NULL, defaultImputationMethod = NULL, 
    data.init = NULL, ...) 
{
    call <- match.call()
    if (!is.na(seed)) 
        set.seed(seed)
    if (!(is.matrix(data) || is.data.frame(data))) 
        stop("Data should be a matrix or data frame")
    nvar <- ncol(data)
    if (nvar < 2) 
        stop("Data should contain at least two columns")
    data <- as.data.frame(data)
    nmis <- apply(is.na(data), 2, sum)
    varnames <- colnames(data)
    if (!(is.matrix(where) || is.data.frame(where))) 
        stop("Argument `where` not a matrix or data frame")
    if (!all(dim(data) == dim(where))) 
        stop("Arguments `data` and `where` not of same size")
    nwhere <- apply(where, 2, sum)
    state <- list(it = 0, im = 0, co = 0, dep = "", meth = "", 
        log = FALSE)
    loggedEvents <- data.frame(it = 0, im = 0, co = 0, dep = "", 
        meth = "", out = "")
    if (!is.null(imputationMethod)) 
        method <- imputationMethod
    if (!is.null(defaultImputationMethod)) 
        defaultMethod <- defaultImputationMethod
    setup <- list(visitSequence = visitSequence, method = method, 
        defaultMethod = defaultMethod, predictorMatrix = predictorMatrix, 
        form = form, post = post, nvar = nvar, nmis = nmis, nwhere = nwhere, 
        varnames = varnames)
    setup <- check.visitSequence(setup, where)
    setup <- check.method(setup, data)
    setup <- check.predictorMatrix(setup)
    setup <- check.data(setup, data, ...)
    method <- setup$method
    predictorMatrix <- setup$predictorMatrix
    visitSequence <- setup$visitSequence
    post <- setup$post
    p <- padModel(data, method, predictorMatrix, visitSequence, 
        form, post, nvar)
    r <- (!is.na(p$data))
    imp <- vector("list", ncol(p$data))
    if (m > 0) {
        for (j in visitSequence) {
            y <- data[, j]
            ry <- r[, j]
            wy <- where[, j]
            imp[[j]] <- as.data.frame(matrix(NA, nrow = sum(wy), 
                ncol = m))
            dimnames(imp[[j]]) <- list(row.names(data)[wy], 1:m)
            if (method[j] != "") {
                for (i in seq_len(m)) {
                  if (nmis[j] < nrow(data)) {
                    if (is.null(data.init)) {
                      imp[[j]][, i] <- mice.impute.sample(y, 
                        ry, wy = wy, ...)
                    }
                    else {
                      imp[[j]][, i] <- data.init[wy, j]
                    }
                  }
                  else imp[[j]][, i] <- rnorm(nrow(data))
                }
            }
        }
    }
    from <- 1
    to <- from + maxit - 1
    q <- sampler(p, data, where, m, imp, r, visitSequence, c(from, 
        to), printFlag, ...)
    for (j in p$visitSequence) {
        p$data[!r[, j], j] <- NA
    }
    imp <- q$imp[seq_len(nvar)]
    names(imp) <- varnames
    names(method) <- varnames
    names(form) <- varnames
    names(post) <- varnames
    names(visitSequence) <- varnames[visitSequence]
    if (!state$log) 
        loggedEvents <- NULL
    if (state$log) 
        row.names(loggedEvents) <- seq_len(nrow(loggedEvents))
    midsobj <- list(call = call, data = as.data.frame(p$data[, 
        seq_len(nvar)]), where = where, m = m, nmis = nmis, imp = imp, 
        method = method, predictorMatrix = predictorMatrix, visitSequence = visitSequence, 
        form = form, post = post, seed = seed, iteration = q$iteration, 
        lastSeedValue = .Random.seed, chainMean = q$chainMean, 
        chainVar = q$chainVar, loggedEvents = loggedEvents, pad = p)
    if (!diagnostics) 
        midsobj$pad <- NULL
    oldClass(midsobj) <- "mids"
    return(midsobj)
}
<bytecode: 0x10e254e00>
<environment: namespace:mice>
> 

0 个答案:

没有答案