Holes, caps and spikes: missing values, censoring and outliers

After this lesson you will find the holes that hide in a data set, decide whether to drop or fill them, tell censored from truncated data, and explain why a z-score can miss an outlier that your eye sees at once.

The slide on p. 1120 prints eleven numbers, 3, 4, 7, 4, 8, 3, 9, 5, 7, 6, 92, and calls the 92 "suspicious". You saw it before you finished reading. Now test it the way a statistics course teaches: compute its z-score, its distance from the mean in standard deviations, and flag it if the score is above 3. The 92 scores 3.006: flagged, but only by a hair.

Make it worse. Replace the 92 by 920, or by 92 million. Write down your guess for the new z-score: 30? 300?

Both times it is 3.015, and no number in a list of eleven can ever score more. Section 5 shows why, and which yardstick puts the 92 at a distance of 29. On the way there, the lesson meets the other ways a data set lies by omission: holes, capped values and spikes.

Munging, and why a number needs a meaning

Lesson 35 followed the wrangling steps of the slides. Before the statistics, the deck adds one more word (p. 1102):

Data munging — "Potentially lossy transformations applied to a piece of data or a file"; "Vague data transformation steps that are not yet completely clear"; "E.g., removing punctuation or html tags, data parsing, filtering, and transformation." (p. 1102)

Both properties are warnings. Lossy: strip the punctuation and "U.S." and "US" become one string, with no way back; strip the HTML tags and the table that said which number was the price is gone. Vague: you munge while still finding out what the data needs, so nobody writes the steps down. Hence the habit: keep the raw file, munge a copy, record each step as a replayable script (the tools are in lesson 37).

A column without a name

The next slide is a single column of thirteen numbers under the header "???", with a large question mark beside it (p. 1103). Look at the left panel of Fig. 1 and decide which number is odd. The second build (p. 1104) reveals the header, "Age(Years)", draws an R boxplot and adds one sentence: "The value stands in the abnormal".

??? 75 80 65 55 67 78 88 90 45 58 69 80 110 what is it?

Before (p. 1103): a column without a name

Age(Years) 75 80 65 55 67 78 88 90 45 58 69 80 110 50 70 90 110 110 fence 102.5 box 65–80 fence 42.5

After (p. 1104): "Age(Years)" and the boxplot

Fig. 1. The same thirteen numbers before and after the header is revealed (pp. 1103–1104, redrawn). The slide's sentence under the boxplot: "The value stands in the abnormal". The two dotted fences are not on the slide: they show where the rule of R's boxplot draws its line, and the ring marks the one value beyond it.

R's boxplot decides with a rule the slide does not print (background): a value more than 1.5 interquartile ranges beyond the box is drawn as a separate point. For the thirteen ages:

\[ Q_1 = 65, \quad \tilde x = 75, \quad Q_3 = 80 \] \[ \text{IQR} = Q_3 - Q_1 = 15 \] \[ Q_3 + 1.5 \cdot \text{IQR} = 102.5 \] \[ Q_1 - 1.5 \cdot \text{IQR} = 42.5 \]
\(Q_1, Q_3\)
lower and upper quartile: the edges of the box
\(\tilde x\)
the median: the thick line inside the box
\(\text{IQR}\)
interquartile range: the height of the box

The whiskers stop at 45 and 90, the last values inside the fences; 110 lies beyond 102.5 and is drawn alone. That is arithmetic, and it holds under any header. The header adds the verdict. As an age, 110 sits at the edge of human life: a typo for 10 or 101, a misfiled record, or a rare real person. As a body weight in kilograms it would be an ordinary heavy adult. Hence the order of the two builds: first the meaning, then the expected, then the departure.

No expected value without the meaning of the column, and no outlier without an expected value.

Holes you can see, and holes that hide

The deck looks for missing data in two layers (pp. 1105–1106): holes you can see if you look, and damage that leaves the file looking complete.

  • "Match data specifications against data - are all the attributes present?"
  • "Scan individual records - are there gaps?"
  • "Rough checks : number of files, file sizes, number of records, number of duplicates"
  • "Compare estimates (averages, frequencies, medians) with “expected” values and bounds; check at various levels of granularity since aggregates can be misleading"
  • "Values are truncated or censored - check for spikes and dips in distributions and histograms"
  • "Missing values and defaults are indistinguishable - too many missing values? metadata or domain expertise can help"
  • "Errors of omission e.g. all calls from a particular area are missing - check if data are missing randomly or are localized in some way"

Mind the last overt check: aggregates can be misleading. A monthly total of calls can be right while one week is missing and another was loaded twice; the errors cancel in the total and show only per week, region or source.

Hidden damage can pass every count. If a loader writes 0 for an absent value, a customer who made no calls and one whose minutes were lost look the same, and only metadata or domain knowledge can tell them apart. The cure is upstream: store a real empty value, never a default that looks like data.

Three ways a value goes missing

"Missing Values: Random" (p. 1107) is a bar chart of visitors per day: days 11, 12 and 16 have no bar, and beside it stand "System failures" and "Complete miss".

0 10k 20k 30k 40k visitors per day ? ? ? 1 5 10 15 20 25 31 days of month
Fig. 2. "Missing Values: Random" (p. 1107), redrawn; the bar heights are read off the slide's chart. The three marked slots are the days the collecting system failed: no record at all, a "complete miss".

