This report was automatically generated with the R package knitr (version 1.5).
library(faraway)
data(chmiss, package = "faraway")
chmiss
race fire theft age involact income
60626 10.0 6.2 29 60.4 NA 11.744
60640 22.2 9.5 44 76.5 0.1 9.323
60613 19.6 10.5 36 NA 1.2 9.948
60657 17.3 7.7 37 NA 0.5 10.656
60614 24.5 8.6 53 81.4 0.7 9.730
60610 54.0 34.1 68 52.6 0.3 8.231
60611 4.9 11.0 75 42.6 0.0 21.480
60625 7.1 6.9 18 78.5 0.0 11.104
60618 5.3 7.3 31 90.1 NA 10.694
60647 21.5 15.1 NA 89.8 1.1 9.631
60622 43.1 29.1 34 82.7 1.9 7.995
60631 1.1 2.2 14 40.2 0.0 13.722
60646 NA 5.7 11 27.9 0.0 16.250
60656 1.7 2.0 11 7.7 0.0 13.686
60630 1.6 2.5 22 63.8 0.0 12.405
60634 1.5 3.0 NA 51.2 0.0 12.198
60641 1.8 5.4 27 85.1 0.0 11.600
60635 1.0 2.2 9 44.4 0.0 12.765
60639 2.5 7.2 29 84.2 0.2 11.084
60651 NA 15.1 30 89.8 0.8 10.510
60644 59.8 16.5 40 NA 0.8 9.784
60624 94.4 18.4 32 72.9 1.8 7.342
60612 86.2 36.2 41 63.1 1.8 6.565
60607 50.2 NA 147 83.0 0.9 7.459
60623 74.2 18.5 22 78.3 1.9 8.014
60608 55.5 NA 29 79.0 1.5 8.177
60616 NA 12.2 46 48.0 0.6 8.212
60632 4.4 5.6 23 71.5 0.3 11.230
60609 46.2 21.8 4 73.1 1.3 NA
60653 99.7 21.6 31 65.0 0.9 5.583
60615 73.5 9.0 39 75.4 0.4 8.564
60638 10.7 3.6 15 20.8 0.0 12.102
60629 1.5 5.0 32 61.8 NA 11.876
60636 48.8 28.6 27 78.1 1.4 9.742
60621 98.9 17.4 NA 68.6 2.2 7.520
60637 90.6 11.3 34 73.4 0.8 7.388
60652 1.4 3.4 17 2.0 0.0 13.842
60620 71.2 11.9 46 NA 0.9 11.040
60619 94.1 10.5 42 55.9 0.9 10.332
60649 66.1 10.7 NA 67.5 0.4 10.908
60617 NA 10.8 34 58.0 0.9 11.156
60655 1.0 4.8 19 15.2 0.0 13.323
60643 42.5 10.4 25 40.8 0.5 12.960
60628 35.1 15.6 28 57.8 1.0 NA
60627 47.4 7.0 3 11.4 0.2 10.080
60633 34.0 7.1 23 49.2 0.3 11.428
60645 3.1 4.9 27 NA 0.0 13.731
summary(chmiss)
race fire theft age
Min. : 1.00 Min. : 2.0 Min. : 3.0 Min. : 2.0
1st Qu.: 3.75 1st Qu.: 5.6 1st Qu.: 22.0 1st Qu.:48.3
Median :24.50 Median : 9.5 Median : 29.0 Median :64.4
Mean :35.61 Mean :11.4 Mean : 32.6 Mean :60.0
3rd Qu.:57.65 3rd Qu.:15.1 3rd Qu.: 38.0 3rd Qu.:78.2
Max. :99.70 Max. :36.2 Max. :147.0 Max. :90.1
NA's :4 NA's :2 NA's :4 NA's :5
involact income
Min. :0.000 Min. : 5.58
1st Qu.:0.000 1st Qu.: 8.56
Median :0.500 Median :10.69
Mean :0.648 Mean :10.74
3rd Qu.:0.925 3rd Qu.:12.10
Max. :2.200 Max. :21.48
NA's :3 NA's :2
rowSums(is.na(chmiss))
60626 60640 60613 60657 60614 60610 60611 60625 60618 60647 60622 60631
1 0 1 1 0 0 0 0 1 1 0 0
60646 60656 60630 60634 60641 60635 60639 60651 60644 60624 60612 60607
1 0 0 1 0 0 0 1 1 0 0 1
60623 60608 60616 60632 60609 60653 60615 60638 60629 60636 60621 60637
0 1 1 0 1 0 0 0 1 0 1 0
60652 60620 60619 60649 60617 60655 60643 60628 60627 60633 60645
0 1 0 1 1 0 0 1 0 0 1
image(is.na(chmiss), axes = FALSE, col = gray(1:0))
axis(2, at = 0:5/5, labels = colnames(chmiss))
axis(1, at = 0:46/46, labels = row.names(chmiss), las = 2)
data(chredlin, package = "faraway")
modfull <- lm(involact ~ ., chredlin)
sumary(modfull)
Estimate Std. Error t value Pr(>|t|)
(Intercept) -0.62909 0.51199 -1.23 0.2264
race 0.00890 0.00264 3.37 0.0017
fire 0.03907 0.00864 4.52 5.3e-05
theft -0.01021 0.00292 -3.49 0.0012
age 0.00842 0.00292 2.88 0.0063
income 0.02470 0.03209 0.77 0.4461
sides 0.02403 0.12505 0.19 0.8486
n = 47, p = 7, Residual SE = 0.34, R-Squared = 0.75
modmiss <- lm(involact ~ ., chmiss)
sumary(modmiss)
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.11648 0.60576 -1.84 0.07947
race 0.01049 0.00313 3.35 0.00302
fire 0.04388 0.01032 4.25 0.00036
theft -0.01722 0.00590 -2.92 0.00822
age 0.00938 0.00349 2.68 0.01390
income 0.06870 0.04216 1.63 0.11808
n = 27, p = 6, Residual SE = 0.34, R-Squared = 0.79
(cmeans <- colMeans(chmiss, na.rm = TRUE))
race fire theft age involact income
35.6093 11.4244 32.6512 59.9690 0.6477 10.7359
mchm <- chmiss
for (i in c(1:4, 6)) mchm[is.na(chmiss[, i]), i] <- cmeans[i]
imod <- lm(involact ~ ., mchm)
sumary(imod)
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.07080 0.50945 0.14 0.890
race 0.00712 0.00271 2.63 0.012
fire 0.02874 0.00939 3.06 0.004
theft -0.00306 0.00275 -1.11 0.272
age 0.00608 0.00321 1.90 0.066
income -0.02709 0.03168 -0.86 0.398
n = 44, p = 6, Residual SE = 0.38, R-Squared = 0.68
lmodr <- lm(race ~ fire + theft + age + income, chmiss)
chmiss[is.na(chmiss$race), ]
race fire theft age involact income
60646 NA 5.7 11 27.9 0.0 16.250
60651 NA 15.1 30 89.8 0.8 10.510
60616 NA 12.2 46 48.0 0.6 8.212
60617 NA 10.8 34 58.0 0.9 11.156
predict(lmodr, chmiss[is.na(chmiss$race), ])
60646 60651 60616 60617
-17.85 26.36 70.39 32.62
lmodr <- lm(logit(race/100) ~ fire + theft + age + income, chmiss)
ilogit(predict(lmodr, chmiss[is.na(chmiss$race), ])) * 100
60646 60651 60616 60617
0.4191 14.7320 84.2654 21.3121
chredlin$race[is.na(chmiss$race)]
[1] 1.0 13.4 62.3 36.4
require(Amelia)
Loading required package: Amelia
Loading required package: foreign
Loading required package: Rcpp
Loading required package: RcppArmadillo
##
## Amelia II: Multiple Imputation
## (Version 1.7.2, built: 2013-04-03)
## Copyright (C) 2005-2014 James Honaker, Gary King and Matthew Blackwell
## Refer to http://gking.harvard.edu/amelia/ for more information
##
set.seed(123)
chimp <- amelia(chmiss, m = 25)
-- Imputation 1 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21
-- Imputation 2 --
1 2 3 4 5 6 7 8 9 10 11
-- Imputation 3 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
-- Imputation 4 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27
-- Imputation 5 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
-- Imputation 6 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27
-- Imputation 7 --
1 2 3 4 5 6 7 8 9 10 11 12
-- Imputation 8 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
-- Imputation 9 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
-- Imputation 10 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69
-- Imputation 11 --
1 2 3 4 5 6 7 8 9 10 11 12
-- Imputation 12 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
-- Imputation 13 --
1 2 3 4 5 6 7 8 9 10 11 12
-- Imputation 14 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
-- Imputation 15 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
-- Imputation 16 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73
-- Imputation 17 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
-- Imputation 18 --
1 2 3 4 5 6 7 8 9 10 11
-- Imputation 19 --
1 2 3 4 5 6 7
-- Imputation 20 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
-- Imputation 21 --
1 2 3 4 5 6 7 8
-- Imputation 22 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25
-- Imputation 23 --
1 2 3 4 5 6 7 8 9
-- Imputation 24 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
-- Imputation 25 --
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
21 22 23 24 25
betas <- NULL
ses <- NULL
for (i in 1:chimp$m) {
lmod <- lm(involact ~ race + fire + theft + age, chimp$imputations[[i]])
betas <- rbind(betas, coef(lmod))
ses <- rbind(ses, coef(summary(lmod))[, 2])
}
(cr <- mi.meld(q = betas, se = ses))
$q.mi
(Intercept) race fire theft age
[1,] -0.2255 0.007595 0.03583 -0.008689 0.00708
$se.mi
(Intercept) race fire theft age
[1,] 0.1574 0.00197 0.008516 0.004577 0.00258
cr$q.mi/cr$se.mi
(Intercept) race fire theft age
[1,] -1.433 3.855 4.207 -1.898 2.744
The R session information (including the OS info, R version and all packages used):
sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-apple-darwin13.1.0 (64-bit)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] graphics grDevices utils datasets methods stats base
other attached packages:
[1] Amelia_1.7.2 RcppArmadillo_0.4.200.0 Rcpp_0.11.1
[4] foreign_0.8-61 faraway_1.0.6 knitr_1.5
[7] ggplot2_0.9.3.1
loaded via a namespace (and not attached):
[1] colorspace_1.2-4 dichromat_2.0-0 digest_0.6.4
[4] evaluate_0.5.3 formatR_0.10 grid_3.1.0
[7] gtable_0.1.2 labeling_0.2 MASS_7.3-31
[10] munsell_0.4.2 plyr_1.8.1 proto_0.3-10
[13] RColorBrewer_1.0-5 reshape2_1.2.2 scales_0.2.3
[16] stringr_0.6.2 tools_3.1.0
Sys.time()
[1] "2014-06-16 14:02:26 BST"