Introduction

A missing value is the absence of a recorded value in one or more variables of an individual, a phenomenon that is an almost unavoidable feature of health research. From a statistical point of view, the presence of missing values reduces the power of a study and the validity of its conclusions. In recent years the spread of electronic health records, patient registries and wearable devices has introduced datasets with rates of missingness far above those met in clinical trials.

In health research, missing values usually arise from a participant's non-response to individual questions (item nonresponse), from withdrawal from the study, or from clinical decisions not to perform a test. These causes are rarely independent of the individual's own characteristics, so handling missing values requires an understanding of the mechanism that produces them.

Missingness mechanisms

Let Y be the variable with missing values, X the fully recorded variables, and R the indicator that equals zero when Y is missing. Rubin's (1976) classification distinguishes three mechanisms according to what the probability of missingness P(R = 0 | X, Y) depends on, as shown in Figure 1.

When

P(R = 0 | X, Y) = P(R = 0),

missingness is completely at random (MCAR), the complete cases form a random subsample and analysing them is unbiased, the only cost being reduced precision, a scenario that is rare in health data.

When

P(R = 0 | X, Y) = P(R = 0 | X),

missingness is at random (MAR), that is, it depends on X but, given X, not on Y, so the distribution of Y given X is estimated from those who have a value.

When

P(R = 0 | X, Y) ≠ P(R = 0 | X),

missingness is not at random (MNAR), the probability of missingness depends on the very value that is missing, and whatever is estimated from the observed data does not describe the missing values.

The three missingness mechanisms in the same sample. Pink marks the true position of the values that are missing.
Figure 1The three missingness mechanisms in the same sample. Pink marks the true position of the values that are missing.

The three panels of Figure 1 show the same sample of two positively correlated variables X and Y, and differ only in which values of Y were removed. In the left panel, under MCAR, the pink and the dark dots share the same distribution, since the removal was made independently of the values of the variables. In the middle panel, under MAR, the missing values cluster towards high values of X, while their upward shift is weak and due solely to the correlation between the two variables, not to a direct effect of Y on the probability of missingness. This is the essence of MAR: Y does not determine whether its own value will be missing, so the bias of simple deletion can be dealt with by a suitable imputation model that makes use of X. In the right panel, under MNAR, the picture is reversed, with the missing values strongly shifted towards high values of Y and only slightly towards X, because the probability of missingness now depends on the very value that is missing, and the usual imputation methods cannot fully correct the bias that results.

In practice it is usually impossible to tell the MAR mechanism from MNAR, since the distribution of the missing values remains unknown and the few available tests hold only under parametric assumptions (Lee et al. 2023). For this reason most analyses proceed under the MAR assumption, a fairly strong assumption adopted mainly for lack of easily applicable alternatives, even though in many health settings the MNAR mechanism is equally or more plausible (Haneuse et al. 2021).

Exploring missing values in R

The example below uses simulated data from a cohort of 800 patients with type 2 diabetes mellitus in primary care, with recorded age, sex, years since diagnosis, educational level (primary, secondary, tertiary education), smoking, body mass index, systolic blood pressure, LDL cholesterol, estimated glomerular filtration rate (eGFR) and HbA1c. Because the data are simulated, the missingness mechanisms are known, so it can be seen what each exploratory tool reveals and what it does not. Missing values are introduced through four different mechanisms, as happens in real data. LDL is missing completely at random at a rate of 8%, because of technical problems in the laboratory. HbA1c is missing under a MAR mechanism, more often in older patients and in those with more years since diagnosis, who are followed in hospital clinics so that the measurement is not recorded in the primary-care file. Smoking is also missing under a MAR mechanism, more often in patients of lower educational level. eGFR, finally, is missing under an MNAR mechanism, as patients with lower kidney function are referred to a nephrologist and the measurement is made outside the system, so the probability of missingness depends on the very value that is missing. The packages used are naniar for the visualisation and the tests, ggmice for the missingness pattern and ggplot2 for the remaining plots.

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: η ίδια η τιμή
  )

Extent of missingness

The first question is how many values are missing and where. The function miss_var_summary() gives the number and the percentage per variable, while pct_complete_case() gives the percentage of observations with complete data, which is as a rule much smaller than the maximum per-variable percentage suggests, because missing values rarely coincide in the same individuals. Here no variable exceeds 25%, and yet about half of the patients would be excluded from a complete-case analysis.

rMissing values per variable
miss_var_summary(d_obs) |> filter(n_miss > 0)
Output
# A tibble: 4 × 3
  variable n_miss pct_miss
  <chr>     <int>    <num>