A failed collector removes whole records, and nothing about those days caused it: the holes fall at random. Leave them as holes. A bar of 0 would claim that nobody visited; an empty slot says that nobody knows. The mean per recorded day stays fair, while the monthly total is three days short.

"Missing Values: Wrong Ingestion" (p. 1108) is a "CSV to table / excel" accident. Three raw lines go into a six-column table:

Antony Mc James IV, 123 Untidy Cir, Suite# 234, Cumbersome, TX, 76849
Miller Johnson, 1102 Messy Data St, Middletow, OH
Betty Flyier 6483 Phew Lane, Apt A4, FixMe, CA, 91103

The loader splits at the commas and fills Customer, Address Line 1, Address Line 2, City, State and Zip from left to right. Line 1 has six values and lands correctly. Line 2 has four; line 3 has five, because the comma after the name is missing. The slide calls the defects "Missing fields" and "Merged fields" (Fig. 3).

Customer Address Line 1 Address Line 2 City State Zip Miller Johnson 1102 Messy Data St Middletow OH 4 values, 6 columns

Row 2 · "Missing fields": everything after the street slides left

Customer Address Line 1 Address Line 2 City State Zip Betty Flyier 6483 Phew Lane Apt A4 FixMe CA 91103 a comma is missing

Row 3 · "Merged fields": the name swallows the street

Fig. 3. Rows 2 and 3 of the loaded table of p. 1108, one field per line. Red wash: a value in the wrong column; dashed: a cell left empty.

Every value was in the file: the loader created the holes and put wrong values beside them ("OH" is now a city). A check that only counts empty cells may pass the file. The fix belongs in the parser — quote the fields, compare each line's number of values with the header — not in a statistical estimate.

"Missing Values: Inapplicability" (p. 1109) circles two blocks of a medical form, the women's health history and the men's (a PSA blood test for the prostate); every patient leaves one of them empty. The slide's two lines: "Partial data by nature", "Remember to leave empty slots".

The form of p. 1109 as a table (the patients are made up). A dash is an empty slot that says "does not apply", not "unknown".
patientsexlast mammogramPSA blood testcolonoscopy
AnnaF2025-03-11——
MarcoM—2024-11-022023-05-20
LuciaF2024-09-30—2022-01-15

Here an empty cell is a statement, not a hole. Filling it invents a PSA test for Anna; a default such as 1900-01-01 recreates the value-or-default confusion; dropping incomplete records deletes every patient. The schema must let the slot stay empty.

Three kinds of holes, three cures: estimate the random ones, fix the ingestion ones in the loader, leave the inapplicable ones empty.

Drop the record, or fill the hole?

Why not simply ignore every record with a hole? The slide "Imputing Values to Missing Data" (p. 1110) answers:

Federated data comes from several sources, each contributing some of the attributes. Why do so many records have a hole when each attribute is missing only now and then? Because the chances multiply:

  1. A record has \(p\) attributes. Each is missing with probability \(q\), so each is present with probability \(1 - q\).

  2. The record is complete only if every attribute is present. If the holes fall independently, the probabilities multiply:

    \[ P(\text{complete}) = (1 - q)^p \]
  3. Ten attributes with 5 % holes each:

    \[ 0.95^{10} = 0.599 \]

    40 % of the records have a hole although 95 % of every column is there. With twenty attributes, \(0.95^{20} = 0.36\): 64 % are lost. Both land inside the slide's 30–70 %.

Wastage is the visible cost; bias is the hidden one. The survivors are a fair sample only if the holes fall purely at random. If heavy callers come from a sloppier source and lose fields more often, the complete records are mostly light callers, and their average bill is too low. The widget shows both, and the two simplest fills.

Drop or impute?

A phone company's customer table, made up for this widget: 400 records with ten attributes each (seeded, so you always see the same table). The slider of each attribute sets the share of its cells that are holes. Top: the first 40 records, one column of ten cells per record; a dashed empty cell is a hole, a greyed record is dropped, and a filled-in value has its own colour (see the legend). Bottom: minutes against bill for all 400 records, with the true mean bill (dashed) and the mean bill the chosen method estimates (solid).

  1. Press "Every column 5 %", keep "at random" and "drop every incomplete record". Before you read the readouts, guess how many of the 400 records are complete.
    What you should see

    238 of 400 (59.5 %); the formula predicts \(0.95^{10} = 0.599\). Dropping incomplete records throws away 162 records, 40 % of the table, although only 5 % of each column is missing; in the grid, 24 of the first 40 records survive. That is the insight the widget is built for: small holes in many columns add up to a large loss of records.

  2. Press "Every column 0 %", then give one attribute, sms, 40 % holes. Does this lose more records than 5 % everywhere, or fewer?
    What you should see

    About the same: 243 complete records against 238, and the formula gives 0.600 against 0.599. Forty per cent of holes in one column cost the same as five per cent in each of ten.

  3. Back to 5 % everywhere, and switch the holes to "more often for heavy callers". With "drop", compare the mean bill with the truth, 40.37 €. Then try "fill with the column mean" and "fill by regression".
    What you should see

    Dropping gives 37.29 €, about 3.1 € too low: heavy callers lost their records more often, so the 251 survivors are mostly light callers — "Remaining data is seriously biased". Mean filling gives 39.99 €, and the correlation falls from 0.85 to 0.81. Regression filling gives 40.36 € with a correlation of 0.83. With holes "at random", dropping gives 40.36 € too: there, the damage is only the waste.

  4. Press "Every column 0 %", set bill to 40 %, keep "more often for heavy callers", and compare the two fills. Then read "typical error of one filled bill".
    What you should see

    Mean filling: 35.04 €, correlation 0.58, because the 182 filled bills sit on one horizontal line. Regression filling: 40.27 €, correlation 0.90, a little above the truth (0.85) because every filled bill lies exactly on the fitted line. The mean is off by 0.10 €, while one filled bill is off by 6.33 € on average: imputed values are useful in aggregates, not individually.

