Install any skill in seconds. Free to start, no credit card required.
Get Started Free →brycewang-stanford/missing-data-handling
Diagnose missing data patterns and apply appropriate imputation strategies
Passed 20 of 22 test cases with the skill, and 19 of 22 without it.
1 fixed19 passed either way2 still failing0 broke
Tokens, turns and time describe resource use, not a dollar price.
A test case the skill fixed. Same model, same prompt, with and without the skill.
I need Python code for handling MAR numerical data using chained equations multiple imputation and pooling results. Please provide two functions: one that accepts a numerical DataFrame and produces a collection of filled-in datasets via iterative sampling, and a second function that takes point estimates and variance vectors from model fits on those datasets and outputs a dictionary with pooled parameter estimates, pooled standard errors, 95% confidence bounds, fraction of missing information, and relative efficiency.
| Checked | Without skill | With skill |
|---|---|---|
| Uses IterativeImputer with BayesianRidge as the estimator for chained equation multiple imputation | Missed | Passed |
| Sets sample_posterior=True in the iterative imputer instantiation | Missed | Passed |
| Returns a dictionary from the pooling function containing keys pooled_estimate, pooled_se, ci_95, fraction_missing_info, and relative_efficiency | Missed | Passed |
The instructions your model reads when the skill loads.
A skill for diagnosing missing data mechanisms, selecting appropriate imputation strategies, and conducting sensitivity analyses. Covers everything from simple imputation to multiple imputation and modern machine learning approaches.
Understanding the mechanism determines the appropriate handling strategy:
| Mechanism | Definition | Example | Implication |
|---|---|---|---|
| MCAR | Missingness unrelated to any variable | Lab sample randomly contaminated | Listwise deletion is unbiased (but loses power) |
| MAR | Missingness related to observed variables | Higher-income respondents skip income question less | Multiple imputation appropriate |
| MNAR | Missingness related to the missing value itself | Depressed patients drop out of depression study | Requires sensitivity analysis; no simple fix |
import pandas as pd
import numpy as np
from scipy import stats
def diagnose_missing_data(df: pd.DataFrame) -> dict:
"""
Diagnose missing data patterns and mechanism.
"""
n_rows, n_cols = df.shape
results = {
'total_cells': n_rows * n_cols,
'total_missing': df.isnull().sum().sum(),
'pct_missing': (df.isnull().sum().sum() / (n_rows * n_cols)) * 100,
'by_column': {}
}
for col in df.columns:
n_missing = df[col].isnull().sum()
pct = n_missing / n_rows * 100
results['by_column'][col] = {
'n_missing': n_missing,
test cases passed, vs 19 / 22 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.