14.2 Missing data
Missing data are common and can bias analyses if handled poorly. Bayesian models can impute missing values inside the model, treating them as additional parameters.
14.2.1 Types of missing data
- MCAR (Missing Completely At Random): Missingness is independent of everything. Dropping cases is unbiased but loses power.
- MAR (Missing At Random): Missingness depends on observed variables. Can be handled by imputation conditional on observed data.
- MNAR (Missing Not At Random): Missingness depends on unobserved values. Hardest to handle — requires explicit model of missingness.
# Demonstrate missing data types and bias
set.seed(42)
n <- 300
# Full data
x <- runif(n, 0, 10)
y <- 2 + 0.5 * x + rnorm(n, 0, 1)
# MCAR: randomly remove 20% of x
mcar_idx <- sample(1:n, 0.2 * n)
x_mcar <- x
x_mcar[mcar_idx] <- NA
# MAR: remove x when y is high (y is observed)
mar_idx <- which(y > quantile(y, 0.8))
x_mar <- x
x_mar[mar_idx] <- NA
# Complete-case analysis (drop NAs)
m_full <- lm(y ~ x)
m_mcar <- lm(y ~ x_mcar[!is.na(x_mcar)] ~ x[!is.na(x_mcar)])
# Fix: proper formula
d_mcar <- data.frame(y = y, x = x_mcar)
m_mcar <- lm(y ~ x, data = d_mcar[complete.cases(d_mcar), ])
d_mar <- data.frame(y = y, x = x_mar)
m_mar <- lm(y ~ x, data = d_mar[complete.cases(d_mar), ])
cat("Missing data bias comparison:\n")
cat(" True slope: 0.500\n")
cat(" Full data slope:", round(coef(m_full)[2], 3), "\n")
cat(" MCAR slope (complete cases):", round(coef(m_mcar)[2], 3), "\n")
cat(" MAR slope (complete cases):", round(coef(m_mar)[2], 3), "(biased!)\n")
cat("\n MCAR: complete-case is unbiased but loses power\n")
cat(" MAR: complete-case is BIASED — need imputation\n")14.2.2 Bayesian imputation
The Bayesian approach treats missing values as parameters to be estimated:
The missing values are imputed from their posterior distribution, and the uncertainty in the imputed values propagates into the regression estimates.
# Bayesian imputation: simple demonstration
set.seed(42)
n <- 300
x <- runif(n, 0, 10)
y <- 2 + 0.5 * x + rnorm(n, 0, 1)
# Create MAR missingness: x missing when y is high
mar_idx <- which(y > quantile(y, 0.8))
x_obs <- x
x_obs[mar_idx] <- NA
# Method 1: Complete-case (biased)
d_cc <- data.frame(y = y, x = x_obs)[complete.cases(data.frame(y = y, x = x_obs)), ]
m_cc <- lm(y ~ x, data = d_cc)
# Method 2: Mean imputation (too simple)
x_mean_imp <- ifelse(is.na(x_obs), mean(x_obs, na.rm = TRUE), x_obs)
m_mean <- lm(y ~ x_mean_imp)
# Method 3: Conditional imputation (impute from y)
# Since x and y are correlated, use y to predict missing x
d_obs <- data.frame(y = y[!is.na(x_obs)], x = x_obs[!is.na(x_obs)])
m_impute_x <- lm(x ~ y, data = d_obs)
x_imputed <- ifelse(is.na(x_obs),
predict(m_impute_x, newdata = data.frame(y = y)),
x_obs)
m_bayes <- lm(y ~ x_imputed)
cat("Imputation comparison:\n")
cat(" True slope: 0.500\n")
cat(" Complete-case:", round(coef(m_cc)[2], 3), "(biased under MAR)\n")
cat(" Mean imputation:", round(coef(m_mean)[2], 3), "(biased)\n")
cat(" Conditional imputation:", round(coef(m_bayes)[2], 3), "(better)\n")
cat("\n Full Bayesian imputation would also propagate\n")
cat(" the uncertainty in the imputed values.\n")Missing data is a modeling opportunity. The standard approaches to missing data — dropping cases, mean imputation — are modeling decisions, even if they do not feel like it. Dropping cases assumes the data are MCAR. Mean imputation assumes the missing values equal the observed mean. Both are usually wrong. The Bayesian approach is more honest: treat missing values as unknown quantities, model them, and let the data inform their values. This is multiple imputation within the posterior — each posterior sample contains a different imputed value, and the uncertainty propagates naturally. The result is not just better estimates — it is more honest uncertainty.
Summary of Section 14.2
- MCAR: Missingness independent of everything — complete-case is unbiased.
- MAR: Missingness depends on observed data — need imputation.
- MNAR: Missingness depends on unobserved data — hardest to handle.
- Bayesian imputation: Treat missing values as parameters, estimate from posterior.
- Uncertainty in imputed values propagates into regression estimates naturally.