Tutorials › Exam PA - Predictive Analytics › Robust Outlier Screening with Median and MAD

Exam PA · Missingness, Outliers, and Factor Levels · Tutorial 178 of 966

Robust Outlier Screening with Median and MAD

Use median-based scores to identify unusual numeric observations, compare their flags with IQR fences, and understand the limits of both screens.

Intermediate 12 min read

What You'll Learn

  • Calculate the median, raw MAD, and modified MAD score for a numeric sample.
  • Explain why the common scaling constant makes MAD comparable to standard deviation under a normal model.
  • Apply a conventional modified-score cutoff without treating it as a proof that a value is erroneous.
  • Compare MAD-based flags with IQR fences using type 7 quartiles.
  • Describe how skewness, contamination, and a zero MAD affect screening.

Why Use the Median and MAD?

A few unusually large or small values can pull the mean and standard deviation toward themselves. The median and median absolute deviation (MAD) are less sensitive to such contamination, making them useful tools for screening a numeric variable. A robust screen can help identify observations for review, but a flag is not a conclusion: an unusual value may be valid, and a screen cannot determine its cause.

This tutorial treats each variable on its own, with missing values excluded from the calculation. The result depends on the observed sample and on the chosen screening convention. It does not, by itself, establish that an observation is an error or that a particular probability model is appropriate.

Definition: For observed numeric values \(x_1,\ldots,x_n\), let \(m\) be their sample median. The raw MAD is the median of the absolute deviations from that median: $$ \operatorname{MAD}_{\text{raw}}=\operatorname{median}\bigl(|x_1-m|,\ldots,|x_n-m|\bigr). $$ When the raw MAD is positive, the modified MAD score for an observation \(x_i\) is $$ M_i=\frac{0.6745(x_i-m)}{\operatorname{MAD}_{\text{raw}}}. $$ A common screening convention flags an observation when \(|M_i|>3.5\). This is a heuristic for identifying values to investigate, not a hypothesis test or a rule for deleting observations.

The numerator is signed, so a positive score indicates a value above the median and a negative score indicates one below it. The absolute value is used for a two-sided screen. A different cutoff can be chosen for a particular application, but it should be stated rather than treated as universal.

Why the Scaling Constant Appears

Raw MAD is measured in the same units as the data, but under a normal model it is smaller than the standard deviation. The factor 0.6745 makes the score approximately comparable to a conventional standardized deviation when the data are normally distributed.

To justify this interpretation, suppose \(X\sim N(\mu,\sigma^2)\). The population median is \(\mu\). The median absolute deviation from \(\mu\), denoted \(c\), satisfies \(P(|X-\mu|\le c)=0.5\). Standardizing by \(\sigma\) gives the following equation:

$$ P\left(\left|\frac{X-\mu}{\sigma}\right|\le \frac{c}{\sigma}\right)=0.5 \quad\Longrightarrow\quad 2\Phi\left(\frac{c}{\sigma}\right)-1=0.5 \quad\Longrightarrow\quad \frac{c}{\sigma}=\Phi^{-1}(0.75)\approx0.6745. $$

Thus the normal-model MAD is approximately \(0.6745\sigma\). Dividing a centered observation by MAD and multiplying by 0.6745 approximately recovers its standard-deviation scale. This derivation explains the scaling; it does not make the data normal, nor does it make the 3.5 cutoff a probability guarantee. In R, the function mad uses a normal-consistency constant by default; use constant = 1 when the raw MAD itself is needed.

Worked Example: Screening a Large Recorded Duration

In a hypothetical audit, a team records eight processing durations, in hours: 2, 2, 3, 3, 4, 4, 5, and 12. Calculate the median and raw MAD, score the value 12, and compare its MAD flag with the upper IQR fence. Use type 7 sample quartiles for the IQR calculation.

Method. First find the median, then find and order the absolute deviations. For the comparison, calculate type 7 quartiles and the conventional upper fence \(Q_3+1.5\operatorname{IQR}\). The MAD cutoff and IQR fence are screens, not diagnoses.

Median. There are eight values, so the median is the average of the fourth and fifth ordered values: \(m=(3+4)/2=3.5\).

Raw MAD. The absolute deviations from 3.5, in the original data order, are 1.5, 1.5, 0.5, 0.5, 0.5, 0.5, 1.5, and 8.5. In order they are 0.5, 0.5, 0.5, 0.5, 1.5, 1.5, 1.5, and 8.5. Their median is the average of the fourth and fifth values: \(\operatorname{MAD}_{\text{raw}}=(0.5+1.5)/2=1.0\).

MAD score. The score for 12 is \(M=0.6745(12-3.5)/1.0=0.6745(8.5)=5.73325\). Since \(|5.73325|>3.5\), 12 is flagged by this convention.

