Introduction

In the article on multiple imputation with the mice package, predictive mean matching (PMM) was used as the default method for the continuous variables. This article explains how PMM works step by step, with an example on a specific patient from the same simulated cohort as the previous article.

The algorithm

PMM was proposed by Rubin (1986) and developed by Little (1988) as a way of combining the information in a regression model with the safety of placing in the gaps only values that have actually been observed. For a variable with missing values, here HbA1c, and a set of predictor variables, the algorithm carries out the following steps.

  1. A linear regression is fitted with the variable to be imputed, here HbA1c, as the outcome and the predictor variables, age, sex, years since diagnosis, educational level, BMI and blood pressure, as explanatory variables. The model is estimated only in the patients with an observed HbA1c, giving the coefficients β̂.
  2. A new set of coefficients β* is drawn at random from the posterior distribution of β̂, that is, from a normal distribution centred on β̂ with their standard errors as its spread. This step captures the uncertainty about the coefficients themselves, which are estimates from a sample and not the true ones, and it is essential to every multiple imputation method. Without it all the datasets would use the same coefficients, the same donors would be chosen every time, and the variance between the datasets would underestimate the real uncertainty.
  3. Predicted HbA1c values are computed for all patients, with β̂ for those with an observed HbA1c and with β* for those without.
  4. For each patient with a missing HbA1c, the patients with an observed HbA1c whose predicted value is closest to theirs are identified. Take a patient with a gap and a predicted value of 7.8 based on β*. Five patients with an observed HbA1c have actual values of 6.9, 8.1, 7.4, 8.8 and 9.3, and in step 3 their predicted values were computed as 7.1, 7.6, 7.9, 8.4 and 9.0 based on β̂. If the number of donors is set to three, the patients with predicted values 7.6, 7.9 and 8.4, the closest to 7.8, are chosen.
  5. One of the three donors is picked at random and their actual HbA1c is placed in the gap. In the example the algorithm chooses at random between 8.1, 7.4 and 8.8, the actual values of the patients with predicted values 7.6, 7.9 and 8.4, and places, say, 7.4. In mice the default number of donors is five.
  6. In multiple imputation steps 2 to 5 are repeated m times. Each repetition draws new β*, hence slightly different predicted values, possibly different donors, and certainly a new random choice among them, so it produces a new completed dataset.

Application to simulated data

The same cohort of 800 patients with type 2 diabetes is used, in which HbA1c is missing under a MAR mechanism that depends on age and years since diagnosis.

rSimulating the cohort and introducing the missing values31 lines
library(tidyverse); library(naniar); library(ggmice); library(mice)
theme_set(theme_minimal(base_family = "sans", base_size = 12) +
          theme(panel.grid.minor = element_blank(), plot.title.position = "plot"))
navy <- "#1F2A44"; pink <- "#D5487F"; grey <- "#8A93A6"
set.seed(2026)
n <- 800
d <- tibble(
  age       = round(rnorm(n, 64, 10)),
  sex       = factor(sample(c("F", "M"), n, replace = TRUE)),
  dm_years  = round(rexp(n, 1 / 8)),
  education = factor(sample(c("primary", "secondary", "tertiary"), n, replace = TRUE,
                            prob = c(0.35, 0.45, 0.20)),
                     levels = c("primary", "secondary", "tertiary")),
  smoking   = factor(rbinom(n, 1, plogis(-1.2 - 0.5 * (education == "tertiary"))),
                     labels = c("no", "yes")),
  bmi       = round(rnorm(n, 30, 5), 1),
  sbp       = round(128 + 0.5 * (age - 64) + 0.7 * (bmi - 30) + rnorm(n, 0, 13)),
  ldl       = round(rnorm(n, 105, 30)),
  egfr      = round(pmax(15, 95 - 0.9 * (age - 64) - 1.2 * dm_years + rnorm(n, 0, 14))),
  hba1c     = round(6.4 + 0.07 * dm_years + 0.02 * (age - 64) + 0.03 * (bmi - 30) + rnorm(n, 0, 1.0), 1)
)