The last line of p. 1110 turns the problem around: the pattern of the holes is itself a finding. Holes from one source only mean a broken feed, holes on one date a failed load; and the pattern tells you what not to fill at all: ingestion holes and inapplicable slots.

The imputation ladder

To impute is to fill a hole with an estimate. The deck climbs a ladder; each rung uses more of the data and costs more.

Rung 1 is "Standalone imputation" (p. 1111): fill the hole with "Mean, median, other point estimates" of its own column. The slide adds: "Assume: Distribution of the missing values is the same as the non-missing values."; "Does not take into account inter-relationships"; "Introduces bias"; "Convenient, easy to implement". The widget showed the bias: filled values sit at the centre, so the spread shrinks and correlations weaken.

Rung 2, "Better imputation - use attribute relationships" (p. 1112), needs a condition on the pattern of the holes: "Assume : all prior attributes are populated", "That is, monotonicity in missing values." The slide's table is its picture (Fig. 4).

sweep left to right X1 X2 X3 X4 X5 row 1 row 2 row 3 row 4 1.0 20 3.5 4 . 1.1 18 4.0 2 . 1.9 22 2.2 . . 0.9 15 . . . once a hole, holes to the right
Fig. 4. The table of p. 1112, redrawn; a dot is a missing value, as on the slide. The staircase separates the observed cells from the holes: every hole has all the attributes to its left populated, which is what "monotonicity in missing values" means.

Monotone missing pattern — the attributes can be ordered \(X_1, X_2, \dots, X_p\) so that whenever \(X_j\) is missing, every attribute after it is missing too.

Monotonicity lets you fill the table column by column, left to right, always predicting from columns already full. The slide names "Two techniques": "Regression (parametric)" and "Propensity score (nonparametric)". The first is the "Regression method" (p. 1113): "Use linear regression, sweep left-to-right",

\[ X_3 = a + b X_2 + c X_1 \] \[ X_4 = d + e X_3 + f X_2 + g X_1 \]

"and so on", where "X3 in the second equation is estimated from the first equation if it is missing". The slide gives no numbers, so fit the first equation on its own table. It is a toy: three complete rows for three unknowns.

  1. Rows 1–3 have \(X_3\); row 4 does not. Write the first equation for the three complete rows:

    \[ 3.5 = a + 20b + 1.0c \] \[ 4.0 = a + 18b + 1.1c \] \[ 2.2 = a + 22b + 1.9c \]
  2. Subtract the first line from the other two, and \(a\) cancels:

    \[ 0.5 = -2b + 0.1c \] \[ -1.3 = 2b + 0.9c \]
  3. Add these two, and \(b\) cancels: \(c = -0.8\). Back-substitute: \(b = -0.29\), then \(a = 3.5 + 5.8 + 0.8 = 10.1\).

  4. Fill the hole of row 4, where \(X_1 = 0.9\) and \(X_2 = 15\):

    \[ \hat X_3 = 10.1 - 0.29 \cdot 15 - 0.8 \cdot 0.9 \] \[ \hat X_3 = 5.03 \]
  5. Compare with rung 1: the mean of the observed \(X_3\) is \(9.7 / 3 = 3.23\), the median 3.5. Three methods, three answers; and 5.03 is an extrapolation, since \(X_2 = 15\) lies below the observed 18 to 22.

The second technique, "Propensity Scores (nonparametric)" (p. 1114), models the chance that \(X_j\) is missing instead of its value:

  1. "Let Yj=1 if Xj is missing, 0 otherwise"
  2. "Estimate P(Yj =1) based on X1 through X(j-1) using logistic regression"
  3. "Group by propensity score P(Yj =1)"
  4. "Within each group, estimate missing Xjs from known Xjs using approximate Bayesian bootstrap."
  5. "Repeat until all attributes are populated."

Records with about the same score, the same chance of a hole, are treated as comparable, and each hole gets a value resampled from the observed values of its group (the approximate Bayesian bootstrap). Hence "nonparametric": no formula for \(X_j\) is assumed, although the score comes from a parametric logistic regression.

Rung 3 handles an "Arbitrary missing pattern" with "Markov Chain Monte Carlo (MCMC)" (p. 1115). It assumes that the "data is multivariate Normal, with parameter Θ" (means and covariances) and alternates "(1) Simulate missing X, given Θ estimated from observed X ; (2) Re-compute Θ using filled in X", "Repeat until stable." It is "Expensive: Used most often to induce monotonicity": MCMC fills just enough cells to make a staircase, and the cheap sweep does the rest. The slide ends, in bold:

"Note that imputed values are useful in aggregates but can’t be trusted individually"

The widget measured it (task 4): regression filling missed the mean bill by 0.10 €, a single filled bill by 6.33 € on average. Errors cancel in an average; one guess stays a guess.

Caps and cuts: censored and truncated data

