Evaluating Feature Imputation Methods for Linear Regression Models
Machine LearningModel answerLast updated
Analyze and contrast mean imputation, empirical sample imputation, and missingness indicator techniques in linear models across MCAR, MAR, and MNAR data mechanisms.
You are building a linear regression pipeline where one of your continuous numerical inputs contains missing entries. You are considering three different approaches to handle these missing entries before fitting the model:
- Mean Imputation: Replace missing values with the mean of the non-missing training entries.
- Empirical Distribution Sampling: Replace missing values by randomly drawing with replacement from the observed non-missing training entries.
- Mean Imputation + Missingness Indicator: Replace missing values with the training mean while adding an extra binary column ($1$ if missing, $0$ otherwise).
Evaluate and compare these three techniques. In your analysis, address:
- Statistical Impact: How each strategy alters feature marginal variance, covariance with other features, model coefficient estimates, and prediction variance.
- Missingness Mechanisms: How each method performs when data is Missing Completely at Random (MCAR), Missing at Random (MAR), or Missing Not at Random (MNAR).
- Data Leakage & Production: Guidelines for properly fitting and serving these imputers without introducing leakage across splits or production environments.
Hints
Hint 1
Consider how filling missing entries with a single constant value impacts the variance of the feature and its calculated covariance with correlated variables.
Hint 2
Distinguish between prediction tasks and parameter inference: adding a missingness indicator creates a piecewise-like continuous adjustment for linear models.
Hint 3
Recall that MAR implies missingness depends on observed features, whereas MNAR depends on unobserved values or the missing feature itself.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Executive Overview
When building linear prediction models, missing values in continuous features cannot be ignored by standard standard estimation routines (such as Ordinary Least Squares). Selecting an imputation strategy involves evaluating trade-offs between variance shrinkage, covariance distortion, prediction quality, and model parameter interpretability.
Detailed Strategy Comparison
1. Mean Imputation
- How it works: Replaces missing entries of feature $X_j$ with its marginal sample mean $\bar{X}_j$, computed strictly over the observed values in the training set.
- Effect on Marginal Variance: Shrinks marginal variance. Adding identical mean values compresses the sample distribution around the center without adding spread.
- Effect on Covariance & Correlation: Attenuates (dampens) covariance and correlation with other features toward zero. Because the imputed values have zero linear relationship with any other covariate $X_k$, the joint covariance drops proportionally to the missingness rate.
- Model Coefficients & Predictions: Distorts coefficient estimates when features are correlated. Shrinking covariance can induce bias in coefficients across all covariates in multi-variable regression. Variance of prediction can be artificially suppressed.
2. Empirical Distribution Sampling (Single Random Draw)
- How it works: Replaces each missing value by drawing randomly (with replacement) from the observed training values of $X_j$.
- Effect on Marginal Variance: Preserves marginal variance approximately on average relative to the observed subset.
- Effect on Covariance & Correlation: Severely degrades covariance. Drawing values independently breaks the underlying relationship between $X_j$ and all other features $X_k$ for missing rows. It injects pure random noise into the joint feature space.
- Model Coefficients & Predictions: Acts like classical measurement error (attenuation bias) on feature $X_j$. It increases model prediction variance due to the artificial noise injected into test rows during random draws.
3. Mean Imputation + Missingness Indicator
- How it works: Replaces missing entries with the marginal mean $\bar{X}_j$ and appends a binary feature $M_j \in {0, 1}$ (where $1$ indicates missingness).
- Effect on Marginal Variance & Covariance: While the univariate mean substitution still compresses $X_j$, the dummy variable $M_j$ acts as an offset shift.
- Model Coefficients & Predictions: Provides the linear model with a dedicated degree of freedom $\beta_{M_j}$ to model the conditional expectation for the missing subpopulation: $$\hat{y} = \beta_0 + \beta_j \cdot X_j^{\text{imputed}} + \beta_{M_j} \cdot M_j$$ For observed rows ($M_j = 0$), the model fits $\beta_j$ using the observed line. For missing rows ($M_j = 1$), the prediction is adjusted by the offset $\beta_{M_j}$, isolating missing rows from biasing the main slope $\beta_j$.
Comparison Matrix
| Property | Mean Imputation | Empirical Sampling | Mean Imputation + Indicator |
|---|---|---|---|
| Marginal Variance of $X_j$ | Underestimated (Shrunk) | Preserved | Underestimated on $X_j$, tracked via $M_j$ |
| Covariance with $X_k$ | Attenuated toward 0 | Destroyed for missing rows | Preserved for observed rows via indicator offset |
| Model Interpretability | Biased coefficients | Noise-attenuated coefficients | Clear separation of missing vs. observed effects |
| Prediction Variance | Underestimated | Artificially elevated | Balanced and adaptive |
Performance Across Missingness Mechanisms
MCAR (Missing Completely at Random)
Missingness is independent of both observed features and unobserved values.
- Mean Imputation: Unbiased estimates of the mean, but distorts regression slopes if covariates are correlated.
- Empirical Sampling: Preserves marginal distribution shape, but degrades predictive power due to noise injection.
- Mean Imputation + Indicator: Performs well. The indicator coefficient $\beta_{M_j}$ will often be near zero or capture minor global mean shifts.
MAR (Missing at Random)
Missingness depends systematically on observed covariates (e.g., older patients are less likely to report income).
- Mean Imputation & Empirical Sampling: Biased. Imputing the global unconditional mean $\bar{X}_j$ ignores the dependence on other observed covariates $X_k$, resulting in distorted parameters.
- Mean Imputation + Indicator: Sub-optimal compared to model-based methods (e.g., Iterative/MICE), but better than pure mean imputation. If missingness correlated features $X_k$ are included in the regression model, the linear model can partially offset the bias, though conditional imputation (predicting $X_j$ from $X_k$) is preferred under MAR.
MNAR (Missing Not at Random)
Missingness depends directly on the unobserved value itself (e.g., high earners omit income).
- Mean Imputation & Empirical Sampling: Severely biased because the observed distribution does not reflect the missing distribution.
- Mean Imputation + Indicator: Strongest non-parametric baseline. The indicator $M_j$ allows the model to assign a specific baseline target response $\beta_{M_j}$ to the missing group, directly learning the distinct outcome behavior of missing rows.
Prevention of Data Leakage & Production Deployment
To prevent target leakage and data snooping in real-world ML systems:
- Split First: Always split data into Training, Validation, and Test sets before performing imputation statistics calculation.
- Stateful Imputers: Compute the baseline parameters (e.g., training mean $\bar{X}_j$, empirical lookup tables) exclusively on the training split.
- Pipeline Transformation: Save the calculated $\bar{X}_j$ inside a scikit-learn pipeline or object artifact. During evaluation or production inference, apply the saved training mean and construct the binary missingness indicator deterministically based on input null states.