d_obs <- d |>
  mutate(
    ldl     = if_else(runif(n) < 0.08, NA, ldl),                                      # MCAR
    hba1c   = if_else(runif(n) < plogis(-2.4 + 0.08 * (age - 64) + 0.12 * dm_years),  # MAR: ηλικία, έτη από διάγνωση
                      NA, hba1c),
    smoking = if_else(runif(n) < plogis(-2.8 + 1.3 * (education == "primary")),       # MAR: μόρφωση
                      NA, smoking),
    egfr    = if_else(runif(n) < plogis(-2.0 - 0.06 * (egfr - 75)), NA, egfr)         # MNAR: η ίδια η τιμή
  )

The matching for one patient

To make the mechanism easier to follow, one patient with a missing HbA1c is chosen and steps 1, 3 and 4 are reproduced by hand, with the same predictor variables that mice uses. Step 2 is left out for simplicity, so the patient's predicted value is computed with β̂ instead of β*. The model is fitted to the patients with an observed HbA1c, predicted values are computed for everyone, and the patient's five donors are identified.

rThe model, the predictions and the five donors11 lines
obs <- d_obs |> filter(!is.na(hba1c))
fit <- lm(hba1c ~ age + sex + dm_years + education + bmi + sbp, data = obs)
i <- which(is.na(d_obs$hba1c))[1]
target <- d_obs[i, ]
target$pred <- predict(fit, newdata = target)
obs$pred <- predict(fit, newdata = obs)
donors <- obs |>
  mutate(dist = abs(pred - target$pred)) |>
  slice_min(dist, n = 5) |>
  select(age, dm_years, bmi, pred, hba1c)
target |> select(age, dm_years, bmi, pred)
Output
# A tibble: 1 × 4
    age dm_years   bmi  pred
  <dbl>    <dbl> <dbl> <dbl>
1    54       10  26.1  6.82
rThe donors
donors
Output
# A tibble: 5 × 5
    age dm_years   bmi  pred hba1c
  <dbl>    <dbl> <dbl> <dbl> <dbl>
1    65        4  29    6.82   7.4
2    45       11  28.5  6.81   5.5
3    65        5  31.1  6.81   5.8
4    88        2  28.3  6.82   6.9
5    57        9  29.9  6.81   7.4

The patient's predicted HbA1c equals the pred value in the first table. The five donors in the second table have predicted values almost identical to theirs, and these five actual values are the candidates for the gap. The plot shows the procedure across the whole sample.

rPlot of the matching9 lines
ggplot(obs, aes(x = pred, y = hba1c)) +
  geom_point(colour = navy, alpha = 0.25, size = 1.4) +
  geom_abline(slope = 1, intercept = 0, colour = grey, linetype = 2) +
  geom_vline(xintercept = target$pred, colour = pink, linewidth = 0.6) +
  geom_point(data = donors, colour = pink, size = 3.5, shape = 21, stroke = 1.2, fill = NA) +
  geom_point(data = donors, colour = pink, size = 1.4) +
  annotate("text", x = target$pred, y = max(obs$hba1c), label = "ασθενής με κενό",
           colour = pink, hjust = -0.1, size = 3.4) +
  labs(x = "προβλεπόμενη HbA1c (%)", y = "παρατηρούμενη HbA1c (%)")
The mechanism of the matching. Each grey dot is a patient with a measured HbA1c, placed by the value the model predicts for them (horizontally) and the value actually measured (vertically). The dashed diagonal is the line on which the actual value equals the predicted one. The pink vertical line is the predicted value of the patient with the gap. Imputation by simple regression would give them the point where that line crosses the diagonal. PMM instead finds the five measured patients with the closest predicted value, the pink circles, and places in the gap the actual HbA1c of one of them, which can lie quite far from the prediction.
Figure 1The mechanism of the matching. Each grey dot is a patient with a measured HbA1c, placed by the value the model predicts for them (horizontally) and the value actually measured (vertically). The dashed diagonal is the line on which the actual value equals the predicted one. The pink vertical line is the predicted value of the patient with the gap. Imputation by simple regression would give them the point where that line crosses the diagonal. PMM instead finds the five measured patients with the closest predicted value, the pink circles, and places in the gap the actual HbA1c of one of them, which can lie quite far from the prediction.

The values multiple imputation produces

With mice the procedure runs automatically for all patients and for m datasets. For the same patient, the 50 values they received are extracted.