Some damage is done by a bound. The slide "Censoring and Truncation" (p. 1116) calls it "Well studied in Biostatistics, relevant to time dependent data e.g. duration" and separates two cases.

Censored — "Measurement is bounded but not precise e.g. Call duration > 20 are recorded as 20". The record stays; its value is replaced by the bound.

Truncated — "Data point dropped if it exceeds or falls below a certain bound e.g. customers with less than 2 minutes of calling per month". The record is gone.

A censored call of 47 minutes is in the table as 20: you know only "at least 20". A truncated customer who called for one minute is not in the table at all, and nothing in it says that anyone is missing. Fig. 5 shows why p. 1106 says "check for spikes and dips".

0 10 20 30 call duration (min) spike at 20

Censored: "Call duration > 20 are recorded as 20"

0 10 20 30 minutes of calling per month under 2 min: gone

Truncated: customers "with less than 2 minutes of calling per month" are dropped

Fig. 5. The two examples of p. 1116 as histograms (the shapes are illustrative). Dashed bars: what really happened but is not in the data. Censoring keeps the records and piles their values on the bound, a spike; truncation removes the records, a hole at the edge, and nothing in the table says it is there.

The two bias the mean in opposite directions (background): capping long calls lowers the average duration, dropping light users makes the average customer heavier. Mnemonic: censored is capped, truncated is thrown out.

Background, not on the slides. In the Second World War the military wanted to armour the parts of returning bombers that showed the most bullet holes. Abraham Wald pointed out that only survivors were in the data: the armour belonged where the survivors showed no damage, because planes hit there had not come back. The lost planes were truncated out of the data.

Intervals the study only half sees

Durations are where censoring is at home. The figure "Censored time intervals" (p. 1117) draws a study window between "Begin Study" and "End Study" and six intervals against it (Fig. 6).

Left and Right censored Left Censored Right censored Complete 1 2 same in the data Begin Study Time End Study
Fig. 6. "Censored time intervals" (p. 1117), redrawn with the slide's labels. Solid: the part of each interval the study observes; dotted: the part it does not. Intervals 1 and 2 start together and are still running at End Study: the data cannot tell them apart, though the second lasts far longer.

An interval that began before the window is left censored: its start is unknown. One still running at the end is right censored: you know only that it lasted at least this long. Only "Complete" has a precise duration. Intervals 1 and 2 make the point: identical in the data, very different in reality. Read both as ending at End Study and both durations come out too short, the second by far. Biostatistics meets this daily: a patient still alive when a study ends has a right-censored survival time.

The bias can be mitigated on one condition, stated on p. 1118: "If censoring/truncation mechanism not known, analysis can be inaccurate and biased." "But if you know the mechanism, you can mitigate the bias from the analysis." Hence "Metadata should record the existence as well as the nature of censoring/truncation": capped at 20 minutes, say, or customers under 2 minutes excluded.

Spikes

The last picture (p. 1119) is a plot titled "Potential Data Problem": a noisy "Count" over "Current Accounts" with one spike above 600 and a smaller one above 200, and the caption "Spikes usually indicate censored time intervals caused by resetting of timestamps to defaults". When a system loses an account's real start date and writes a default instead (say, the date of a data migration), you know only that the account existed by then — its interval is censored — and every such account piles onto one value: defaults standing in for missing values.

Censored: the record stays and its value is capped. Truncated: the record is dropped. Both can show in a histogram, as a spike or a dip, and their bias can be mitigated only if metadata records them.

Departure from the expected: outliers

Back to the hook. The slide "Suspicious Data" (p. 1120) lists the eleven numbers and says "“92” is suspicious - an outlier". Then it refuses to convict: "Outliers are potentially legitimate"; "Often, they are data or model glitches"; "Or, they could be a data miner’s dream, e.g. highly profitable customers".

Three verdicts, all possible: a real but rare value; a glitch of the data (a typo for 9, a unit error, a default) or of the model (a wrong "expected" makes a normal value look odd); or your most valuable record, the big spender, the fraud worth finding. Deleting outliers automatically throws the third kind out with the second.

"Outliers must be removed before the analysis." The course notes (p. 86) do call outliers records "which need to be eliminated", but the slides say the opposite — potentially legitimate, possibly a data miner's dream — and the slides win. Investigate, then decide.

Outliers also move aggregates. Without the 92 the ten numbers have mean 5.6 and median 5.5; with it, mean 13.45 and median 6. One record in eleven more than doubled the mean; the median barely noticed.

Two yardsticks

The classic test divides the distance from the mean by the standard deviation. The robust test (background, not on the slide) uses ingredients an outlier cannot drag: the median and the median absolute deviation, MAD.

\[ z = \frac{x - \bar x}{s} \] \[ z_{\text{rob}} = \frac{x - \tilde x}{1.4826 \cdot \text{MAD}} \] \[ \text{MAD} = \operatorname{median}_i \abs{x_i - \tilde x} \]
\(\bar x, s\)
mean and sample standard deviation
\(\tilde x\)
median
\(\text{MAD}\)
median of the distances from the median
\(1.4826\)
makes MAD comparable to \(s\) for normally distributed data

For the slide's numbers, \(\bar x = 13.45\) and \(s = 26.13\), so the 92 has \(z = 3.006\). The median is 6, the distances from it are 3, 2, 1, 2, 2, 3, 3, 1, 1, 0 and 86, their median is 2, so \(z_{\text{rob}} = 86 / 2.965 = 29.0\). One yardstick says "barely", the other "very far".

