Filling gaps and what it costs
Fill missing values by column, by group or along time, flag what you filled, and see what a single fill does to uncertainty.
You will be able to
- Choose between mean, median, group and time-based fills
- Flag filled values so analyses can tell them apart
- Explain why one fill understates uncertainty
Read first
Your options in Prepare
ReadEach fill is a step in a recipe:
- Fill missing values uses the mean, median, most frequent value or a constant.
- Fill missing values by group uses the value for the row's group.
- Fill down / up carries a neighboring value along a sequence.
- Interpolate gaps draws a straight line between known neighbors.
Prefer the median for skewed columns, and the group version when groups differ. Use the last two only when rows are in a meaningful order.
What a fill does to spread
PredictPredict first
A column holds 2, 4 and 6, plus two blanks. You fill both blanks with the mean. What happens to the standard deviation?
Reveal
The answer: Goes down
It goes down. Before: . After, the values are 2, 4, 4, 4, 6, and . The fills added rows and no spread, so everything computed from this column looks more certain than it is.
Flag before you fill
In the appAdd Flag missing values before the fill. You get a TRUE/FALSE column that records which rows were filled, and a model can then use the fact that a value was missing.
Suggested fixes propose this pairing for you. Open a recipe on airquality in Prepare (⌘3), then open Suggested fixes.
Time order changes the choice
Reflectairquality has one row per day, so a gap in ozone sits between two real neighbors. Interpolating respects that order, and a column-wide median ignores it.
Ask yourself: is today's reading more like yesterday's or like the summer's median? If you can answer, you know which fill fits. If you can't, the row order probably carries no meaning, and neighbor-based fills would invent a pattern.
The real cost
ReadAny single fill treats a guess as if it had been measured. Standard errors shrink, p-values fall and intervals narrow, for no new information.
For describing data or feeding a tree model, that may be acceptable. For inference, use multiple imputation, which keeps the uncertainty about each guess. It has its own lesson in this track.
Check your understanding
CheckpointCheck yourself
Income is strongly right-skewed and 5% missing. For a quick descriptive table, which single fill is the most defensible?
Show the answer
Answer: b
The mean is pulled up by large incomes, and zero asserts something false. A flag keeps the fill visible.
Check yourself
A column holds 1, 2, 3, 4, 5 and one blank. What value does a mean fill give the blank?
Show the answer
Answer: 3
The mean of the observed values: (1 + 2 + 3 + 4 + 5) / 5.
Recap
Recap- Match the fill to the data: median for skew, group for groups, time-based only for ordered rows.
- Flag before you fill.
- A single fill understates uncertainty. For inference, use multiple imputation.
Concepts in this lesson