1 hba1c       197    24.6 
2 egfr         91    11.4 
3 smoking      77     9.62
4 ldl          66     8.25
rPercentage of complete cases
pct_complete_case(d_obs)
Output
[1] 56
rPlot of missing values per variable
gg_miss_var(d_obs, show_pct = TRUE) +
  labs(x = NULL, y = "% ελλειπουσών τιμών") +
  theme(axis.text.y = element_text(size = 11))
Percentage of missing values per variable.
Figure 2Percentage of missing values per variable.

Missingness pattern

The second question is which combinations of variables are missing together. The pattern is called monotone when the variables can be ordered so that the missingness of one implies the missingness of all those that follow, as with dropout from a longitudinal study, and arbitrary in every other case. The distinction matters in practice, because a monotone pattern allows simpler imputation methods, whereas an arbitrary one requires iterative procedures such as MICE. plot_pattern() from ggmice renders each pattern as a row, with the number of patients who follow it.

rMissingness patterns
plot_pattern(d_obs |> select(age, sex, dm_years, education, bmi, sbp, ldl, smoking, hba1c, egfr),
             rotate = TRUE, npat = 10) +
  scale_fill_manual(values = c(observed = navy, missing = pink),
                    labels  = c(observed = "παρατηρούμενη", missing = "ελλείπουσα")) +
  labs(fill = NULL)
Missingness patterns. Each row is one combination of observed and missing variables, with the number of patients who show it on the left.
Figure 3Missingness patterns. Each row is one combination of observed and missing variables, with the number of patients who show it on the left.

The pattern is clearly arbitrary, with four variables missing in every possible combination. The same information is conveyed more directly as the number of patients per number of missing variables, which shows that most incomplete patients have a single missing value, a fact that makes excluding them particularly wasteful.

rPatients per number of missing variables10 lines
d_obs |>
  mutate(n_miss = rowSums(is.na(pick(everything())))) |>
  count(n_miss) |>
  mutate(complete = n_miss == 0) |>
  ggplot(aes(x = factor(n_miss), y = n, fill = complete)) +
  geom_col(width = 0.6) +
  geom_text(aes(label = n), vjust = -0.4, size = 3.6, colour = navy) +
  scale_fill_manual(values = c(`TRUE` = navy, `FALSE` = pink), guide = "none") +
  scale_y_continuous(expand = expansion(mult = c(0, 0.12))) +
  labs(x = "ελλείπουσες μεταβλητές ανά ασθενή", y = "ασθενείς")
Number of patients per number of missing variables.
Figure 4Number of patients per number of missing variables.

Exploring the mechanism

The third question, and the only one directly tied to the validity of the analysis, is what the missingness of each variable depends on. The simplest way to explore it is to compare the distribution of each observed variable between those who have and those who do not have a value in the variable that is missing. naniar adds, with bind_shadow(), a missingness indicator for each variable, which is then used as an ordinary grouping variable. For HbA1c, the comparison with respect to age, years since diagnosis and body mass index shows a shift in the first two and none in the third.

rDistributions by HbA1c missingness11 lines
d_obs |>
  bind_shadow() |>
  pivot_longer(c(age, dm_years, bmi), names_to = "var", values_to = "value") |>
  mutate(var = factor(var, levels = c("age", "dm_years", "bmi"),
                      labels = c("Ηλικία (έτη)", "Έτη από τη διάγνωση", "Δείκτης μάζας σώματος"))) |>
  ggplot(aes(x = value, fill = hba1c_NA)) +
  geom_density(alpha = 0.55, colour = NA, adjust = 1.5) +
  facet_wrap(~ var, scales = "free") +
  scale_fill_manual(values = c(navy, pink), labels = c("HbA1c παρατηρούμενη", "HbA1c ελλείπουσα")) +
  labs(x = NULL, y = "πυκνότητα", fill = NULL) +
  theme(legend.position = "top")
Distribution of age, years since diagnosis and body mass index according to whether HbA1c is observed or missing.
Figure 5Distribution of age, years since diagnosis and body mass index according to whether HbA1c is observed or missing.

The differences seen in the graphical comparison are then tested with logistic regression, in which the missingness indicator of each variable is modelled as a function of the fully observed variables. This model is the most useful tool of the exploration, because it shows which variables predict missingness and therefore which must without fail be included in an imputation model. The odds ratios of the four models are summarised in Figure 6.

rLogistic regression of the missingness indicator28 lines
miss_models <- d_obs |>
  mutate(across(c(ldl, hba1c, smoking, egfr), is.na, .names = "{.col}_NA")) |>
  pivot_longer(ends_with("_NA"), names_to = "variable", values_to = "missing") |>
  mutate(variable = str_remove(variable, "_NA")) |>
  group_by(variable) |>
  group_modify(~ glm(missing ~ age + sex + dm_years + education + bmi + sbp,
                     family = binomial, data = .x) |>
                 broom::tidy(exponentiate = TRUE, conf.int = TRUE)) |>
  ungroup() |>
  filter(term != "(Intercept)")