The masked outlier

The ten ordinary numbers of p. 1120 and one suspicious value, 92 on the slide; the slider moves it. Top: the numbers on a line, twice — once with the classic band, mean ± k·s, once with the robust band, median ± k·1.4826·MAD; a ringed number is flagged as an outlier, the short vertical bar marks the centre. Bottom: the score of the suspicious value for every position from 10 to 100, classic and robust, against the threshold k.

  1. Keep the slide's 92 and \(k = 3\). Predict: does the classic rule flag the 92? Then set \(k = 3.1\).
    What you should see

    At \(k = 3\) the classic z is 3.006: flagged, by a margin of 0.006. At \(k = 3.1\) the 92 is no longer flagged. The robust z is 29.0, flagged for every \(k\) the slider offers.

  2. Move the suspicious value down to 50 and predict its classic z-score before you look.
    What you should see

    2.982: not flagged, although 50 sits among numbers from 3 to 9. Below 72 the 3-sigma rule never flags the suspicious value; its robust z at 50 is 14.8. In the lower plot the classic curve flattens under its ceiling of 3.015 while the robust line keeps climbing. That is the insight of the widget: the outlier inflates the standard deviation that judges it.

  3. Back to 92, and switch on the second suspicious value. Predict the classic z of each 92.
    What you should see

    2.137: neither 92 is flagged, because the mean is now 20 and \(s = 33.69\); even the ceiling drops to 2.141. The robust yardstick barely moves (median 6.5, MAD 2.5) and gives each 92 a robust z of 23.1: both flagged. Two outliers hide each other from the classic rule.

Why the classic score cannot pass 3.015

The masking is built into the formula (background, not on the slide): the outlier sits inside the mean and the standard deviation that judge it. Follow the most extreme case through:

  1. Put \(n - 1\) values equal to \(c\) and one at \(c + d\). The mean moves only a little:

    \[ \bar x = c + \frac{d}{n} \]
  2. The odd value lies \(d\,(n-1)/n\) above the mean, each of the others \(d/n\) below it. Add up the squared deviations:

    \[ (n-1)\,\frac{d^2}{n^2} + \frac{(n-1)^2\, d^2}{n^2} \] \[ = \frac{(n-1)\, d^2}{n} \]
  3. Divide by \(n - 1\) for the sample variance: \(s^2 = d^2 / n\), so \(s = d / \sqrt{n}\). The yardstick grows in proportion to the outlier's own distance.

  4. Divide the distance by the yardstick, and \(d\) cancels:

    \[ z = \frac{d\,(n-1)/n}{d / \sqrt{n}} = \frac{n-1}{\sqrt{n}} \]

    For \(n = 11\), \(10 / \sqrt{11} = 3.015\). Spreading the other values apart only lowers the score, so no value in a sample of eleven can score more.

The puzzle, resolved

The hook asked for the z-score of 920 and of 92 million among the ten small numbers. Both give 3.015, the ceiling \((n-1)/\sqrt{n}\) for eleven values: as the outlier moves away, it stretches the standard deviation as fast as its own distance grows. With eleven values a 3-sigma rule can flag a value only by a hair; among the slide's numbers it misses anything below about 72, and it misses both copies when the 92 comes twice. The robust yardstick does not move with the outlier: the 92 stands 29 robust units from the median, the 920 more than 300. The boxplot rule of Fig. 1 catches it too: for the eleven numbers the upper fence is \(7.5 + 1.5 \cdot 3.5 = 12.75\).

Many ways to define "expected"

The next slide (p. 1121) turns the example into a definition: "Outlier – “departure from the expected”", and "Types of outliers – defining “expected”". Every detection method states what you expected; the slide lists "Many approaches".

The approaches of p. 1121, in the slide's words, with what each one takes as "expected".
Approach (p. 1121)"Expected" isA departure is
"Error bounds, tolerance limits – control charts"a centre line and bounds computed from the dataan aggregate outside the bounds (section 6)
"Model based – regression depth, analysis of residuals"a model fitted to the relationships between attributesa large residual from a well-fitting model (section 6)
"Geometric"the dense region of the dataa point far from all its neighbours
"Distributional"the bulk of an assumed distributiona value in a low-probability tail, as with the z-scores above
"Time Series outliers"the series' own pasta sudden jump or shift

The geometric kind is familiar from clustering: the noise points of DBSCAN are points that no dense neighbourhood claims.

An outlier is a departure from the expected; every method is a way of defining "expected", and the verdict — legitimate, glitch or a data miner's dream — needs the meaning of the data.

Control charts: the expected band, for one variable and for many

Control charts come from "Quality control of production lots" (p. 1122): every hour a factory measures a small sample of its output and asks whether the process has changed. They are "Typically univariate: X-Bar, R, CUSUM": an X-bar chart plots the mean of each sample, an R chart its range (largest minus smallest value), a CUSUM chart the cumulative sum of the deviations from the target, which catches a small persistent shift. The "Main steps (based on statistical inference)":

  1. "Define “expected” and “departure” e.g. Mean and standard error based on sampling distribution of sample mean (aggregate);"
  2. "Compute aggregate each sample"
  3. "Plot aggregates vs expected and error bounds"
  4. "“Out of Control” if aggregates fall outside bounds"

For data quality a sample is a batch: one day's file, one source, one load (Fig. 7).