rMultiple imputation with PMM
imp <- mice(d_obs, m = 50, maxit = 10, method = "pmm", seed = 2026, printFlag = FALSE)
rThe patient's 50 values and the distribution of similar patients10 lines
imputed_i <- tibble(value = unlist(imp$imp$hba1c[as.character(i), ]))
neighbours <- obs |> mutate(dist = abs(pred - target$pred)) |> slice_min(dist, n = 60)
ggplot() +
  geom_density(data = neighbours, aes(x = hba1c, y = after_stat(density)),
               fill = alpha(navy, 0.12), colour = navy, linewidth = 0.5, adjust = 1.4) +
  geom_dotplot(data = imputed_i, aes(x = value), binwidth = 0.1,
               fill = pink, colour = NA, dotsize = 0.8, stackratio = 1.1) +
  geom_vline(xintercept = target$pred, colour = navy, linetype = 2) +
  scale_y_continuous(NULL, breaks = NULL) +
  labs(x = "HbA1c (%)")
The 50 imputed HbA1c values of the same patient, one per completed dataset, and their distribution. The values are all observed values of other patients.
Figure 2The 50 imputed HbA1c values of the same patient, one per completed dataset, and their distribution. The values are all observed values of other patients.

The 50 values are spread around the patient's predicted value, the dashed line, with a spread that matches the spread among similar patients. It is this spread that passes, through Rubin's rules, into the standard error of the final estimate.

Comparison with stochastic regression imputation

The closest alternative to PMM is stochastic regression imputation, in mice the norm method, which carries out the same steps 1 to 3 but in step 5 places the predicted value plus a random residual from a normal distribution. The two methods give similar results when the data are roughly normal and homoscedastic. They differ in two situations often met in health data.

Bounded and skewed variables

Many clinical variables have a natural bound, HbA1c does not fall below 4%, eGFR and LDL are not negative, and their distribution is often skewed. norm adds normal noise around the prediction and can produce values outside the possible range. To show the difference, the duration in years since diagnosis is used, a variable with an exponential distribution starting at zero, into which missing values are introduced.

rImputing years since diagnosis with norm and pmm
d_dm <- d_obs |> mutate(dm_years = if_else(runif(n) < 0.25, NA, dm_years))
imp_norm <- mice(d_dm, m = 1, method = "norm", seed = 1, printFlag = FALSE)
imp_pmm  <- mice(d_dm, m = 1, method = "pmm",  seed = 1, printFlag = FALSE)
tibble(method = c("norm", "pmm"),
       n_negative = c(sum(complete(imp_norm)$dm_years < 0), sum(complete(imp_pmm)$dm_years < 0)),
       min_imputed = c(min(imp_norm$imp$dm_years), min(imp_pmm$imp$dm_years)))
Output
# A tibble: 2 × 3
  method n_negative min_imputed
  <chr>       <int>       <dbl>
1 norm           NA          NA
2 pmm             0           0
rComparing the distributions11 lines
bind_rows(
  tibble(value = d$dm_years[!is.na(d_dm$dm_years)], source = "παρατηρούμενες"),
  tibble(value = unlist(imp_norm$imp$dm_years), source = "norm"),
  tibble(value = unlist(imp_pmm$imp$dm_years),  source = "pmm")) |>
  mutate(source = factor(source, levels = c("παρατηρούμενες", "norm", "pmm"))) |>
  ggplot(aes(x = value, fill = source)) +
  geom_density(alpha = 0.55, colour = NA, adjust = 1.3) +
  geom_vline(xintercept = 0, colour = grey, linetype = 2) +
  scale_fill_manual(values = c(navy, "#8A93A6", pink)) +
  labs(x = "έτη από τη διάγνωση", y = "πυκνότητα", fill = NULL) +
  theme(legend.position = "top")
Distribution of years since diagnosis, observed values and values imputed with the two methods. Stochastic regression produces negative years and an almost normal curve, while PMM keeps the shape of the exponential distribution.
Figure 3Distribution of years since diagnosis, observed values and values imputed with the two methods. Stochastic regression produces negative years and an almost normal curve, while PMM keeps the shape of the exponential distribution.

norm places negative years since diagnosis in several patients and smooths the distribution into a shape that does not resemble the data. PMM, borrowing only observed values, stays within the range and reproduces the skewness. In practice the negative values from norm can be truncated afterwards, but truncation disturbs the distribution and the standard errors in a way that is not controlled.

