Skip to content

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.

Applied ~10 min7 steps

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

01

Your options in Prepare

Read

Each 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.

02

What a fill does to spread

Predict

Predict first

A column holds 2, 4 and 6, plus two blanks. You fill both blanks with the mean. What happens to the standard deviation?

Goes upStays the sameGoes down
Reveal

The answer: Goes down

It goes down. Before: s=8/2=2s = \sqrt{8/2} = 2. After, the values are 2, 4, 4, 4, 6, and s=8/4≈1.41s = \sqrt{8/4} \approx 1.41. The fills added rows and no spread, so everything computed from this column looks more certain than it is.

03

Flag before you fill

In the app

Add 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.

New York air quality, 1973
04

Time order changes the choice

Reflect

airquality 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.

05

The real cost

Read

Any 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.

06

Check your understanding

Checkpoint

Check 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.

07

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