Missing observations are not simply empty cells to be removed. A missing measurement can change the composition of a research sample, alter a regression estimate, and introduce uncertainty that an ordinary standard error cannot describe. Multiple imputation addresses this problem by creating several plausible versions of an incomplete dataset and combining the resulting estimates, rather than treating any one imputed value as the truth.
This tutorial uses a historical Dutch growth-reference sample to estimate the association between body height and weight after adjusting for age and geographic region. The statistical lesson transfers to incomplete agricultural phenotypes, soil measurements and survey responses, provided that the imputation model respects their sampling or experimental design.
1. Inspect the source data
The boys dataset distributed with the R package mice contains 748 boys from the 1997 Dutch growth-reference study. The observations are cross-sectional, not repeated measurements of individual growth trajectories. Age is measured in years, height in centimetres, and weight in kilograms. The nine variables include derived BMI and developmental measures that are not all appropriate for the same imputation model. Read the dataset documentation for the study context. The package can be installed with install.packages(c("mice", "ggplot2")) if needed. The original data can also be exported with write.csv(mice::boys, "boys.csv", row.names = FALSE, na = "NA").
library(mice)Warning: package 'mice' was built under R version 4.5.3
Attaching package: 'mice'
The following object is masked from 'package:stats':
filter
The following objects are masked from 'package:base':
cbind, rbind
library(ggplot2)
output_dir <- "04_outputs_quarto"
dir.create(output_dir, showWarnings = FALSE, recursive = TRUE)
boys <- read.csv("01_data/boys.csv", na.strings = "NA")
stopifnot(identical(names(boys), c("age", "hgt", "wgt", "bmi", "hc",
"gen", "phb", "tv", "reg")),
nrow(boys) == 748L, !anyNA(boys$age),
all(boys$hgt > 0, na.rm = TRUE), all(boys$wgt > 0, na.rm = TRUE))
missing <- data.frame(variable = names(boys), n_missing = colSums(is.na(boys)))
missing$pct <- 100 * missing$n_missing / nrow(boys)
print(missing, row.names = FALSE) variable n_missing pct
age 0 0.0000000
hgt 20 2.6737968
wgt 4 0.5347594
bmi 21 2.8074866
hc 46 6.1497326
gen 503 67.2459893
phb 503 67.2459893
tv 522 69.7860963
reg 3 0.4010695
write.csv(missing, file.path(output_dir, "01_missingness.csv"), row.names = FALSE)
p_missing <- ggplot(missing, aes(reorder(variable, pct), pct)) +
geom_col(fill = "#287C8E", width = 0.7) + coord_flip() +
labs(x = NULL, y = "Missing observations (%)") + theme_minimal(base_size = 13)
print(p_missing)
ggsave(file.path(output_dir, "01_missingness.png"), p_missing, width = 7, height = 4.5, dpi = 300)
The total number of unavailable cells is 1622, but their distribution matters more than the overall percentage. In particular, developmental measurements have a different availability pattern from the height and weight measurements. An unavailable developmental assessment should not be interpreted as zero or automatically assigned a biologically inappropriate stage.
2. Understand missingness before choosing a method
Let \(R\) denote a missingness indicator, \(Y_{obs}\) the observed data, and \(Y_{mis}\) the unavailable values. Under MCAR, the probability of missingness does not depend on either observed or unobserved measurements. Under MAR, it can depend on observed measurements, but conditional on them it does not depend on the missing values themselves. Under MNAR, dependence on unobserved values remains even after conditioning on observed information.
A descriptive age-group comparison can reveal whether height availability is associated with a known predictor. It cannot prove MAR or rule out MNAR. The age groups here are descriptive bins, not the age specification used in the regression.
age_group <- cut(boys$age, c(0, 2, 8, 12, 16, Inf), include.lowest = TRUE,
labels = c("0-2", ">2-8", ">8-12", ">12-16", ">16"))
age_missing <- aggregate(cbind(n = rep(1, nrow(boys)), missing = as.integer(is.na(boys$hgt))),
list(age_group = age_group), sum)
age_missing$pct <- 100 * age_missing$missing / age_missing$n
print(age_missing, row.names = FALSE) age_group n missing pct
0-2 216 17 7.8703704
>2-8 107 1 0.9345794
>8-12 100 1 1.0000000
>12-16 178 0 0.0000000
>16 147 1 0.6802721
write.csv(age_missing, file.path(output_dir, "02_height_missing_by_age.csv"), row.names = FALSE)
p_age <- ggplot(age_missing, aes(age_group, pct)) +
geom_col(fill = "#C17939", width = 0.65) +
geom_text(aes(label = paste0(missing, "/", n)), vjust = -0.4, size = 3.5) +
scale_y_continuous(expand = expansion(mult = c(0, 0.18))) +
labs(x = "Age (years)", y = "Height missing (%)") + theme_minimal(base_size = 13)
print(p_age)
ggsave(file.path(output_dir, "02_height_missing_by_age.png"), p_age, width = 7, height = 4.5, dpi = 300)
The youngest age group contains 17 unavailable heights among 216 boys; the other groups combined contain 3 among 532. This pattern is relevant to the imputation model because age is fully observed and closely related to physical growth. It is not an explanation of why any particular measurement is absent.
3. Define one regression model for both analyses
The outcome is log weight and the principal predictor is log height. Body mass changes nonlinearly with height and age, so a log–log specification provides a proportional association rather than assuming that each centimetre adds a constant number of kilograms across the age range. A natural cubic spline with four degrees of freedom accommodates a flexible age relationship without making age categories part of the fitted model. Region enters as a categorical adjustment, with north as the reference. The spline basis is fixed using all observed ages, ensuring the same functional form in every analysis.
\[ \log(W_i)=\beta_0+\beta_1\log(H_i)+f(A_i)+\gamma_{R_i}+\varepsilon_i \]
BMI is calculated from weight and height, so including BMI as an independent imputation target would introduce near-deterministic dependence. Developmental measurements are omitted because eligibility and nonresponse cannot be distinguished reliably from the available fields. Head circumference is not required by the primary regression; its potential value as an auxiliary predictor deserves separate consideration.
region_levels <- c("north", "east", "west", "south", "city")
stopifnot(all(boys$reg[!is.na(boys$reg)] %in% region_levels))
# Fix the spline basis using the fully observed ages, before deleting any rows.
age_basis <- as.data.frame(splines::ns(boys$age, df = 4))
names(age_basis) <- paste0("age", 1:4)
core <- data.frame(log_wgt = log(boys$wgt), log_hgt = log(boys$hgt),
reg = factor(boys$reg, levels = region_levels), age_basis)
model_formula <- log_wgt ~ log_hgt + age1 + age2 + age3 + age4 + reg
cc <- complete.cases(core)
sample_counts <- data.frame(sample = c("All rows", "All nine complete", "Core complete"),
n = c(nrow(boys), sum(complete.cases(boys)), sum(cc)))
print(sample_counts, row.names = FALSE) sample n
All rows 748
All nine complete 223
Core complete 724
write.csv(sample_counts, file.path(output_dir, "03_sample_counts.csv"), row.names = FALSE)
print(md.pattern(core, plot = FALSE)) age1 age2 age3 age4 reg log_wgt log_hgt
724 1 1 1 1 1 1 1 0
17 1 1 1 1 1 1 0 1
1 1 1 1 1 1 0 1 1
3 1 1 1 1 1 0 0 2
3 1 1 1 1 0 1 1 1
0 0 0 0 3 4 20 27
fit_cc <- lm(model_formula, data = core[cc, ])
print(summary(fit_cc))
Call:
lm(formula = model_formula, data = core[cc, ])
Residuals:
Min 1Q Median 3Q Max
-0.31015 -0.07302 -0.01013 0.06237 0.42785
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -8.86161 0.33682 -26.310 < 2e-16 ***
log_hgt 2.59505 0.08228 31.540 < 2e-16 ***
age1 -0.51534 0.06627 -7.777 2.61e-14 ***
age2 -0.32009 0.07733 -4.140 3.90e-05 ***
age3 -0.69646 0.15482 -4.499 7.98e-06 ***
age4 -0.07538 0.06039 -1.248 0.212
regeast -0.01536 0.01527 -1.006 0.315
regwest -0.01631 0.01445 -1.129 0.259
regsouth -0.01819 0.01492 -1.219 0.223
regcity 0.01392 0.01813 0.768 0.443
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.1094 on 714 degrees of freedom
Multiple R-squared: 0.9859, Adjusted R-squared: 0.9858
F-statistic: 5564 on 9 and 714 DF, p-value: < 2.2e-16
Only 223 rows are complete on all nine fields, whereas 724 are complete for this particular model. The complete-case analysis must be based on the variables actually required, not on unrelated missing measurements. Its estimate of the height elasticity is 2.595. This is a conditional association, not an estimate of the causal effect of changing a child’s height.
4. Impute with chained equations
MICE cycles through the incomplete variables, updating each conditional model using the currently observed or imputed values of the other variables. Predictive mean matching (PMM) uses a stochastic regression prediction to find observed donors with similar predicted values, then draws a donor’s observed measurement. Here it operates on log height and log weight, so the analysis and imputation scales agree. The fully observed age basis is included as a predictor, not imputed. Region is imputed with multinomial logistic regression because its five categories have no natural order.
Each of 40 chains runs for 20 iterations, with a fixed seed for reproducibility. These are initial computational settings, not a guarantee of convergence. Including the response among the imputation predictors helps preserve associations needed by the scientific model.
method <- make.method(core)
method[] <- ""
method[c("log_wgt", "log_hgt")] <- "pmm"
method["reg"] <- "polyreg"
pred <- make.predictorMatrix(core)
pred[method == "", ] <- 0
print(method) log_wgt log_hgt reg age1 age2 age3 age4
"pmm" "pmm" "polyreg" "" "" "" ""
print(pred) log_wgt log_hgt reg age1 age2 age3 age4
log_wgt 0 1 1 1 1 1 1
log_hgt 1 0 1 1 1 1 1
reg 1 1 0 1 1 1 1
age1 0 0 0 0 0 0 0
age2 0 0 0 0 0 0 0
age3 0 0 0 0 0 0 0
age4 0 0 0 0 0 0 0
write.csv(data.frame(variable = names(method), method = unname(method)),
file.path(output_dir, "04_imputation_methods.csv"), row.names = FALSE)
write.csv(pred, file.path(output_dir, "05_predictor_matrix.csv"))
imp <- mice(core, m = 40, maxit = 20, method = method,
predictorMatrix = pred, seed = 20261128, printFlag = FALSE)Warning: Number of logged events: 1147
print(imp)Class: mids
Number of multiple imputations: 40
Imputation methods:
log_wgt log_hgt reg age1 age2 age3 age4
"pmm" "pmm" "polyreg" "" "" "" ""
PredictorMatrix:
log_wgt log_hgt reg age1 age2 age3 age4
log_wgt 0 1 1 1 1 1 1
log_hgt 1 0 1 1 1 1 1
reg 1 1 0 1 1 1 1
age1 0 0 0 0 0 0 0
age2 0 0 0 0 0 0 0
age3 0 0 0 0 0 0 0
Number of logged events: 1147
it im dep meth out
1 1 1 log_hgt pmm log_wgt
2 1 2 log_hgt pmm log_wgt
3 1 3 log_hgt pmm log_wgt
4 1 4 log_hgt pmm log_wgt
5 1 5 log_hgt pmm log_wgt
6 1 6 log_hgt pmm log_wgt
events <- imp$loggedEvents
if (is.null(events)) events <- data.frame(it = integer(), im = integer(),
dep = character(), meth = character(), out = character())
event_summary <- if (nrow(events) > 0) {
x <- as.data.frame(table(events$dep, events$out), stringsAsFactors = FALSE)
names(x) <- c("imputed_variable", "predictor_affected", "n_events")
subset(x, n_events > 0)
} else {
data.frame(imputed_variable = character(), predictor_affected = character(),
n_events = integer())
}
print(event_summary) imputed_variable predictor_affected n_events
2 log_wgt log_hgt 394
3 log_hgt log_wgt 753
write.csv(events, file.path(output_dir, "06_logged_events.csv"), row.names = FALSE)The method vector describes which variables are updated; the predictor matrix specifies their conditional predictors. A value of one requests a predictor, and zero excludes it. This run records 1147 logged events. Of these, 753 occur while imputing log height with log weight listed as the predictor affected, and 394 occur in the reverse direction. MICE’s internal predictor screen uses a default maxcor = 0.99 threshold. The observed pairwise correlation between log height and log weight is 0.99003, based on 727 paired observations. The relationship is just above the screening threshold, so MICE repeatedly removes the other size variable from the corresponding conditional model. This is not an execution failure, but it means the intended reciprocal height–weight information is not consistently retained. Treat the pooled estimate as provisional until a pre-specified alternative imputation model is examined. Do not disable collinearity safeguards blindly; compare the event log, conditional plausibility, chain behaviour and pooled estimates.
The supplied execution used mice version 3.19.0. The MICE documentation records a separate predictive-mean-matching tie-handling correction in version 3.19.12; versions 3.11.8 through 3.19.11 can reuse a small donor set when predicted values are tied, potentially inflating between-imputation variance and widening confidence intervals. This execution falls within the documented affected range; rerun with mice 3.19.12 or later before treating the pooled estimate as final. This issue is separate from the predictor-screening events above. Updating the package does not automatically change the 0.99 predictor-screening threshold, so both issues require attention.
5. Examine the imputations
Chain stability
Trace plots compare the mean and standard deviation of imputed cells over iterations. Look for chains that fluctuate around a stable range rather than showing drift or persistent separation. In this run, the weight traces adjust most noticeably at the first iteration and then fluctuate within overlapping bands; the height traces are comparatively stable. With very few missing weights, the standard-deviation traces can be noisy. Visual stability alone does not establish convergence, and it does not override the repeated predictor removals recorded in the event log.
# Means and standard deviations of imputed cells, not whole completed columns.
trace_frame <- function(a, statistic) {
selected <- a[c("log_wgt", "log_hgt"), , , drop = FALSE]
d <- expand.grid(variable = c("log_wgt", "log_hgt"),
iteration = seq_len(dim(selected)[2]), chain = seq_len(dim(selected)[3]))
d$value <- as.vector(selected)
d$statistic <- statistic
d
}
traces <- rbind(trace_frame(imp$chainMean, "Mean"),
trace_frame(sqrt(imp$chainVar), "SD"))
stopifnot(all(is.finite(traces$value)))
p_trace <- ggplot(traces, aes(iteration, value, group = chain)) +
geom_line(alpha = 0.22, colour = "#287C8E", linewidth = 0.4) +
facet_wrap(vars(variable, statistic), scales = "free_y", ncol = 2) +
labs(x = "Iteration", y = "Imputed-cell statistic") + theme_minimal(base_size = 12)
print(p_trace)
ggsave(file.path(output_dir, "03_chain_traces.png"), p_trace, width = 8, height = 5.5, dpi = 300)
write.csv(traces, file.path(output_dir, "07_chain_traces.csv"), row.names = FALSE)
Conditional plausibility and observed-value preservation
The next checks confirm that observed values have not been overwritten and that predictive mean matching selects observed donor values. Comparing imputed measurements with observed measurements at the same ages is more informative than relying on a marginal density alone. All 40 draws for each missing measurement appear in the display; these are repeated plausible values, not additional participants. The imputed region counts are likewise counts of draws, not people.
completed <- complete(imp, action = "all")
for (d in completed) {
stopifnot(nrow(d) == nrow(core), !anyNA(d))
for (v in names(core)) {
observed <- !is.na(core[[v]])
stopifnot(isTRUE(all.equal(d[[v]][observed], core[[v]][observed], check.attributes = FALSE)))
}
for (v in c("log_hgt", "log_wgt")) {
stopifnot(all(d[[v]][is.na(core[[v]])] %in% core[[v]][!is.na(core[[v]])]))
}
}
# Show repeated donor draws at their actual ages; dots are not independent boys.
observed_plot <- rbind(
data.frame(age = boys$age, value = boys$hgt, variable = "Height (cm)"),
data.frame(age = boys$age, value = boys$wgt, variable = "Weight (kg)"))
observed_plot <- observed_plot[!is.na(observed_plot$value), ]
imputed_plot <- do.call(rbind, lapply(completed, function(d) {
h <- is.na(boys$hgt); w <- is.na(boys$wgt)
rbind(data.frame(age = boys$age[h], value = exp(d$log_hgt[h]), variable = "Height (cm)"),
data.frame(age = boys$age[w], value = exp(d$log_wgt[w]), variable = "Weight (kg)"))
}))
p_donors <- ggplot(observed_plot, aes(age, value)) +
geom_point(colour = "grey65", alpha = 0.55, size = 1) +
geom_point(data = imputed_plot, colour = "#C17939", alpha = 0.20, size = 1.4) +
facet_wrap(~variable, scales = "free_y") +
labs(x = "Age (years)", y = "Measurement", subtitle = "Grey: observed; orange: repeated imputed draws") +
theme_minimal(base_size = 12)
print(p_donors)
ggsave(file.path(output_dir, "04_imputation_plausibility.png"), p_donors, width = 8, height = 4.8, dpi = 300)
region_draws <- table(factor(unlist(lapply(completed, function(d) as.character(d$reg[is.na(core$reg)]))),
levels = region_levels))
print(region_draws)
north east west south city
6 20 41 35 18
write.csv(as.data.frame(region_draws), file.path(output_dir, "08_region_draws.csv"), row.names = FALSE)
A donor value can fall inside the overall observed range yet be implausible for a given age. Conditional inspection therefore matters. The charts should be read alongside the study context, the event log and the missingness patterns; they cannot reveal the true unobserved measurements.
6. Analyze each dataset and pool the estimates
Multiple imputation does not average completed datasets before regression. Fit the same model separately to each completed dataset, yielding estimates \(Q_j\) and estimated within-analysis variances \(U_j\). With \(m\) imputations, Rubin’s rules combine them as
\[ \bar Q=\frac{1}{m}\sum_{j=1}^{m}Q_j,\qquad \bar U=\frac{1}{m}\sum_{j=1}^{m}U_j \]
\[ B=\frac{1}{m-1}\sum_{j=1}^{m}(Q_j-\bar Q)^2,\qquad T=\bar U+\left(1+\frac{1}{m}\right)B \]
The first variance component captures sampling uncertainty inside completed datasets; the second captures variation across imputations, including a finite-imputation correction. The pooled standard error is \(\sqrt{T}\). The pool() function supplies a small-sample degrees-of-freedom adjustment and the fraction of missing information. The approximate Monte Carlo error of the pooled point estimate is \(\sqrt{B/m}\); comparing this to the pooled standard error is a useful stability check, not a complete assessment of interval accuracy.
fits <- lapply(completed, function(d) lm(model_formula, data = d))
stopifnot(all(vapply(fits, function(f) f$rank == length(coef(f)), logical(1))))
pooled <- pool(as.mira(fits))$pooled
# Compute interval endpoints directly to avoid version-specific summary column names.
mi <- data.frame(term = as.character(pooled$term), estimate = pooled$estimate,
se = sqrt(pooled$t), df = pooled$df, ubar = pooled$ubar,
between = pooled$b, total = pooled$t, fmi = pooled$fmi,
mcse = sqrt(pooled$b / imp$m))
mi$lower <- mi$estimate - qt(0.975, mi$df) * mi$se
mi$upper <- mi$estimate + qt(0.975, mi$df) * mi$se
mi$mcse_ratio <- mi$mcse / mi$se
stopifnot(all(is.finite(as.matrix(mi[, -1]))),
isTRUE(all.equal(mi$total, mi$ubar + (1 + 1 / imp$m) * mi$between)))
print(mi, row.names = FALSE) term estimate se df ubar between
(Intercept) -8.74461558 0.33800740 709.4508 0.1113929149 2.786429e-03
log_hgt 2.56644046 0.08259974 709.3879 0.0066518429 1.667062e-04
age1 -0.49593072 0.06664140 703.2237 0.0043104735 1.274177e-04
age2 -0.29417434 0.07764803 712.4654 0.0058920619 1.338099e-04
age3 -0.63687541 0.15604959 707.9399 0.0237159923 6.199836e-04
age4 -0.06007635 0.06063389 699.4625 0.0035590397 1.145651e-04
regeast -0.01838531 0.01532129 718.5520 0.0002305372 4.102122e-06
regwest -0.01771235 0.01454559 700.5845 0.0002049741 6.438945e-06
regsouth -0.01911579 0.01495291 716.8860 0.0002192788 4.205632e-06
regcity 0.01589399 0.01809129 723.1642 0.0003227415 4.442231e-06
total fmi mcse lower upper mcse_ratio
0.1142490051 0.02773585 0.0083463008 -9.40823005 -8.08100111 0.02469266
0.0068227167 0.02778198 0.0020414834 2.40427126 2.72860966 0.02471537
0.0044410766 0.03215667 0.0017847807 -0.62677066 -0.36509078 0.02678186
0.0060292171 0.02548022 0.0018290021 -0.44662066 -0.14172802 0.02355503
0.0243514754 0.02883605 0.0039369517 -0.94325078 -0.33050003 0.02522885
0.0036764689 0.03469694 0.0016923730 -0.17912259 0.05896989 0.02791134
0.0002347418 0.02063407 0.0003202391 -0.04846515 0.01169453 0.02090158
0.0002115741 0.03394828 0.0004012152 -0.04627051 0.01084581 0.02758330
0.0002235896 0.02200450 0.0003242542 -0.04847252 0.01024094 0.02168502
0.0003272948 0.01662777 0.0003332503 -0.01962373 0.05141171 0.01842048
write.csv(mi, file.path(output_dir, "09_pooled_estimates.csv"), row.names = FALSE)
cc_table <- data.frame(term = names(coef(fit_cc)), estimate = unname(coef(fit_cc)),
se = unname(coef(summary(fit_cc))[, "Std. Error"]),
lower = unname(confint(fit_cc)[, 1]), upper = unname(confint(fit_cc)[, 2]))
comparison <- rbind(transform(cc_table, analysis = "Complete cases"),
transform(mi[, names(cc_table)], analysis = "Multiple imputation"))
write.csv(comparison, file.path(output_dir, "10_model_comparison.csv"), row.names = FALSE)
height <- subset(comparison, term == "log_hgt")
print(height, row.names = FALSE) term estimate se lower upper analysis
log_hgt 2.595054 0.08227710 2.433520 2.756588 Complete cases
log_hgt 2.566440 0.08259974 2.404271 2.728610 Multiple imputation
p_compare <- ggplot(height, aes(analysis, estimate, colour = analysis)) +
geom_pointrange(aes(ymin = lower, ymax = upper), linewidth = 0.6) + coord_flip() +
scale_colour_manual(values = c("Complete cases" = "#287C8E", "Multiple imputation" = "#C17939")) +
labs(x = NULL, y = "Height elasticity (95% CI)") +
theme_minimal(base_size = 13) + theme(legend.position = "none")
print(p_compare)
ggsave(file.path(output_dir, "05_height_elasticity.png"), p_compare, width = 7, height = 3.8, dpi = 300)
| Analysis | Estimate | SE | 95% lower | 95% upper | |
|---|---|---|---|---|---|
| 2 | Complete cases | 2.5951 | 0.0823 | 2.4335 | 2.7566 |
| 12 | Multiple imputation | 2.5664 | 0.0826 | 2.4043 | 2.7286 |
The multiply imputed height elasticity is 2.566 (standard error 0.083; 95% confidence interval 2.404 to 2.729), compared with 2.595 in the complete-case model (95% confidence interval 2.434 to 2.757). The point estimates differ by 0.029 and the intervals overlap substantially. No formal test of the difference was performed. Holding the modeled age and region terms fixed, a 1% difference in height corresponds approximately to a 2.57% difference in the modeled geometric mean of weight. This is an association within the model, not a clinical recommendation or a causal effect.
For this coefficient, the fraction of missing information is 0.0278 and the approximate Monte Carlo error relative to the pooled standard error is 0.025. A small relative Monte Carlo error supports the stability of the pooled point estimate under the chosen run, but does not test MAR or repair the predictor-screening issue described above. Small differences between methods are possible because the four-variable model already has many complete records. Neither a narrower interval nor a larger sample alone establishes that an estimate is less biased.
7. Check regression assumptions separately
Stable imputation chains do not guarantee a suitable regression model. Standardized residuals against fitted log weight help identify curvature, changing variance and extreme residuals. The display uses the complete-case fit and the first completed dataset for illustration; the summary records residual standard deviations and maximum Cook’s distances across all completed fits. These summaries are screening diagnostics, not proof that every fit satisfies homoscedasticity, normality or independence.
residual_summary <- data.frame(imputation = seq_along(fits),
residual_sd = vapply(fits, sigma, numeric(1)),
max_cooks_d = vapply(fits, function(f) max(cooks.distance(f)), numeric(1)))
print(summary(residual_summary[, -1])) residual_sd max_cooks_d
Min. :0.1089 Min. :0.02642
1st Qu.:0.1098 1st Qu.:0.02724
Median :0.1102 Median :0.02759
Mean :0.1102 Mean :0.02757
3rd Qu.:0.1106 3rd Qu.:0.02789
Max. :0.1115 Max. :0.02891
write.csv(residual_summary, file.path(output_dir, "11_residual_summary.csv"), row.names = FALSE)
residual_plot <- rbind(data.frame(fitted = fitted(fit_cc), residual = rstandard(fit_cc), model = "Complete cases"),
data.frame(fitted = fitted(fits[[1]]), residual = rstandard(fits[[1]]), model = "Imputation 1"))
p_residual <- ggplot(residual_plot, aes(fitted, residual)) +
geom_hline(yintercept = 0, linetype = 2, colour = "grey45") +
geom_point(alpha = 0.4, size = 1, colour = "#287C8E") +
geom_smooth(method = "loess", formula = y ~ x, se = FALSE, colour = "#C17939") +
facet_wrap(~model) + labs(x = "Fitted log weight", y = "Standardized residual") + theme_minimal(base_size = 12)
print(p_residual)
ggsave(file.path(output_dir, "06_residual_diagnostics.png"), p_residual, width = 8, height = 4.8, dpi = 300)
Across the forty completed fits, residual standard deviations range from 0.109 to 0.112; maximum Cook’s distances range from 0.026 to 0.029. The residual smooths remain close to zero overall, although the spread is wider at the high end of fitted log weight and a few standardized residuals are large. These are screening results, not proof of homoscedasticity or a reason to delete observations automatically. A study with clustered plots, repeated measurements or survey weights would require appropriate analysis and imputation models for that design. Here no such design variables are supplied.
8. Sensitivity to departures from MAR
The observed data cannot identify the distribution of genuinely unobserved heights. An illustrative pattern-mixture sensitivity exercise shifts only the imputed heights by minus or plus 5%, retaining the observed heights and refitting every model. The zero-shift scenario must reproduce the primary pooled estimate. These percentages are hypothetical departures, not values estimated from the growth study, and they do not account for all possible MNAR mechanisms. Shifts are applied after imputation and other variables are held fixed; this is a deliberately limited scenario check, not a new fully coherent joint imputation model.
# These scenario shifts are not estimated from the survey.
shift_fit <- function(multiplier) {
shifted <- lapply(completed, function(d) {
d$log_hgt[is.na(core$log_hgt)] <- d$log_hgt[is.na(core$log_hgt)] + log(multiplier)
lm(model_formula, data = d)
})
p <- subset(pool(as.mira(shifted))$pooled, term == "log_hgt")
data.frame(height_multiplier = multiplier, estimate = p$estimate,
lower = p$estimate - qt(0.975, p$df) * sqrt(p$t),
upper = p$estimate + qt(0.975, p$df) * sqrt(p$t))
}
sensitivity <- do.call(rbind, lapply(c(0.95, 1, 1.05), shift_fit))
stopifnot(isTRUE(all.equal(sensitivity$estimate[2], mi$estimate[mi$term == "log_hgt"])))
print(sensitivity, row.names = FALSE) height_multiplier estimate lower upper
0.95 2.506635 2.336616 2.676653
1.00 2.566440 2.404271 2.728610
1.05 2.499203 2.332300 2.666106
write.csv(sensitivity, file.path(output_dir, "12_height_shift_sensitivity.csv"), row.names = FALSE)
p_sensitivity <- ggplot(sensitivity, aes(100 * (height_multiplier - 1), estimate)) +
geom_line(colour = "#287C8E") + geom_pointrange(aes(ymin = lower, ymax = upper), colour = "#287C8E") +
scale_x_continuous(breaks = c(-5, 0, 5)) +
labs(x = "Change to imputed heights only (%)", y = "Height elasticity (95% CI)") + theme_minimal(base_size = 13)
print(p_sensitivity)
ggsave(file.path(output_dir, "07_height_shift_sensitivity.png"), p_sensitivity, width = 7, height = 4.5, dpi = 300)
The zero-shift estimate is 2.566. The minus-five-percent and plus-five-percent scenarios give 2.507 and 2.499, respectively; their confidence intervals overlap the baseline interval substantially. Both shifted point estimates are slightly lower than the baseline in this dataset, illustrating that the effect depends on which records are missing and how they influence the fitted relationship. The spread shows sensitivity to this specific perturbation, not a confidence interval for the missingness mechanism. A complete substantive analysis could examine more realistic, age-dependent shifts and additional auxiliary measurements, including head circumference, if their availability and relationships justify inclusion.
9. What researchers should take away
Multiple imputation is most useful when the imputation model reflects the scientific question, the relevant predictors of missingness and the structure of the original study. In agricultural experiments, for example, imputations may need to respect blocks, treatments and repeated plot measurements; missing entire plots after crop failure may require explicit sensitivity analysis rather than a routine MAR assumption. In survey research, the sampling weights and design variables can be essential. Missingness that represents nonapplicability must be distinguished from missing eligible responses.
The central lesson is to define the analysis first, use a defensible imputation model, inspect the completed data and combine estimates with appropriate uncertainty. This run also demonstrates why a successful computation is not enough: the event log shows that MICE repeatedly screens out the other log-size variable from the conditional imputation model because the observed correlation is just above its default threshold. The pooled estimate is therefore provisional until a justified alternative specification is compared. The historical growth dataset cannot establish current national growth norms, causal effects or the true missing values. The confidence intervals are model-based; no survey weights or clustering information is provided.
References
- Fredriks, A. M., et al. (2000). Continuing positive secular growth change in the Netherlands 1955–1997. Pediatric Research, 47, 316–323.
- van Buuren, S., & Groothuis-Oudshoorn, K. (2011). mice: Multivariate imputation by chained equations in R. Journal of Statistical Software, 45(3), 1–67. https://doi.org/10.18637/jss.v045.i03.
- van Buuren, S. (2018). Flexible Imputation of Missing Data (2nd ed.). Chapman & Hall/CRC. Online book.
- MICE documentation: boys data, chained equations, predictive mean matching, pooling, and logged-event information.
- MICE internal predictor-screening source: remove.lindep().
Comments
Post a Comment