Heteroscedasticity

The second situation is when the spread of the incomplete variable is not constant but changes with the predictor variables. norm assumes a constant residual variance and adds noise of the same size everywhere, so it overestimates the spread where it is small and underestimates it where it is large. PMM, choosing donors from the same region of predicted values, automatically inherits the local spread. To show this graphically, a variable is constructed whose spread increases with age, as happens with many biomarkers, and 30% of its values are removed.

rA biomarker whose spread increases with age
set.seed(2026)
d_het <- d |>
  mutate(marker = 50 + 0.8 * (age - 64) + rnorm(n, 0, 2 + 0.4 * pmax(age - 40, 0)),
         marker_obs = if_else(runif(n) < 0.30, NA, marker)) |>
  select(age, sex, bmi, marker_obs)
imp_het_norm <- mice(d_het, m = 1, method = "norm", seed = 1, printFlag = FALSE)
imp_het_pmm  <- mice(d_het, m = 1, method = "pmm",  seed = 1, printFlag = FALSE)
rObserved and imputed values per method13 lines
bind_rows(
  complete(imp_het_norm) |> mutate(method = "Στοχαστική παλινδρόμηση (norm)"),
  complete(imp_het_pmm)  |> mutate(method = "PMM")) |>
  mutate(imputed = rep(is.na(d_het$marker_obs), 2),
         method = factor(method, levels = c("Στοχαστική παλινδρόμηση (norm)", "PMM"))) |>
  arrange(imputed) |>
  ggplot(aes(x = age, y = marker_obs, colour = imputed)) +
  geom_point(alpha = 0.55, size = 1.5) +
  facet_wrap(~ method) +
  scale_colour_manual(values = c(`FALSE` = navy, `TRUE` = pink),
                      labels = c("παρατηρούμενη", "αναπληρωμένη")) +
  labs(x = "ηλικία (έτη)", y = "βιοδείκτης", colour = NULL) +
  theme(legend.position = "top")
A biomarker whose spread increases with age. Observed values in navy and imputed values in pink, for the two methods. Stochastic regression scatters the imputed values evenly, while PMM follows the funnel shape of the data.
Figure 4A biomarker whose spread increases with age. Observed values in navy and imputed values in pink, for the two methods. Stochastic regression scatters the imputed values evenly, while PMM follows the funnel shape of the data.

In the left panel the imputed values form a band of constant width around the regression line, much wider than the data at younger ages and narrower at older ones. In the right panel the imputed values are hard to tell apart from the observed ones, because each gap was filled from a patient with a similar predicted value, and therefore a similar local spread.

When PMM is not the right choice

PMM assumes that for every patient with a gap there are enough donors with nearby predicted values. In small samples, or when the patient with the gap lies at the extremes of the distribution of the predictors, the closest donors may be far away, and the value borrowed may not suit them. In that case norm, which generates the value from the model and can extrapolate beyond the observed range, may be preferable, provided the normal linear model is plausible even where there are no observations. In addition, PMM with the same five donors in every dataset can underestimate the variance between the datasets when the sample is small, so the number of donors, the donors argument, is worth examining. For categorical variables, finally, mice uses logistic and multinomial models, not PMM. In samples of the size met in clinical epidemiology and for continuous variables, PMM remains the safest default (Morris et al. 2014, van Buuren 2018).

References

  1. Little RJA (1988). Missing-data adjustments in large surveys. Journal of Business & Economic Statistics, 6(3), 287–296.
  2. Morris TP, White IR, Royston P (2014). Tuning multiple imputation by predictive mean matching and local residual draws. BMC Medical Research Methodology, 14, 75.
  3. Rubin DB (1986). Statistical matching using file concatenation with adjusted weights and multiple imputations. Journal of Business & Economic Statistics, 4(1), 87–94.
  4. van Buuren S (2018). Flexible Imputation of Missing Data, 2nd ed. Chapman & Hall/CRC.
  5. van Buuren S, Groothuis-Oudshoorn K (2011). mice, multivariate imputation by chained equations in R. Journal of Statistical Software, 45(3), 1–67.
  6. Vink G, Frank LE, Pannekoek J, van Buuren S (2014). Predictive mean matching imputation of semicontinuous variables. Statistica Neerlandica, 68(1), 61–90.