Missing Data Processing

Lesson Objectives

  • Understand why missing data matters.
  • Differentiate MCAR, MAR, and MNAR.
  • Observe shifts in bias, variance, and distribution shapes.
  • Compare strategies:
    • dropna
    • mean imputation
    • KNN / model-based imputation
  • Review applications in BigMart.

Introduction

Core Premise

It is not enough to count how many data points are missing.
We must understand why they are missing.

The missingness mechanism determines:

  • whether our estimates suffer from bias
  • whether imputation is statistically valid
  • whether our model learns from a representative sample

Motivation

Missing data can lead to:

  • loss of statistical power
  • biased parameter estimators
  • corrupted standard errors
  • misleading confidence intervals
  • degraded predictive performance

Visual Example:

Missingness Concentrated in High Values

True Mean: 12.043, True Average: 12.043
Observed Mean: 11.119, Observed Average: 11.119
Missing Proportion: 28.650%

Guiding Questions

Before applying any missing data technique, ask:

  1. What is the percentage of missing data?
  2. What is the pattern of missingness?
  3. What is the underlying mechanism of missingness?
  4. Are we modeling a target variable or a predictor?1

1 A model can learn from imperfect predictors, but cannot learn without observing true target labels.


Structural Types of Missing Data

Unit Nonresponse

Entire observation is missing

X1 X2 Y
? ? ?

Example:
A respondent declines an entire survey questionnaire.

Item Nonresponse

Only specific features are missing

X1 X2 Y
✓ ? ✓

Example:
A customer profile exists, but one specific field was left unrecorded.


Missingness Mechanisms

MCAR — Missing Completely At Random

The probability of missingness does not depend on any variable.

\[ f(R \mid Y, X, \theta) = f(R \mid \theta) \]

Intuitively: “Rows were dropped completely at random.”

Example: Random sensor connection dropouts.


Synthetic Example: MCAR in Action

Missing Proportion: 20.57%
True Mean:        12.0425
Observed Mean:    12.0411
True Std Dev:     2.1935
Observed Std Dev: 2.1811

Interpretation

  • Missingness is independent of observed features.
  • Missingness is independent of unobserved values.
  • Mathematically the most straightforward scenario.

Practical Consequence

Ignoring missing values under MCAR:

  • Does not introduce estimation bias.
  • Reduces sample size and statistical power.

MAR — Missing At Random

Missingness probability depends strictly on observed variables.

\[ f(R \mid Y, X, \theta) = f(R \mid Y_{obs}, X, \theta) \]

Intuitively: “Missingness varies systematically across observable subgroups.”

Example: Item_Weight missingness occurs more frequently in specific known Outlet_Type categories.


Synthetic Example: MAR in Action

Missing Proportion by Group:
     Outlet_Type  missing
0  Grocery Store    0.763
1    Mini Market    0.173
2    Supermarket    0.031

True Mean: 12.177 Observed Mean: 13.693

Effect of MAR on the Observed Sample


Interpretation

  • Missingness is fully explained by observed variables.
  • Conditional on observed features, missingness does not depend on unobserved values.
  • Represents the standard assumption in applied data science.

Practical Consequence

Ignoring missing values under MAR:

  • Introduces sample selection bias.
  • Model-based or feature-conditioned imputation mitigates bias.

MNAR — Missing Not At Random

Missingness probability depends directly on the unobserved value itself.

\[ f(R \mid Y, X, \theta) = f(R \mid Y_{obs}, Y_{mis}, X, \theta) \]

Intuitively: “Data is missing precisely because of its value.”

Example: Extremely heavy items fail to be weighed due to scale limits.


Synthetic Example: MNAR in Action

True Mean: 12.012
Observed Mean: 10.716
Missing Proportion: 62.44%

Interpretation

  • Missingness mechanism depends on unobserved values.
  • The unobserved value causes its own missingness.
  • Most challenging scenario to handle.

Practical Consequence

Ignoring missing values under MNAR:

  • Introduces structural bias.
  • Standard imputation methods fail to correct bias.

Global Classification of Missing Data Mechanisms

In real datasets, different variables can exhibit different missingness mechanisms (MCAR, MAR, or MNAR). However, global dataset classification is determined by the joint missingness indicator vector:

\[ P(R \mid X_{\text{obs}}, X_{\text{mis}}) \]

If even one variable exhibits an MNAR mechanism, the overall joint missingness probability depends on unobserved values:

\[ P(R \mid X_{\text{obs}}, X_{\text{mis}}) \neq P(R \mid X_{\text{obs}}) \]

Consequently, the entire dataset must be classified as MNAR.

Conclusion: A single MNAR feature dictates the global missingness classification.

Strategies for Handling Missing Data

Practical Strategies

  • Listwise Deletion (Complete Cases): Drops incomplete records; simple, but loses sample volume and power.
  • Single Imputation: Replaces missing entries with mean, median, or mode; fast, but artificially depresses variance.
  • Multiple Imputation: Generates multiple plausible imputed datasets and pools results; captures uncertainty.
  • KNN / Model-Based Imputation: Uses observed feature correlations to estimate missing values; effective under MAR.

Listwise Deletion

Listwise deletion discards any observation containing at least one missing feature value.

Effective sample size decreases to:

\[ n_{\text{effective}} = n \cdot P(\text{complete}) \]

Valid primarily under MCAR.

Single Imputation

Replaces missing values with a representative statistic computed from observed data:

\[ Y_{mis} \leftarrow \bar{Y}_{obs} \]

Synthetic Example: Single Imputation Comparison

Single imputation artificially reduces sample variance by placing a spike of identical values at the central estimator.

Multiple Imputation

Multiple imputation generates \(m\) plausible imputed datasets, fits the model on each, and pools estimates across datasets using Rubin’s rules:

\[ \bar{q} = \frac{1}{m} \sum_{i=1}^{m} q_i \qquad T = \bar{U} + \left(1 + \frac{1}{m}\right) B \]

where \(\bar{U}\) is within-imputation variance and \(B\) is between-imputation variance.

Synthetic Example: Multiple Imputation

KNN and Model-Based Imputation

KNN estimates missing values using \(k\) nearest neighbors across observed feature dimensions:

\[ \hat{x}_i = \frac{1}{k}\sum_{j \in N_k(i)} x_j \]

Conclusions

  1. The mechanism matters more than the missing percentage. A 5% MNAR pattern introduces more structural bias than a 25% MCAR pattern.
  2. Diagnose missingness patterns before choosing imputation algorithms.
  3. Mean imputation suppresses variance and introduces bias under non-MCAR conditions.
  4. KNN and model-based imputations preserve correlation structures under MAR.
  5. Use Scikit-learn Pipelines (sklearn.pipeline.Pipeline) to prevent data leakage during imputation.