IQR comparison. For type 7 quartiles with \(n=8\), the position is \(1+(n-1)p\). For \(Q_1\), the position is \(1+7(0.25)=2.75\), between the second value 2 and third value 3. Therefore \(Q_1=2+0.75(3-2)=2.75\). For \(Q_3\), the position is \(1+7(0.75)=6.25\), between the sixth value 4 and seventh value 5. Therefore \(Q_3=4+0.25(5-4)=4.25\). It follows that \(\operatorname{IQR}=4.25-2.75=1.5\), and the upper fence is \(4.25+1.5(1.5)=6.5\). Since \(12>6.5\), the IQR screen flags 12 as well.

Check and common mistake avoided. Both methods flag the same observation here, but they use different centers and measures of spread. When interpolating \(Q_3\), the fraction 0.25 is applied between 4 and 5; it gives 4.25, not a value obtained by interpolating between unrelated order statistics.

Comparing MAD Scores with IQR Fences

Both MAD scores and IQR fences use robust summaries: the median or quartiles rather than the mean and standard deviation. Their definitions differ, so they need not flag exactly the same observations. For the IQR screen, an observation is outside the conventional fences if it is below \(Q_1-1.5\operatorname{IQR}\) or above \(Q_3+1.5\operatorname{IQR}\). Quartiles depend on the quantile convention; comparisons should use the stated convention consistently.

A MAD screen measures distance from the median in units of a robust spread estimate. The 3.5 threshold is applied to the absolute modified score. An IQR screen instead measures distance from a quartile in units of the interquartile range. Neither method is guaranteed to be more appropriate in every dataset. Agreement between them can be informative, but disagreement is a reason to inspect the summaries and the distribution rather than to choose whichever flag is preferred.

Worked Example: A Right-Skewed Hypothetical Severity Sample

Consider eight hypothetical payment amounts, in hundreds of dollars: 1, 2, 2, 3, 4, 5, 8, and 15. Calculate the MAD scores for 8 and 15 and compare the flags with the type 7 upper IQR fence.

Method. Use the sample median and raw MAD for the modified scores, then calculate the upper IQR fence separately. This comparison shows what each rule flags; it does not establish that an upper-tail value is invalid.

Median and MAD. The median is \(m=(3+4)/2=3.5\). The absolute deviations are 2.5, 1.5, 1.5, 0.5, 0.5, 1.5, 4.5, and 11.5. In order they are 0.5, 0.5, 1.5, 1.5, 1.5, 2.5, 4.5, and 11.5, so the raw MAD is \((1.5+1.5)/2=1.5\).

Scores. For 8, \(M=0.6745(8-3.5)/1.5=3.03525/1.5=2.0235\), so 8 is not flagged at 3.5. For 15, \(M=0.6745(15-3.5)/1.5=7.75675/1.5\approx5.1712\), so 15 is flagged.

IQR fence. The type 7 \(Q_1\) position is 2.75, between 2 and 2, giving \(Q_1=2\). The \(Q_3\) position is 6.25, between 5 and 8, giving \(Q_3=5+0.25(8-5)=5.75\). Thus \(\operatorname{IQR}=5.75-2=3.75\), and the upper fence is \(5.75+1.5(3.75)=11.375\). Since \(15>11.375\), the IQR screen also flags 15; 8 is below the fence.

Check and common mistake avoided. The scores and fence identify 15 as unusually far into this sample’s upper tail. A right-skewed population can naturally have a longer upper tail than a symmetric one, so a flag is not proof of an error. Do not interpret a normal-scaled MAD score as though the sample’s distribution had thereby been shown to be normal.

Robustness and Its Limits

The median and MAD resist the influence of a small number of extreme observations because they depend on ranks and middle values. They are not unaffected by every change: adding observations can shift the median or the middle absolute deviations, particularly in small samples. A zero raw MAD also requires special care. If most values are identical, the median absolute deviation may be zero even though some observations differ; the modified score is then undefined because it divides by zero.

The following example contrasts the movement of the mean with the movement of median-based summaries after one extreme value is added. It also checks the IQR screen, which is robust in the sense that a single extreme observation generally has limited influence on central quartiles, but is not identical to MAD.

Worked Example: One Extreme Value Added to a Small Sample

A hypothetical data-quality review begins with seven amounts, in dollars: 10, 11, 11, 12, 12, 13, and 14. A value of 1,000 is subsequently added. Compare the mean, median, raw MAD, and type 7 upper IQR fence before and after it is added; then calculate the modified score of 1,000 in the expanded sample.

Method. Calculate each summary directly in both samples. This makes the effect of contamination explicit rather than assuming that a robust statistic cannot move.

Original sample. The sum is \(10+11+11+12+12+13+14=83\), so the mean is \(83/7\approx11.8571\). The median is 12. The absolute deviations from 12 are 2, 1, 1, 0, 0, 1, and 2; in order they are 0, 0, 1, 1, 1, 2, 2. The raw MAD is 1.

