Definition
An outlier is an observation that lies far from the bulk of the data. Outlier handling is the procedure, declared before the analysis, that decides whether each such observation is a valid measurement, to be kept, or the product of a measurement fault, to be repaired or excluded, and how valid extreme values enter the summary. The decision must rest on evidence about how the value was produced, never on its size alone: an extreme value is often the most important real behavior in the data, such as a stall.
The idea
Nine timings of an operation read, in milliseconds: 10, 11, 11, 12, 12, 12, 13, 14 and 48. The 48 stands out. It might be a real stall: the processor was interrupted, a lock was held by another task, or the memory allocator had to reorganize its free space. It might also be a broken measurement: the two timestamps came from different clocks, a counter wrapped around, or a record was garbled. The distance of 48 from the other values cannot tell these apart. Only evidence about how the 48 was produced can.
A doctor who receives one very high blood-test result is a fair picture. The doctor does not discard the result because it is high. The doctor checks whether the sample was mishandled or mislabeled. If it was, the result is set aside for that reason; if not, the high value is the finding. The picture stops being accurate in one respect. The doctor can usually take a new sample, whereas a stall in a measurement run often cannot be reproduced, so the evidence about how each value was produced must be recorded at the time of measurement.
How it works
Declare the validity checks before the data are examined, as part of the analysis plan §13.17; a check declared in advance is a prospective exclusion rule §13.15. Each check concerns the measurement process, not the size of the value. Typical checks: the record’s framing (the markers that delimit it) and checksum §4.32 are intact; sequence numbers have no gaps or repeats; both timestamps come from the same clock and were converted with the same rate; counter wraparound §6.21, the return of a fixed-width counter to zero after its largest value, was handled; the value is physically possible, for example not negative; the instrument reported no error; and no independently logged event that is known to disturb the measurement, such as a debugger being attached, overlapped it.
Screen for extreme values with a rule that only points to where to look. A common robust rule flags values more than 3 scaled MADs from the median §11.13, the middle value. The MAD (median absolute deviation) is the median of the distances of the values from their median. Scaling multiplies it by 1.4826, so that for data from a normal (bell-shaped) distribution the scaled MAD estimates the standard deviation §11.14, the usual measure of spread. A flag starts an investigation; it is not a verdict.
Investigate each flagged value against the declared checks. A value that fails a check is a measurement fault: repair it from the raw data §13.16 if possible, otherwise exclude it, and record the reason. A value that passes every check is valid and stays.
Choose the summary for the question, not for the outliers. The mean includes the full cost of stalls. The median describes a typical operation. A high percentile §11.16, the value below which a given high percentage of the observations fall, describes the slow tail. A robust summary such as the median limits the influence of extreme values without pretending that they did not happen. A trimmed mean, which drops a fixed fraction of the smallest and largest values before averaging, is acceptable when it is declared in advance and reported under its own name.
Report the counts and the reasons: how many values were flagged, repaired and excluded, under which check, and the main result with and without the excluded values whenever a decision involved judgment.
Worked example
Screening. The median of the nine timings 10, 11, 11, 12, 12, 12, 13, 14, 48 is the fifth value, 12. The distances from 12 are 2, 1, 1, 0, 0, 0, 1, 2 and 36; sorted, they are 0, 0, 0, 1, 1, 1, 2, 2, 36, whose median is 1. So the MAD is 1 millisecond and the scaled MAD is 1.4826 milliseconds. Three scaled MADs are milliseconds, so values below or above milliseconds are flagged. Only the 48 is flagged.
What the decision changes. With the 48, the sum is 143 and the mean is milliseconds. Without it, the sum is 95 and the mean is milliseconds. The median is 12 with the 48 and without it. The mean moves by about 4 milliseconds; the median does not move.
Two investigations, two answers. In the first, a log written independently by the operating system shows that a background task erased a page of flash memory §6.6 during that measurement, and on this hypothetical device an erase holds up the processor. The 48 is a real cost that users of the device will see. It stays, and 15.89 milliseconds is the honest mean. In the second, the record’s sequence number repeats that of the previous record and its start timestamp comes from a different clock: the record was garbled in transfer. The 48 is excluded under the declared framing check, and the reason is recorded.
Repair instead of deletion. A 16-bit counter that advances once per microsecond holds values and wraps around every 65,536 microseconds. A start reading of 65,000 and an end reading of 1,000 give a naive difference of microseconds, which is impossible. Subtracting modulo 65,536, which here means adding 65,536 to the negative difference, gives microseconds, the true elapsed time provided that less than one full wrap period passed. The negative value was evidence of a fault in the analysis, and the raw readings allowed the fault to be corrected instead of the value deleted.
Stated precisely
Let be the true outcome of a trial, and let be its validity flag: if the record passes every declared check. A sound exclusion rule computes only from evidence about the measurement process. The values that remain then describe the distribution of among trials with valid records. That distribution equals the distribution of over all trials when a fault is as likely to strike a slow trial as a fast one, that is, when is independent of . If faults strike slow trials more often, exclusion creates missing data §11.29 that depend on the outcome, and the missing data and attrition entry applies.
A rule based on size is different. Keeping only values with for a threshold replaces the mean , where denotes the expected value (the probability-weighted average), by the conditional mean , the mean among values that do not exceed . The conditional mean is never larger than , and it is smaller whenever values above occur with positive probability. In the example, milliseconds turns a mean of 15.89 into 11.875 milliseconds.
The screening rule flags a value when , where is the median of the values and is the median of the distances . The constant 1.4826 is approximately , and 0.6745 is the 75th percentile of the standard normal distribution, the normal distribution with mean 0 and standard deviation 1. For a normal distribution the scaled MAD therefore equals the standard deviation. The rule assumes that the bulk of the data is roughly symmetric.
Limits and common mistakes
Removing real extreme values erases the risk being studied. In work on latency and reliability, the rare slow case is often the reason for the measurement.
Keeping a corrupted value is also wrong. Neither automatic deletion nor automatic retention is a policy; evidence about the process decides.
Screening rules assume a symmetric bulk. Latency distributions §11.36 usually have a long tail on the slow side, so a rule built for symmetric data flags many valid slow values. A flag is not evidence of invalidity.
A rule based on the mean and the standard deviation, such as “more than 3 standard deviations from the mean”, can hide outliers: a few large values inflate the standard deviation so much that none of them is flagged. This effect is called masking. Rules based on the median resist it.
Removing outliers repeatedly, recomputing the rule after each removal, keeps shrinking the spread and eventually removes valid data.
The same rule must apply to every version compared, and running a trial again to replace an outlier is exclusion under another name.
A physically impossible value, such as a negative duration, is evidence of a fault, but the same fault may have distorted other values that look normal. A clock mistake that makes one interval negative may make others too long. Repair the method, not only the visible symptom.
Questions answered
What independent evidence marks a value as invalid rather than merely inconvenient?
A value is invalid only when evidence about how it was produced, gathered and judged independently of whether the value helps or hurts the conclusion, shows that the measurement process failed. Such evidence includes a record whose framing, checksum or sequence number is broken; timestamps taken from two different clocks, or converted with the wrong rate; a counter that wrapped around without being handled; a physically impossible value, such as a negative duration; an error reported by the instrument; and an independently logged event that is known to corrupt the measurement, such as a debugger being attached.
Size alone is not such evidence. A value far from the others may be the real stall that the measurement exists to find, and removing it changes the quantity being estimated: dropping a 48-millisecond value from nine timings lowers the mean from about 15.89 to 11.875 milliseconds without showing that anything was wrong. Independent means that the same evidence would have led to the same decision if the value had supported the preferred conclusion. Declare the checks before the analysis, keep every excluded value with its reason, repair values from the raw data where possible, and show the result with and without any exclusion that involved judgment.
Related entries: Sample mean (§11.12), Median (§11.13), Censoring (§11.28), Sensitivity analysis (§11.46), Counter wraparound (§6.21), Prospective exclusion rule (§13.15).