5 6 7 mean call duration of the day's file (min) UCL = mean + 3 SE centre line LCL = mean − 3 SE investigate day 1 day 10 day 20 day 30
Fig. 7. A control chart for data quality (an illustration, not the slide's data). Each dot is the aggregate of one sample, the mean call duration of one day's file; the thick dashed centre line is the expected value; the two thin dashed limits are the error bounds. Day 22 falls outside: that file is "Out of Control" and gets investigated before anyone uses it.

The bounds are usually three standard errors (background), \(\bar{\bar x} \pm 3\,\sigma / \sqrt{n}\) for samples of \(n\) items: standard errors, because the plotted point is an aggregate. This also explains "Distributional assumptions for charts not based on means e.g. R–charts": by the central limit theorem sample means are close to normal whatever the data, so an X-bar chart needs few assumptions; ranges enjoy no such theorem, so R-chart limits assume a normal population.

The kilogram example

"An Example" (p. 1123) is a real chart from the NIST handbook, "Shewhart control chart for kilogram calibrations": the "Corrections (mg)" of a reference kilogram calibrated again and again from the mid-1970s to the late 1980s. It prints "UCL = mean + 3s = -19.39 mg" and "LCL = mean - 3s = -19.57 mg", and the rest follows:

\[ \bar x = \frac{-19.39 - 19.57}{2} = -19.48 \ \text{mg} \] \[ s = \frac{-19.39 + 19.57}{6} = 0.03 \ \text{mg} \]

The limits are \(6s\) apart, hence the 6. Each point is a single calibration, not the mean of a sample, so its standard error is \(s\) itself and the bounds are \(\pm 3s\). A few points around 1987 reach the upper limit: those measurements get investigated. Under normality a point crosses a 3s limit by chance 0.27 % of the time, once in about 370 (background).

Two variables: the rectangle and the ellipse

Watch two correlated variables with one chart each and you get the rectangle of Fig. 8: a point is "in control" when it is inside both pairs of limits. "Multivariate Control Charts - 1" (p. 1124) says why that is not enough: bivariate charts are "based on bivariate Normal assumptions", and "component-wise limits lead to Type I, II errors", because the region of expected points is an ellipse tilted along the correlation (p. 1125).

missed false alarm missed X Y
Fig. 8. The "Bivariate Control Chart" of p. 1125, redrawn. Dashed rectangle: the separate control limits of X and Y; ellipse: the limit of the bivariate Normal. Crosses lie inside the rectangle but outside the ellipse: in control for each variable, out of control for the pair. Squares lie at the tips of the ellipse, beyond one limit: out of control for one variable, normal for the pair. On the slide the crosses are red dots and the squares blue ones.

Read the disagreements as errors of the rectangle, with "in control" as the null hypothesis. A point inside the rectangle but outside the ellipse is fine for each variable alone but implausible for the pair, such as a high X with a low Y when the two always rise together: the rectangle misses the alarm, a Type II error. A point at a tip of the ellipse, beyond one limit, is unusual for one variable but exactly what the correlation predicts: the rectangle raises a false alarm, a Type I error.

The ellipse is the set of points at the same Mahalanobis distance from the centre, the distance that measures in units of the covariance:

\[ d^2(\vb{x}) = (\vb{x} - \vb{\mu})\T\, \Sigma^{-1}\, (\vb{x} - \vb{\mu}) \]
\(\vb{x}\)
the point: one value per variable
\(\vb{\mu}\)
the centre of the data
\(\Sigma\)
the covariance matrix

Hence the second idea of p. 1124, "Depth based control charts (nonparametric)": "map n-dimensional data to one dimension using depth e.g. Mahalanobis", "Build control charts for depth", "Compare against benchmark using depth e.g. Q-Q plots of depth of each data set". However many attributes a record has, its depth (how far inside the cloud it lies) is one number for an ordinary chart; if new data resemble the benchmark, the Q-Q plot of their depths follows the diagonal.

For signals, p. 1126 adds "Multiscale process control with wavelets": it "Detects abnormalities at multiple scales as large wavelet coefficients", is "Useful for data with heteroscedasticity" (a variance that changes over time) and was "Applied in chemical process control".

Models and baselines

"Model Fitting and Outliers" (p. 1127): "Models summarize general trends in data", "more complex than simple aggregates", like regressions that "focus on attribute relationships"; "Data points that do not conform to well fitting models are potential outliers" — potential, since the model may be wrong. Hence "Goodness of fit tests (DQ for analysis/mining)": "check suitableness of model to data", "verify validity of assumptions", "data rich enough to answer analysis/business question?". The residual analysis of regression, turned on the data.

"Set Comparison and Outlier Detection" (p. 1128) works on whole data sets: the "“Model” consists of partition based summaries" (counts, quantiles, histograms per day or region), and you "Perform nonparametric statistical tests for a rapid section-wise comparison of two or more massive data sets"; "If there exists a baseline “good’’ data set, this technique can detect potentially corrupt sections in the test data set". A control chart for files, rapid because summaries are small.

Every method of this lesson, from the boxplot of the ages to the baseline comparison, does the same two things: it states what is expected, and it measures the departure.

Exam-style questions

Theory questions in the form of the written exam: open answers of a few sentences, and closed questions, multiple choice or true/false, where a wrong answer may carry a penalty. The past papers cover only the practical part and no sample theory questions are published, so these questions follow the slides, and the model answers use their wording.

True or false: in the terminology of the lecture, data munging denotes well-specified, lossless transformations of a data set.

  • True The lecture says the opposite: munging consists of "Potentially lossy" transformations and of "Vague" steps that are "not yet completely clear".
  • False Munging is defined as "Potentially lossy transformations applied to a piece of data or a file" and "Vague data transformation steps that are not yet completely clear", e.g. removing punctuation or HTML tags, data parsing, filtering and transformation.
Show model answer

False. Data munging is defined as potentially lossy transformations applied to a piece of data or a file, and as vague transformation steps that are not yet completely clear, for example removing punctuation or HTML tags, data parsing, filtering and transformation.

Two words carry the point: "lossy" and "vague". With a possible penalty for a wrong answer, answer only if you remember both.

A common way to handle missing values is to discard every record that contains one. Explain why the lecture warns against this policy. Support your answer with a computation: a table has 10 attributes, and each attribute is missing in 5 % of the records, independently of the others.

Show model answer

A record survives only if all of its attributes are present. With independent holes this happens with probability \((1 - 0.05)^{10} = 0.95^{10} \approx 0.60\), so about 40 % of the records would be discarded although only 5 % of each attribute is missing. The lecture reports that in federated data between 30 % and 70 % of the data points have at least one missing attribute, so ignoring them causes data wastage. Moreover, the remaining data is seriously biased: the complete records are representative only if values are missing completely at random, while in practice the holes often depend on the source or on the values themselves. The consequence is a lack of confidence in the results. Finally, the pattern of the missing data is itself useful, since it unearths data integrity issues. The alternative is imputation, keeping in mind that imputed values are useful in aggregates but cannot be trusted individually.

A complete answer names the slide's three consequences — wastage, bias, lack of confidence — and shows why 5 % becomes 40 %. Independence is part of the computation: state it.

Describe the techniques for imputing missing values presented in the lecture, in increasing order of sophistication, with the assumption each one makes. What does the lecture say about how far imputed values can be trusted?

Show model answer

1. Standalone imputation fills each hole with a point estimate of its attribute, such as the mean or the median; it assumes that the missing values are distributed like the non-missing ones, ignores the relationships between attributes and introduces bias, but it is convenient and easy to implement.

2. Better imputation uses the attribute relationships and assumes a monotone pattern: all prior attributes are populated. The regression method (parametric) sweeps left to right with linear regressions, X3 = a + b·X2 + c·X1, then X4 = d + e·X3 + f·X2 + g·X1, where a missing X3 is estimated from the first equation. The propensity score method (nonparametric) estimates the probability that Xj is missing from X1 … X(j−1) by logistic regression, groups the records by this score and fills the missing Xj within each group from the known ones with the approximate Bayesian bootstrap.

3. For an arbitrary missing pattern, Markov Chain Monte Carlo assumes multivariate Normal data with parameter Θ and alternates simulating the missing values given Θ and re-computing Θ from the filled-in data until stable; it is expensive and mostly used to induce monotonicity.

Imputed values are useful in aggregates but cannot be trusted individually.

What makes the answer complete is the order of the methods and the assumption of each. Monotonicity is easy to name and forget to explain: say what it means, "all prior attributes are populated".

Which of the following is the lecture's example of truncated data?

  • Call durations above 20 are recorded as 20. That is the lecture's example of censored data: the record stays, and its value is bounded but not precise.
  • Days 11, 12 and 16 are missing from a chart of visitors per day because of system failures. Those are random missing values, "System failures" and "Complete miss", not the effect of a bound.
  • Customers with less than 2 minutes of calling per month are not in the data. Truncated: "Data point dropped if it exceeds or falls below a certain bound". The records below the bound are gone.
  • A spike of accounts on one value because timestamps were reset to defaults. The lecture reads such spikes as censored time intervals caused by default timestamps; truncation shows as a dip, not a spike.
Show model answer

Customers with less than 2 minutes of calling per month are not in the data. Truncated data: a data point is dropped if it exceeds or falls below a certain bound. Censored data keeps the record but bounds its value, e.g. call durations above 20 recorded as 20.

Censored against truncated is the classic confusion. Capped, or thrown out.

Define an outlier as the lecture does. Should outliers be removed before an analysis? List the families of approaches the lecture gives for detecting outliers.

Show model answer

An outlier is a departure from the expected, so every detection approach is a way of defining what is expected. In the lecture's example, 3, 4, 7, 4, 8, 3, 9, 5, 7, 6, 92, the value 92 is suspicious. Outliers should not be removed automatically: they are potentially legitimate; often they are data or model glitches; but they could also be a data miner's dream, such as highly profitable customers. Each must be investigated with knowledge of the meaning of the data. The approaches are: error bounds and tolerance limits (control charts); model-based approaches (regression depth, analysis of residuals); geometric approaches; distributional approaches; and time-series outliers.

A complete answer has the definition in the slide's words, the three possible natures of an outlier and the five approaches. A sentence on why a plain 3-sigma rule can miss an outlier — the outlier inflates the standard deviation that judges it — shows understanding beyond the list.

Two positively correlated variables are monitored with a separate control chart each (component-wise limits). A point lies inside both univariate control bands but outside the ellipse of the bivariate Normal distribution. For the component-wise charts this point is:

  • a Type II error (a missed alarm) The point is out of control jointly, but each univariate chart accepts it: the alarm is missed.
  • a Type I error (a false alarm) A Type I error is an alarm raised for a point that is in control; here the component-wise charts raise no alarm at all.
  • correctly in control Outside the ellipse, the pair of values contradicts the correlation: the point is out of control.
  • correctly out of control The component-wise charts do not flag it, so they cannot be "correctly" signalling it.
Show model answer

A Type II error: the point is accepted by both component-wise limits, but it is out of control for the bivariate distribution, so the alarm is missed. The points at the tips of the ellipse that cross a univariate limit are the opposite case, Type I errors (false alarms). This is why the lecture says that component-wise limits lead to Type I and II errors.

Picture the rectangle and the ellipse, and the answer reads off the picture.

A Shewhart control chart for kilogram calibrations prints its two control limits as "UCL = mean + 3s = −19.39 mg" and "LCL = mean − 3s = −19.57 mg". Compute s, in mg.

Show model answer

The two limits are 6s apart:

\[ s = \frac{-19.39 - (-19.57)}{6} \] \[ s = \frac{0.18}{6} = 0.03 \ \text{mg} \]

The mean is \((-19.39 - 19.57) / 2 = -19.48\) mg. The chart follows the main steps of a control chart: define the expected value and the departure (here the mean and 3s), compute the aggregate of each sample, plot the aggregates against the expected value and the error bounds, and declare "out of control" any point outside the bounds.

The only trap is the 6: the distance between the limits is twice 3s.

Check yourself

A temperature logger writes 0 °C whenever its sensor is offline. A histogram of one month of readings has a tall, narrow spike at exactly 0. What does the spike most likely show?

  • A cold spell: many readings close to freezing A cold spell spreads the readings over a range of values around 0; a spike on one exact value is a stored default.
  • Missing readings stored as a default value "Missing values and defaults are indistinguishable" inside the column; the spike in the histogram is how the hidden damage shows. Metadata on what the logger writes when offline would confirm it.
  • Truncation: readings below 0 were dropped Truncation removes records: it leaves a dip or a hole beyond the bound, not a spike on it.

A fitness app stores every workout longer than 3 hours as exactly 3 hours. Its workout durations are…

  • censored: the workouts are kept, but their durations are capped Bounded but not precise: for those workouts you know only "at least 3 hours", and the histogram shows a spike at 3 hours.
  • truncated: the long workouts are dropped Truncation would remove the long workouts from the data; here they are still there, with a capped value.
  • missing at random Nothing is missing, and the damage depends on the value itself: only the long workouts are affected.

You fill the 30 % of missing cells in the column income, which went missing at random, with the mean of the observed incomes. Which statements are true? Select all that apply.

  • The mean of the filled column equals the mean of the observed incomes Every filled value is that mean, so the average does not move.
  • The spread of the column shrinks 30 % of the values now sit exactly at the centre; the variance drops to about 70 % of its former value.
  • Each filled cell is close to the real income of that person Individually, a filled value is a guess that ignores everything else known about the person: imputed values "can’t be trusted individually".
  • The correlation between income and age gets weaker The filled records have the same income whatever their age, which flattens any relationship there was; the widget showed the correlation falling as more bills were filled with the mean.

Mean filling keeps the mean and damages everything else: the spread, the relationships, and every individual value.

To the slide's eleven numbers you add a second 92. With the threshold \(k = 3\), what happens to the classic z-score of each 92?

  • It rises above 3.006: two extreme values make the tail heavier The opposite: the second 92 inflates the standard deviation even more.
  • It stays at 3.006, since each 92 is as far from the rest as before The mean and the standard deviation both change: the mean becomes 20 and \(s\) becomes 33.69.
  • It falls to 2.137, and neither 92 is flagged Masking: two outliers inflate the yardstick that judges them. The robust z of each 92 is 23.1, far above any threshold.

Three small tables with the attributes X1, X2, X3; a dot is a missing value, and rows are separated by "/". Which pattern is monotone for a sweep in the order X1, X2, X3?

  • 1.0 . 3.5 / 1.1 18 4.0 / 0.9 15 2.2 The first row has a hole in X2 but a value in X3: in this order a hole followed by a value is not monotone. (Swapping the last two columns would make it monotone.)
  • 1.0 20 3.5 / 1.1 18 . / 0.9 . . Once a row has a hole, every attribute to its right is a hole too: all the prior attributes of every hole are populated.
  • . 20 3.5 / 1.1 18 4.0 / 0.9 15 . The first row misses X1 while X2 and X3 are present, so the sweep cannot predict X2 from a full X1.

Two positively correlated variables are watched with one control chart each. A point lies at the upper-right tip of the bivariate ellipse, just beyond the upper limit of X, and the component-wise charts call it out of control. That verdict is…

  • correct, because the point is beyond a control limit It is beyond the limit of X alone, but a high X together with a high Y is exactly what the correlation predicts.
  • a Type II error, a missed alarm A Type II error is the opposite case: no alarm for a point that is out of control.
  • a Type I error, a false alarm Jointly the point is in control, inside the ellipse; the component-wise rule raised an alarm anyway.

A hospital table has an empty "last mammogram" cell for every male patient. What should you do with these cells?

  • Impute them with the mean date of the female patients That invents a mammogram for men. Imputation is for values that exist but were not recorded.
  • Drop the male patients, since their records are incomplete Every patient has some block that does not apply, so this policy would empty the table.
  • Leave them empty: the attribute does not apply "Partial data by nature", "Remember to leave empty slots": the empty cell says "not applicable".

Key take-aways

What to watch and read