For type 7 quartiles with \(n=7\), the \(Q_1\) position is \(1+6(0.25)=2.5\); the second and third values are both 11, so \(Q_1=11\). The \(Q_3\) position is \(1+6(0.75)=5.5\); the fifth and sixth values are 12 and 13, so \(Q_3=12+0.5(13-12)=12.5\). Thus \(\operatorname{IQR}=1.5\), and the upper fence is \(12.5+1.5(1.5)=14.75\).

Expanded sample. The new sum is \(83+1000=1083\), and the new mean is \(1083/8=135.375\). The median is the average of the fourth and fifth values, \((12+12)/2=12\). The absolute deviations from 12 are 2, 1, 1, 0, 0, 1, 2, and 988; the ordered list is 0, 0, 1, 1, 1, 2, 2, 988. The expanded raw MAD is still 1.

The type 7 \(Q_1\) position is \(1+7(0.25)=2.75\), between two values of 11, so \(Q_1=11\). The \(Q_3\) position is \(1+7(0.75)=6.25\), between 13 and 14, so \(Q_3=13+0.25(14-13)=13.25\). Hence \(\operatorname{IQR}=13.25-11=2.25\), and the expanded upper fence is \(13.25+1.5(2.25)=16.625\).

Score and comparison. The modified score of 1,000 is \(0.6745(1000-12)/1=0.6745(988)=666.406\), which exceeds 3.5. The value is also above the upper IQR fence of 16.625. The median and MAD stayed fixed in this particular example, while the mean rose from about 11.8571 to 135.375. This result illustrates robustness, not immunity: the quartiles also moved, and a different sample could produce different changes.

Check and common mistake avoided. Use the expanded sample’s median and MAD when scoring 1,000. Do not use the original sample’s summaries automatically after the data have changed, even when they happen to have the same values here.

Practical Interpretation and Common Traps

For a numeric variable in an exploratory analysis, a defensible MAD workflow is to state which observations were included, calculate the median and raw MAD, calculate modified scores only when the raw MAD is positive, and report the chosen cutoff. In R, median and mad can calculate the relevant summaries; to reproduce the raw MAD explicitly, take the median of the absolute differences from the sample median. Confirm whether the function’s scaling constant is enabled before interpreting its output.

Two arithmetic details deserve special attention. First, apply the scaling factor to the centered observation and then divide by the raw MAD. For example, if \(m=3.5\), raw MAD \(=1.5\), and \(x=10\), then \(0.6745(10-3.5)/1.5=4.38425/1.5\approx2.923\). For \(x=18\), \(0.6745(18-3.5)/1.5=9.78025/1.5\approx6.520\). The first score is below 3.5 and the second is above it. Rounding the first incorrectly to 2.922 or miscalculating the second can change the interpretation of a borderline result.

  • Do not equate a flag with a bad record. It means the value is unusual under the selected screen, not that it should be deleted.
  • Do not assume symmetry. A normal-consistency scale does not adjust automatically for skewness or heavy tails.
  • Do not ignore zero MAD. The modified score is undefined when raw MAD is zero; report the issue and use a separately specified alternative screen if one is appropriate.
  • Do not mix quartile conventions. Type 7 interpolation should be used consistently when comparing with the stated IQR fences.
Key takeaway: The median and MAD provide a robust way to screen numeric observations, and the modified score gives a convenient common scale under a normal reference model. Treat the cutoff as a review rule, compare it thoughtfully with IQR fences, and interpret flags in light of the sample’s distribution rather than as automatic evidence of error.

Check Your Understanding

For each problem, calculate the requested summaries before checking the final answer.

  1. A hypothetical sensor records 1, 2, 2, 3, 4, 4, 5, and 20. Find the median and raw MAD, then determine whether 20 is flagged by the \(|M|>3.5\) convention. (Answer: Median \(=3.5\), raw MAD \(=1.5\), \(M_{20}\approx7.4195\); 20 is flagged.)
  2. For the hypothetical observations 3, 4, 4, 5, 6, 7, and 8, find the raw MAD and modified score of 8. Is 8 flagged at 3.5? (Answer: Median \(=5\), raw MAD \(=1\), \(M_8=2.0235\); 8 is not flagged.)
  3. A sample consists of 5, 5, 5, 5, 5, 5, and 9. Explain why the modified MAD score for 9 cannot be calculated, and give the type 7 upper IQR fence. (Answer: The median is 5 and raw MAD is 0, so the modified score is undefined; \(Q_1=Q_3=5\), so the upper fence is 5.)
  4. For hypothetical values 2, 3, 3, 4, 5, 6, 7, and 16, calculate the median, raw MAD, modified score for 16, and type 7 upper IQR fence. State whether each screen flags 16. (Answer: Median \(=4.5\), raw MAD \(=1.5\), \(M_{16}\approx5.1712\), so MAD flags it; \(Q_1=3\), \(Q_3=6.25\), \(\operatorname{IQR}=3.25\), upper fence \(=11.125\), so IQR flags it.)
Clinical Biostats