miss_models |>
  mutate(term = factor(term,
           levels = rev(c("age", "sexM", "dm_years", "educationsecondary", "educationtertiary", "bmi", "sbp")),
           labels = rev(c("ηλικία (ανά έτος)", "άνδρας (έναντι γυναίκας)", "έτη από τη διάγνωση (ανά έτος)",
                          "δευτεροβάθμια εκπαίδευση", "τριτοβάθμια εκπαίδευση", "BMI (ανά μονάδα)", "ΣΑΠ (ανά mmHg)"))),
         variable = factor(variable, levels = c("ldl", "hba1c", "smoking", "egfr"),
                           labels = c("LDL", "HbA1c", "Κάπνισμα", "eGFR")),
         signif = conf.low > 1 | conf.high < 1) |>
  ggplot(aes(x = estimate, y = term, colour = signif)) +
  geom_vline(xintercept = 1, colour = grey, linetype = 2) +
  geom_errorbar(aes(xmin = conf.low, xmax = conf.high), width = 0.25, orientation = "y") +
  geom_point(size = 2.2) +
  facet_wrap(~ variable, nrow = 1, scales = "free_x") +
  scale_x_log10() +
  scale_y_discrete(labels = function(x) x, drop = FALSE) +
  scale_colour_manual(values = c(`TRUE` = pink, `FALSE` = navy), guide = "none") +
  labs(x = NULL, y = NULL)
Logistic regression of each variable's missingness indicator on the observed variables. Odds ratios of missingness with 95% confidence intervals, in pink those that differ statistically from one. Secondary and tertiary education versus primary.
Figure 6Logistic regression of each variable's missingness indicator on the observed variables. Odds ratios of missingness with 95% confidence intervals, in pink those that differ statistically from one. Secondary and tertiary education versus primary.

For LDL no factor is associated with missingness, a picture compatible with MCAR. For HbA1c, age and years since diagnosis predict missingness, for smoking the educational level does, and these variables must be included in the imputation model. For eGFR, age and years since diagnosis also appear as predictors, not because they directly determine the missingness, however, but because they are correlated with eGFR itself, on which the loss really depends. From the observed data the picture for eGFR cannot be told apart from that for HbA1c, and yet the first is MNAR and the second MAR.

Little's (1988) test, finally, examines the null hypothesis that the mechanism is MCAR for the whole dataset.

rLittle's MCAR test
mcar_test(d_obs |> select(age, dm_years, bmi, sbp, ldl, hba1c, egfr))
Output
# A tibble: 1 × 4
  statistic    df p.value missing.patterns
      <dbl> <dbl>   <dbl>            <int>
1      257.    37       0                8

The MCAR hypothesis is rejected, as expected, since three of the four incomplete variables are not MCAR. But the test does not say which, nor can it separate eGFR from HbA1c. It answers the question of whether the dataset as a whole is missing completely at random, not the question that matters in practice.

What the exploration can and cannot show

The steps above answer three questions: how extensive the missingness is, what structure it has, and which observed variables it depends on. The last answer rules out MCAR for most variables and indicates which variables the imputation model must include. It cannot show, however, whether, beyond age and years since diagnosis, the missingness of eGFR also depends on eGFR itself, because that information lies by definition in the values that were not observed. Telling MAR from MNAR remains a decision that rests on knowledge of how the data were collected, in this example the knowledge that patients with renal impairment are referred outside the system, and the choice of imputation method, examined in the next article, starts from that decision.

References

  1. Haneuse S, Arterburn D, Daniels MJ (2021). Assessing missing data assumptions in EHR-based studies, a complex and underappreciated task. JAMA Network Open, 4(2), e210184.
  2. Lee KJ, Tilling K, Cornish RP, et al. (2023). Assumptions and analysis planning in studies with missing data in multiple variables, moving beyond the MCAR/MAR/MNAR classification. International Journal of Epidemiology, 52(4), 1268–1275.
  3. Little RJA (1988). A test of missing completely at random for multivariate data with missing values. Journal of the American Statistical Association, 83(404), 1198–1202.
  4. Oberman HI (2023). ggmice: Visualizations for mice. R package. https://amices.org/ggmice/
  5. Rubin DB (1976). Inference and missing data. Biometrika, 63(3), 581–592.
  6. Tierney N, Cook D (2023). Expanding tidy data principles to facilitate missing data exploration, visualization and assessment of imputations. Journal of Statistical Software, 105(7), 1–31.
  7. van Buuren S (2018). Flexible Imputation of Missing Data, 2nd ed. Chapman & Hall/CRC.