age hyp bmi chl
13 1 1 1 1 0
3 1 1 1 0 1
1 1 1 0 1 1
1 1 0 0 1 2
7 1 0 0 0 3
0 8 9 10 27
Course 3 — #courses
Note
Inference lab using the five-step template: Hypothesis → Visualise → Assumptions → Conduct → Conclude.
mice.Session 1 of this week (MCAR/MAR/MNAR).
Multiple imputation (MI) replaces each missing value with several plausible values drawn from a predictive distribution, producing m completed datasets. Each completed dataset is analysed separately; the results are pooled using Rubin’s rules so that the standard errors reflect both the within-imputation uncertainty (ordinary sampling variance) and the between-imputation uncertainty (the variance of the imputations themselves).
mice implements MI by chained equations: for each incomplete variable, it fits a conditional model given the others and draws imputations from the posterior predictive distribution of that model. The procedure iterates until the imputations stabilise. The standard diagnostics are trace plots (should mix and not drift) and density plots comparing observed and imputed values (should overlap but need not match exactly).
The inclusion of the outcome in the imputation model is not optional. Omitting it biases the imputations toward the null and attenuates the estimated effect in the pooled analysis.
In the mice::nhanes teaching dataset, the cholesterol outcome (chl) is related to age and BMI (bmi). We will estimate that relationship under MI.
age hyp bmi chl
13 1 1 1 1 0
3 1 1 1 0 1
1 1 1 0 1 1
1 1 0 0 1 2
7 1 0 0 0 3
0 8 9 10 27
MAR conditional on the variables in the imputation model; a compatible imputation model (predictive mean matching by default); enough imputations (here m = 10) to stabilise the pooled standard errors.
Class: mids
Number of multiple imputations: 10
Imputation methods:
age bmi hyp chl
"" "pmm" "pmm" "pmm"
PredictorMatrix:
age bmi hyp chl
age 0 1 1 1
bmi 1 0 1 1
hyp 1 1 0 1
chl 1 1 1 0


term estimate std.error statistic df p.value 2.5 %
1 (Intercept) -20.438744 62.937778 -0.3247452 16.005017 0.74957990 -153.8574736
2 age 35.356555 11.358554 3.1127691 9.992386 0.01101837 10.0455054
3 bmi 5.626004 2.167537 2.5955751 12.785700 0.02243612 0.9353351
97.5 % conf.low conf.high
1 112.97999 -153.8574736 112.97999
2 60.66760 10.0455054 60.66760
3 10.31667 0.9353351 10.31667
Multiple imputation of the
nhanesdataset (m = 10, predictive mean matching) gave a pooled coefficient for BMI on cholesterol of 5.63 (see pooled table above), with standard errors reflecting both within- and between-imputation uncertainty through Rubin’s rules.
pool().R version 4.6.1 (2026-06-24)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 26.04.1 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.32.so; LAPACK version 3.12.0
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8
[4] LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
time zone: UTC
tzcode source: system (glibc)
attached base packages:
[1] stats graphics grDevices datasets utils methods base
other attached packages:
[1] mice_3.19.0 lubridate_1.9.5 forcats_1.0.1 stringr_1.6.0
[5] dplyr_1.2.1 purrr_1.2.2 readr_2.2.0 tidyr_1.3.2
[9] tibble_3.3.1 ggplot2_4.0.3 tidyverse_2.0.0
loaded via a namespace (and not attached):
[1] gtable_0.3.6 shape_1.4.6.1 xfun_0.62 lattice_0.22-9
[5] tzdb_0.5.0 vctrs_0.7.3 tools_4.6.1 Rdpack_2.6.6
[9] generics_0.1.4 stats4_4.6.1 pan_2.0 pkgconfig_2.0.3
[13] jomo_2.7-6 Matrix_1.7-5 RColorBrewer_1.1-3 S7_0.2.2
[17] lifecycle_1.0.5 compiler_4.6.1 farver_2.1.2 codetools_0.2-20
[21] htmltools_0.5.9 yaml_2.3.12 glmnet_5.2 pillar_1.11.1
[25] nloptr_2.2.1 MASS_7.3-65 reformulas_0.4.4 iterators_1.0.14
[29] rpart_4.1.27 boot_1.3-32 foreach_1.5.2 mitml_0.4-5
[33] nlme_3.1-169 tidyselect_1.2.1 digest_0.6.39 stringi_1.8.9
[37] labeling_0.4.3 splines_4.6.1 fastmap_1.2.0 grid_4.6.1
[41] cli_3.6.6 magrittr_2.0.5 survival_3.8-6 broom_1.0.13
[45] withr_3.0.3 scales_1.4.0 backports_1.5.1 timechange_0.4.0
[49] rmarkdown_2.32 otel_0.2.0 nnet_7.3-20 lme4_2.1-0
[53] hms_1.1.4 evaluate_1.0.5 knitr_1.52 rbibutils_2.4.1
[57] rlang_1.3.0 Rcpp_1.1.2 glue_1.8.1 renv_1.3.1
[61] minqa_1.2.8 jsonlite_2.0.0 R6_2.6.1