Two variables are jointly Gaussian with x1 ~ N(0, 1), x2 = 2 + 0.7 x1 + noise, so E x2 = 2. Some values of x2 are then deleted. If the chance of deletion is the same for everyone (MCAR), the average of the values that remain is still unbiased. If it depends on the always-observed x1 (MAR), the observed average is biased but a model that uses x1 repairs it. If it depends on the deleted value itself (NMAR), no method that ignores the mechanism can recover the truth. Mean imputation also shrinks the spread of x2 and weakens its correlation with x1, even under MCAR.
P(x2 missing) is 1/(1 + e−b) for MCAR, 1/(1 + e−(s x1 + b)) for MAR and 1/(1 + e−(s (x2 − 2) + b)) for NMAR; each point is deleted when its stored uniform number is below this probability. The sample is a fixed set of 2000 draws, the first n of which are used. Regression imputation fits x2 on x1 by least squares among the complete cases and fills each gap with the fitted value.
code/ch01_introduction.py (missing_sample, missing_summary).