{"id":6796,"date":"2026-08-18T14:24:10","date_gmt":"2026-08-18T19:24:10","guid":{"rendered":"https:\/\/ykim.synology.me\/wordpress\/?p=6796"},"modified":"2026-11-26T22:37:39","modified_gmt":"2026-11-27T04:37:39","slug":"hampel-identifier-flagging-outliers-with-the-median-and-the-mad","status":"publish","type":"post","link":"https:\/\/ykim.synology.me\/wordpress\/hampel-identifier-flagging-outliers-with-the-median-and-the-mad-6796\/","title":{"rendered":"Hampel Identifier \u2014 Flagging Outliers with the Median and the MAD"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/yBarn1\/Images\/main\/parks\/hillside-plaza-stone-columns.jpg\" alt=\"\" style=\"width:auto;height:500px\"\/><\/figure>\n\n\n<p><div class=\"github-readme-container markdown-body\"><div id=\"file\" class=\"md\" data-path=\"EDA\/Outlier\/Hampel\/hampel-identifier.md\"><article class=\"markdown-body entry-content container-lg\" itemprop=\"text\"><div class=\"markdown-heading\" dir=\"auto\"><h1 class=\"heading-element\" dir=\"auto\">Hampel Identifier \u2014 Flagging Outliers with the Median and the MAD<\/h1><a id=\"user-content-hampel-identifier--flagging-outliers-with-the-median-and-the-mad\" class=\"anchor\" aria-label=\"Permalink: Hampel Identifier \u2014 Flagging Outliers with the Median and the MAD\" href=\"#hampel-identifier--flagging-outliers-with-the-median-and-the-mad\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Version 41 | Created: 2026-08-17 | Updated: 2026-11-07 13:46 UTC<\/p>\n<ul dir=\"auto\">\n<li><a href=\"#1-scope\">1. Scope<\/a><\/li>\n<li><a href=\"#2-modified-z-score\">2. Modified z-score<\/a>\n<ul dir=\"auto\">\n<li><a href=\"#21-definition\">2.1. Definition<\/a><\/li>\n<li><a href=\"#22-consistency-constant\">2.2. Consistency Constant<\/a><\/li>\n<li><a href=\"#23-outlier-flag\">2.3. Outlier Flag<\/a><\/li>\n<li><a href=\"#24-retained-interval\">2.4. Retained Interval<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#3-robustness\">3. Robustness<\/a>\n<ul dir=\"auto\">\n<li><a href=\"#31-assumptions\">3.1. Assumptions<\/a><\/li>\n<li><a href=\"#32-contaminated-scale\">3.2. Contaminated Scale<\/a><\/li>\n<li><a href=\"#33-breakdown-point\">3.3. Breakdown Point<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#references\">References<\/a><\/li>\n<li><a href=\"#appendix-a-terminology\">Appendix A. Terminology<\/a><\/li>\n<li><a href=\"#appendix-b-reference-implementation\">Appendix B. Reference Implementation<\/a><\/li>\n<li><a href=\"#appendix-c-worked-example\">Appendix C. Worked Example<\/a>\n<ul dir=\"auto\">\n<li><a href=\"#c1-sample\">C.1. Sample<\/a><\/li>\n<li><a href=\"#c2-normality\">C.2. Normality<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#appendix-d-consistency-constant-of-the-mad\">Appendix D. Consistency Constant of the MAD<\/a>\n<ul dir=\"auto\">\n<li><a href=\"#d1-derivation\">D.1. Derivation<\/a><\/li>\n<li><a href=\"#d2-finite-samples\">D.2. Finite Samples<\/a><\/li>\n<li><a href=\"#d3-other-distributions\">D.3. Other Distributions<\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<blockquote>\n<p dir=\"auto\">A note on the modified z-score built from the median and the median absolute deviation,\norganized as the score and then the robustness that the score rests on.<\/p>\n<\/blockquote>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">1. Scope<\/h2><a id=\"user-content-1-scope\" class=\"anchor\" aria-label=\"Permalink: 1. Scope\" href=\"#1-scope\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">The classical way to call an observation extreme is to divide its deviation from the mean by\nthe standard deviation and compare the result against a threshold. Both the centre and the scale\nin that ratio are computed from the same sample the observation belongs to, so an outlier\ninflates the quantity it is being measured against.<\/p>\n<p dir=\"auto\">The Hampel identifier replaces the pair with the median and the median absolute deviation, the\nMAD. A minority of contaminating observations cannot move either, so the scale keeps describing\nthe bulk of the sample rather than the observation under test.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">2. Modified z-score<\/h2><a id=\"user-content-2-modified-z-score\" class=\"anchor\" aria-label=\"Permalink: 2. Modified z-score\" href=\"#2-modified-z-score\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">2.1. Definition<\/h3><a id=\"user-content-21-definition\" class=\"anchor\" aria-label=\"Permalink: 2.1. Definition\" href=\"#21-definition\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\"><math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$$\\mathrm{MAD} = \\mathrm{median}\\left( \\left| x_1 - \\tilde{x} \\right|, \\ldots, \\left| x_n - \\tilde{x} \\right| \\right)$$<\/math-renderer><\/p>\n<p dir=\"auto\"><math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$$M_i = \\frac{x_i - \\tilde{x}}{\\mathrm{MAD} \/ \\Phi^{-1}(0.75)}$$<\/math-renderer><\/p>\n<ul dir=\"auto\">\n<li>\n<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$x_1, \\ldots, x_n$<\/math-renderer> \u2014 the sample, and <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$x_i$<\/math-renderer> its <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$i$<\/math-renderer>-th observation.<\/li>\n<li>\n<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\tilde{x}$<\/math-renderer> (x tilde) \u2014 the median of the sample, which the deviations are taken from and which the score is centred on.<\/li>\n<li>\n<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\mathrm{MAD}$<\/math-renderer> \u2014 the median of those absolute deviations, which is the raw robust scale before any rescaling.<\/li>\n<li>\n<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\Phi^{-1}(0.75) = 0.674490$<\/math-renderer> \u2014 the third quartile of the standard normal distribution, which the MAD is divided by. It is the subject of section 2.2.<\/li>\n<li>\n<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$M_i$<\/math-renderer> \u2014 the modified z-score of observation <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$i$<\/math-renderer>.<\/li>\n<\/ul>\n<p dir=\"auto\">The denominator is the robust scale. The score <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$M_i$<\/math-renderer> is an ordinary z-score with the median put in\nplace of the mean and the robust scale in place of the standard deviation, which is why it is\ncalled the modified z-score.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">2.2. Consistency Constant<\/h3><a id=\"user-content-22-consistency-constant\" class=\"anchor\" aria-label=\"Permalink: 2.2. Consistency Constant\" href=\"#22-consistency-constant\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">For a normal sample the MAD converges to <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\Phi^{-1}(0.75) \\sigma$<\/math-renderer> rather than to <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\sigma$<\/math-renderer>, so\nthe raw MAD understates the spread by about a third. Dividing by <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\Phi^{-1}(0.75)$<\/math-renderer>, equivalently\nmultiplying by 1.482602, removes that bias in the limit and makes the modified score comparable\nto a classical z-score. Without it the score would sit on a scale of its own and no threshold\ncould be carried over from the classical rule. A short sample still lands below the limit, which\nis the second thing the appendix works out.\n<a href=\"#appendix-d-consistency-constant-of-the-mad\">Appendix D. Consistency Constant of the MAD<\/a> derives\nthe number and shows what a short sample does to it.<\/p>\n<p dir=\"auto\">The constant is the only place normality enters the method, and it is a calibration rather than\nan assumption: changing it rescales every score by the same factor and reorders nothing. Its\npurpose is to let the threshold of section 2.3 be read as a false-positive rate.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">2.3. Outlier Flag<\/h3><a id=\"user-content-23-outlier-flag\" class=\"anchor\" aria-label=\"Permalink: 2.3. Outlier Flag\" href=\"#23-outlier-flag\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">An observation is flagged as an outlier when its modified z-score exceeds the threshold <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$k$<\/math-renderer> in\nabsolute value.<\/p>\n<p dir=\"auto\"><math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$$\\left| M_i \\right| \\gt k$$<\/math-renderer><\/p>\n<p dir=\"auto\">The threshold <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$k$<\/math-renderer> is 3.5 by convention. The value comes from Iglewicz and Hoaglin (1993), who set\nit high enough that a sample which really is normal almost never produces a flag. On such a\nsample the expected number of false flags in fifteen observations is 0.007. A threshold of 3.0\nis also used and is roughly six times looser. Fix the threshold before looking at the data, and\nreport it, because a verdict that changes between 3.0 and 3.5 rests on the choice rather than on\nthe sample.<\/p>\n<p dir=\"auto\">Every observation is scored once, against one centre and one scale. There is no iteration and\nnothing is removed part-way, because the estimates the scores are built on were never\ncontaminated in the first place.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">2.4. Retained Interval<\/h3><a id=\"user-content-24-retained-interval\" class=\"anchor\" aria-label=\"Permalink: 2.4. Retained Interval\" href=\"#24-retained-interval\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">The same rule can be written in the units of the data rather than in scales. Multiplying the\ninequality through by the robust scale turns it into an interval around the median.<\/p>\n<p dir=\"auto\"><math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$$\\tilde{x} - k \\cdot \\frac{\\mathrm{MAD}}{\\Phi^{-1}(0.75)} \\le x_i \\le \\tilde{x} + k \\cdot \\frac{\\mathrm{MAD}}{\\Phi^{-1}(0.75)}$$<\/math-renderer><\/p>\n<p dir=\"auto\">An observation inside that interval is retained and an observation outside it is flagged. The\ninterval is therefore where the rule draws its boundary on the measurement scale itself.<\/p>\n<p dir=\"auto\">The interval is not fixed by the method. The median and the scale are both computed from the\nsample, so two samples tested at the same threshold have different intervals.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">3. Robustness<\/h2><a id=\"user-content-3-robustness\" class=\"anchor\" aria-label=\"Permalink: 3. Robustness\" href=\"#3-robustness\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">3.1. Assumptions<\/h3><a id=\"user-content-31-assumptions\" class=\"anchor\" aria-label=\"Permalink: 3.1. Assumptions\" href=\"#31-assumptions\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">The sample is univariate. Contamination is a minority: fewer than half the observations are\noutliers.<\/p>\n<p dir=\"auto\">No value may be taken by more than half the sample. If one is, the MAD is 0, the score divides by\nzero, and it is undefined. This is a hard failure rather than a loss of accuracy, and an\nimplementation that returns zeros instead of raising an error reports a clean sample on data it\ncannot read. Reaching for a different robust estimator does not help: Sn and Qn have the same 50%\nbreakdown point and return 0 on exactly the same samples. A positive scale can only come from an\nestimator that does not rest on a median of the deviations, such as the interquartile range,\nwhich buys the scale by dropping to a 25% breakdown point.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">3.2. Contaminated Scale<\/h3><a id=\"user-content-32-contaminated-scale\" class=\"anchor\" aria-label=\"Permalink: 3.2. Contaminated Scale\" href=\"#32-contaminated-scale\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">A sample standard deviation is a mean of squared deviations, so a single distant observation\nenters it quadratically. Pushing that observation further out enlarges its own deviation and the\nstandard deviation together, so the ratio of the two grows far more slowly than the distance does.<\/p>\n<p dir=\"auto\">The median absolute deviation is a median of absolute deviations. Sending one observation off to\ninfinity moves the middle of that list by one position and no further.<\/p>\n<p dir=\"auto\">The same self-reference, an observation inflating the scale that it is measured against, caps the\nclassical score outright: in a sample of size <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$n$<\/math-renderer> no absolute z-score can exceed <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$(n-1)\/\\sqrt{n}$<\/math-renderer>,\nwhatever the data are, a bound due to Shiffler (1988). The modified score has no such ceiling,\nbecause its denominator stops responding to the observation in its numerator once that\nobservation is far enough out.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">3.3. Breakdown Point<\/h3><a id=\"user-content-33-breakdown-point\" class=\"anchor\" aria-label=\"Permalink: 3.3. Breakdown Point\" href=\"#33-breakdown-point\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">One corrupted observation is enough to break the mean and the standard deviation. Breaking the\nmedian or the MAD takes more than half the sample.<\/p>\n<p dir=\"auto\">An estimate breaks down when it stops describing the sample and describes the corrupted\nobservations instead. The calculation still returns a number. Setting one observation of the\nworked example to a billion takes the mean past 66 million while the median stays at 0.0232, and\na mean of 66 million says nothing about the fourteen observations that still sit near 0.02.<\/p>\n<p dir=\"auto\">The breakdown point is the fraction of the sample that has to be corrupted for that to happen.<\/p>\n<p dir=\"auto\"><strong>Table 1. Breakdown point of the two pairs<\/strong><\/p>\n<markdown-accessiblity-table><table>\n<thead>\n<tr>\n<th>Estimator<\/th>\n<th>Breakdown point<\/th>\n<th>What it takes to break it<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Mean and standard deviation<\/td>\n<td>0%<\/td>\n<td>One observation is enough, if it is moved far enough.<\/td>\n<\/tr>\n<tr>\n<td>Median and MAD<\/td>\n<td>50%<\/td>\n<td>Eight of the fifteen are needed. Seven leave the median at 0.0403, which is still one of the real observations.<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/markdown-accessiblity-table>\n<p dir=\"auto\">The breakdown point is the whole reason the method works. Section 2 is nothing more than the\narithmetic that puts the robust pair on a scale a threshold can be read against.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">References<\/h2><a id=\"user-content-references\" class=\"anchor\" aria-label=\"Permalink: References\" href=\"#references\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\"><a id=\"user-content-ref-1\"><\/a>\n[1] Hampel, F. R. (1974). <a href=\"https:\/\/doi.org\/10.1080\/01621459.1974.10482962\" rel=\"nofollow\">The Influence Curve and Its Role in Robust Estimation<\/a>. <em>Journal of the American Statistical Association<\/em>, 69(346), 383\u2013393.<br>\n<a id=\"user-content-ref-2\"><\/a>\n[2] Iglewicz, B., &amp; Hoaglin, D. C. (1993). <em>How to Detect and Handle Outliers<\/em>. The ASQC Basic References in Quality Control: Statistical Techniques, Vol. 16. ASQC Quality Press, Milwaukee. <a href=\"https:\/\/asq.org\/quality-press\" rel=\"nofollow\">https:\/\/asq.org\/quality-press<\/a>. ISBN 978-0-87389-247-6.<br>\n<a id=\"user-content-ref-3\"><\/a>\n[3] Shiffler, R. E. (1988). <a href=\"https:\/\/doi.org\/10.1080\/00031305.1988.10475530\" rel=\"nofollow\">Maximum Z Scores and Outliers<\/a>. <em>The American Statistician<\/em>, 42(1), 79\u201380.<br>\n<a id=\"user-content-ref-4\"><\/a>\n[4] Rousseeuw, P. J., &amp; Croux, C. (1993). <a href=\"https:\/\/doi.org\/10.1080\/01621459.1993.10476408\" rel=\"nofollow\">Alternatives to the Median Absolute Deviation<\/a>. <em>Journal of the American Statistical Association<\/em>, 88(424), 1273\u20131283.<br>\n<a id=\"user-content-ref-5\"><\/a>\n[5] Leys, C., Ley, C., Klein, O., Bernard, P., &amp; Licata, L. (2013). <a href=\"https:\/\/doi.org\/10.1016\/j.jesp.2013.03.013\" rel=\"nofollow\">Detecting outliers: Do not use standard deviation around the mean, use absolute deviation around the median<\/a>. <em>Journal of Experimental Social Psychology<\/em>, 49(4), 764\u2013766.<\/p>\n<hr>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">Appendix A. Terminology<\/h2><a id=\"user-content-appendix-a-terminology\" class=\"anchor\" aria-label=\"Permalink: Appendix A. Terminology\" href=\"#appendix-a-terminology\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<ul dir=\"auto\">\n<li>\n<strong>breakdown point<\/strong> \u2014 The fraction of a sample that has to be corrupted before a statistic becomes unusable. The mean has a breakdown point of 0%, because one corrupted observation is enough to take it anywhere. The median has 50%, because more than half the sample has to be corrupted before it leaves the uncontaminated data.<\/li>\n<li>\n<strong>consistency constant<\/strong> \u2014 A factor applied to a robust scale estimate so that it converges to the standard deviation under an assumed distribution.<\/li>\n<li>\n<strong>contamination<\/strong> \u2014 The fraction of a sample that does not come from the assumed distribution.<\/li>\n<li>\n<strong>cumulative distribution function<\/strong> \u2014 The function giving, for each value, the probability of falling at or below it. The standard normal one is written <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\Phi$<\/math-renderer>, and its inverse turns a probability back into a number of standard deviations.<\/li>\n<li>\n<strong>MAD<\/strong> \u2014 The abbreviation used throughout for the median absolute deviation.<\/li>\n<li>\n<strong>median absolute deviation (MAD)<\/strong> \u2014 The median of the absolute deviations of the observations from the sample median, used as a scale estimate that a minority of extreme observations cannot inflate. On a normal sample it converges to 0.674490 times the standard deviation rather than to the standard deviation itself, which is why section 2.2 divides it by that constant before using it as a scale.<\/li>\n<li>\n<strong>modified z-score<\/strong> \u2014 The deviation from the median divided by the rescaled MAD.<\/li>\n<li>\n<strong>Qn<\/strong> \u2014 A robust scale estimator of Rousseeuw and Croux (1993), taking an order statistic of the pairwise distances between observations. It shares the 50% breakdown point of the MAD and needs no centre to measure from, and it is far more efficient on a normal sample, at 82% against 37%.<\/li>\n<li>\n<strong>Sn<\/strong> \u2014 A robust scale estimator of Rousseeuw and Croux (1993), built from a median of medians of pairwise distances. It shares the 50% breakdown point of the MAD and assumes no symmetry, and it reaches 58% efficiency on a normal sample against the 37% of the MAD.<\/li>\n<li>\n<strong>z-score<\/strong> \u2014 The deviation from the mean divided by the sample standard deviation.<\/li>\n<\/ul>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">Appendix B. Reference Implementation<\/h2><a id=\"user-content-appendix-b-reference-implementation\" class=\"anchor\" aria-label=\"Permalink: Appendix B. Reference Implementation\" href=\"#appendix-b-reference-implementation\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">The block below is <code>hampel_identifier.py<\/code>, in the folder of this document. It is that file as\nwritten, without the module docstring and the <code>if __name__ == '__main__':<\/code> guard.<\/p>\n<p dir=\"auto\">The file holds the method of section 2 and nothing else. It scores a sample and reports the\ninterval; tabulating, printing and reading the scores are left to whatever calls it.<\/p>\n<div class=\"highlight highlight-source-python notranslate position-relative overflow-auto\" dir=\"auto\" data-snippet-clipboard-copy-content=\"# EDA\/Outlier\/Hampel\/hampel_identifier.py\n__author__ = 'yRocket'\n__version__ = &quot;0.9.1.2026.8.18&quot;  # Semantic Versioning: Major.Minor.Patch.Date(YYYY.M.D)\n\n# Everything this module offers. The names beginning with an underscore are internal.\n__all__ = [\n    'NORMAL_QUARTILE',\n    'DEFAULT_THRESHOLD',\n    'median_absolute_deviation',\n    'hampel_score',\n    'retained_interval',\n]\n\nimport numpy as np\nfrom scipy import stats\n\n# The MAD of a normal sample converges to this multiple of sigma, so dividing by it puts the\n# modified score on the same scale as a classical z-score. It is the third quartile of N(0, 1).\nNORMAL_QUARTILE = float(stats.norm.ppf(0.75))\n\n# The cut-off recommended by Iglewicz and Hoaglin for the modified z-score.\nDEFAULT_THRESHOLD = 3.5\n\n\ndef _as_sample(data: np.ndarray = None) -&gt; np.ndarray:\n    &quot;&quot;&quot;Return the sample as a 1-D float array, refusing input the identifier cannot read.&quot;&quot;&quot;\n    values = np.asarray(data, dtype=float)\n    if values.ndim != 1:\n        raise ValueError(f&quot;data must be 1-D, got shape {values.shape}.&quot;)\n    if values.size &lt; 3:\n        raise ValueError(f&quot;the identifier needs at least 3 observations to have a usable median, got {values.size}.&quot;)\n    if not np.all(np.isfinite(values)):\n        raise ValueError(f&quot;data carries {int((~np.isfinite(values)).sum())} non-finite values; &quot;\n                         f&quot;remove or impute them before scoring.&quot;)\n    return values\n\n\ndef median_absolute_deviation(data: np.ndarray = None) -&gt; float:\n    &quot;&quot;&quot;Median of the absolute deviations from the sample median.\n\n    Args:\n        data: the sample, shape (n,).\n\n    Returns:\n        The MAD, before any rescaling.\n    &quot;&quot;&quot;\n    values = np.asarray(data, dtype=float)\n    return float(np.median(np.abs(values - np.median(values))))\n\n\ndef _hampel_scale(data: np.ndarray = None, quartile: float = NORMAL_QUARTILE) -&gt; float:\n    &quot;&quot;&quot;Robust scale of the sample, which is the MAD divided by the consistency constant.\n\n    Args:\n        data: the sample, shape (n,).\n        quartile: the constant the MAD is divided by; the default makes the scale estimate the\n            standard deviation on a normal sample.\n\n    Returns:\n        The robust scale.\n    &quot;&quot;&quot;\n    values = _as_sample(data=data)\n    if quartile &lt;= 0.0:\n        raise ValueError(f&quot;quartile must be positive, got {quartile}.&quot;)\n    mad = median_absolute_deviation(data=values)\n    if mad == 0.0:\n        # More than half the sample sits on one value, so the MAD carries no scale at all.\n        # Returning zero here would make every score infinite or undefined further down.\n        centre = float(np.median(values))\n        repeated = int((values == centre).sum())\n        raise ValueError(f&quot;the MAD is 0 because {repeated} of {values.size} observations equal the median &quot;\n                         f&quot;{centre}; the robust scale is undefined. Every 50% breakdown estimator returns 0 &quot;\n                         f&quot;here, Sn and Qn included, so report that the sample cannot support the method or &quot;\n                         f&quot;take a scale that does not rest on a median of the deviations.&quot;)\n    return mad \/ quartile\n\n\ndef hampel_score(data: np.ndarray = None, quartile: float = NORMAL_QUARTILE) -&gt; np.ndarray:\n    &quot;&quot;&quot;Modified z-score of every observation, which is its distance from the median in robust scales.\n\n    No threshold is taken, because the score does not depend on one. A caller decides by comparing\n    the absolute score against a cut-off, 3.5 by convention.\n\n    Args:\n        data: the sample, shape (n,).\n        quartile: the constant the MAD is divided by, as in median_absolute_deviation.\n\n    Returns:\n        The modified z-scores, shape (n,).\n    &quot;&quot;&quot;\n    values = _as_sample(data=data)\n    return (values - np.median(values)) \/ _hampel_scale(data=values, quartile=quartile)\n\n\ndef retained_interval(data: np.ndarray = None, threshold: float = DEFAULT_THRESHOLD,\n                      quartile: float = NORMAL_QUARTILE) -&gt; tuple[float, float]:\n    &quot;&quot;&quot;The decision rule written in the units of the data rather than in scales.\n\n    An observation inside the interval is retained and an observation outside it is flagged.\n\n    Args:\n        data: the sample, shape (n,).\n        threshold: the cut-off on the absolute modified z-score.\n        quartile: the constant the MAD is divided by, as in median_absolute_deviation.\n\n    Returns:\n        The lower and the upper end of the interval.\n    &quot;&quot;&quot;\n    values = _as_sample(data=data)\n    if threshold &lt;= 0.0:\n        raise ValueError(f&quot;threshold must be positive, got {threshold}.&quot;)\n    centre = float(np.median(values))\n    half_width = threshold * _hampel_scale(data=values, quartile=quartile)\n    return centre - half_width, centre + half_width\"><pre><span class=\"pl-c\"># EDA\/Outlier\/Hampel\/hampel_identifier.py<\/span>\n<span class=\"pl-s1\">__author__<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s\">'yRocket'<\/span>\n<span class=\"pl-s1\">__version__<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s\">\"0.9.1.2026.8.18\"<\/span>  <span class=\"pl-c\"># Semantic Versioning: Major.Minor.Patch.Date(YYYY.M.D)<\/span>\n\n<span class=\"pl-c\"># Everything this module offers. The names beginning with an underscore are internal.<\/span>\n<span class=\"pl-s1\">__all__<\/span> <span class=\"pl-c1\">=<\/span> &#91;\n    <span class=\"pl-s\">'NORMAL_QUARTILE'<\/span>,\n    <span class=\"pl-s\">'DEFAULT_THRESHOLD'<\/span>,\n    <span class=\"pl-s\">'median_absolute_deviation'<\/span>,\n    <span class=\"pl-s\">'hampel_score'<\/span>,\n    <span class=\"pl-s\">'retained_interval'<\/span>,\n&#93;\n\n<span class=\"pl-k\">import<\/span> <span class=\"pl-s1\">numpy<\/span> <span class=\"pl-k\">as<\/span> <span class=\"pl-s1\">np<\/span>\n<span class=\"pl-k\">from<\/span> <span class=\"pl-s1\">scipy<\/span> <span class=\"pl-k\">import<\/span> <span class=\"pl-s1\">stats<\/span>\n\n<span class=\"pl-c\"># The MAD of a normal sample converges to this multiple of sigma, so dividing by it puts the<\/span>\n<span class=\"pl-c\"># modified score on the same scale as a classical z-score. It is the third quartile of N(0, 1).<\/span>\n<span class=\"pl-c1\">NORMAL_QUARTILE<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">float<\/span>(<span class=\"pl-s1\">stats<\/span>.<span class=\"pl-c1\">norm<\/span>.<span class=\"pl-c1\">ppf<\/span>(<span class=\"pl-c1\">0.75<\/span>))\n\n<span class=\"pl-c\"># The cut-off recommended by Iglewicz and Hoaglin for the modified z-score.<\/span>\n<span class=\"pl-c1\">DEFAULT_THRESHOLD<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">3.5<\/span>\n\n\n<span class=\"pl-k\">def<\/span> <span class=\"pl-en\">_as_sample<\/span>(<span class=\"pl-s1\">data<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">None<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>:\n    <span class=\"pl-s\">\"\"\"Return the sample as a 1-D float array, refusing input the identifier cannot read.\"\"\"<\/span>\n    <span class=\"pl-s1\">values<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">asarray<\/span>(<span class=\"pl-s1\">data<\/span>, <span class=\"pl-s1\">dtype<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">float<\/span>)\n    <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">values<\/span>.<span class=\"pl-c1\">ndim<\/span> <span class=\"pl-c1\">!=<\/span> <span class=\"pl-c1\">1<\/span>:\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">ValueError<\/span>(<span class=\"pl-s\">f\"data must be 1-D, got shape <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">values<\/span>.<span class=\"pl-c1\">shape<\/span><span class=\"pl-kos\">}<\/span><\/span>.\"<\/span>)\n    <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">values<\/span>.<span class=\"pl-c1\">size<\/span> <span class=\"pl-c1\">&lt;<\/span> <span class=\"pl-c1\">3<\/span>:\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">ValueError<\/span>(<span class=\"pl-s\">f\"the identifier needs at least 3 observations to have a usable median, got <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">values<\/span>.<span class=\"pl-c1\">size<\/span><span class=\"pl-kos\">}<\/span><\/span>.\"<\/span>)\n    <span class=\"pl-k\">if<\/span> <span class=\"pl-c1\">not<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">all<\/span>(<span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">isfinite<\/span>(<span class=\"pl-s1\">values<\/span>)):\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">ValueError<\/span>(<span class=\"pl-s\">f\"data carries <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-en\">int<\/span>((<span class=\"pl-c1\">~<\/span><span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">isfinite<\/span>(<span class=\"pl-s1\">values<\/span>)).<span class=\"pl-c1\">sum<\/span>())<span class=\"pl-kos\">}<\/span><\/span> non-finite values; \"<\/span>\n                         <span class=\"pl-s\">f\"remove or impute them before scoring.\"<\/span>)\n    <span class=\"pl-k\">return<\/span> <span class=\"pl-s1\">values<\/span>\n\n\n<span class=\"pl-k\">def<\/span> <span class=\"pl-en\">median_absolute_deviation<\/span>(<span class=\"pl-s1\">data<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">None<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-smi\">float<\/span>:\n    <span class=\"pl-s\">\"\"\"Median of the absolute deviations from the sample median.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    Args:<\/span>\n<span class=\"pl-s\">        data: the sample, shape (n,).<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    Returns:<\/span>\n<span class=\"pl-s\">        The MAD, before any rescaling.<\/span>\n<span class=\"pl-s\">    \"\"\"<\/span>\n    <span class=\"pl-s1\">values<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">asarray<\/span>(<span class=\"pl-s1\">data<\/span>, <span class=\"pl-s1\">dtype<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">float<\/span>)\n    <span class=\"pl-k\">return<\/span> <span class=\"pl-en\">float<\/span>(<span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">median<\/span>(<span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">abs<\/span>(<span class=\"pl-s1\">values<\/span> <span class=\"pl-c1\">-<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">median<\/span>(<span class=\"pl-s1\">values<\/span>))))\n\n\n<span class=\"pl-k\">def<\/span> <span class=\"pl-en\">_hampel_scale<\/span>(<span class=\"pl-s1\">data<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">None<\/span>, <span class=\"pl-s1\">quartile<\/span>: <span class=\"pl-smi\">float<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">NORMAL_QUARTILE<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-smi\">float<\/span>:\n    <span class=\"pl-s\">\"\"\"Robust scale of the sample, which is the MAD divided by the consistency constant.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    Args:<\/span>\n<span class=\"pl-s\">        data: the sample, shape (n,).<\/span>\n<span class=\"pl-s\">        quartile: the constant the MAD is divided by; the default makes the scale estimate the<\/span>\n<span class=\"pl-s\">            standard deviation on a normal sample.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    Returns:<\/span>\n<span class=\"pl-s\">        The robust scale.<\/span>\n<span class=\"pl-s\">    \"\"\"<\/span>\n    <span class=\"pl-s1\">values<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">_as_sample<\/span>(<span class=\"pl-s1\">data<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">data<\/span>)\n    <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">quartile<\/span> <span class=\"pl-c1\">&lt;=<\/span> <span class=\"pl-c1\">0.0<\/span>:\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">ValueError<\/span>(<span class=\"pl-s\">f\"quartile must be positive, got <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">quartile<\/span><span class=\"pl-kos\">}<\/span><\/span>.\"<\/span>)\n    <span class=\"pl-s1\">mad<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">median_absolute_deviation<\/span>(<span class=\"pl-s1\">data<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">values<\/span>)\n    <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">mad<\/span> <span class=\"pl-c1\">==<\/span> <span class=\"pl-c1\">0.0<\/span>:\n        <span class=\"pl-c\"># More than half the sample sits on one value, so the MAD carries no scale at all.<\/span>\n        <span class=\"pl-c\"># Returning zero here would make every score infinite or undefined further down.<\/span>\n        <span class=\"pl-s1\">centre<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">float<\/span>(<span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">median<\/span>(<span class=\"pl-s1\">values<\/span>))\n        <span class=\"pl-s1\">repeated<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">int<\/span>((<span class=\"pl-s1\">values<\/span> <span class=\"pl-c1\">==<\/span> <span class=\"pl-s1\">centre<\/span>).<span class=\"pl-c1\">sum<\/span>())\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">ValueError<\/span>(<span class=\"pl-s\">f\"the MAD is 0 because <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">repeated<\/span><span class=\"pl-kos\">}<\/span><\/span> of <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">values<\/span>.<span class=\"pl-c1\">size<\/span><span class=\"pl-kos\">}<\/span><\/span> observations equal the median \"<\/span>\n                         <span class=\"pl-s\">f\"<span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">centre<\/span><span class=\"pl-kos\">}<\/span><\/span>; the robust scale is undefined. Every 50% breakdown estimator returns 0 \"<\/span>\n                         <span class=\"pl-s\">f\"here, Sn and Qn included, so report that the sample cannot support the method or \"<\/span>\n                         <span class=\"pl-s\">f\"take a scale that does not rest on a median of the deviations.\"<\/span>)\n    <span class=\"pl-k\">return<\/span> <span class=\"pl-s1\">mad<\/span> <span class=\"pl-c1\">\/<\/span> <span class=\"pl-s1\">quartile<\/span>\n\n\n<span class=\"pl-k\">def<\/span> <span class=\"pl-en\">hampel_score<\/span>(<span class=\"pl-s1\">data<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">None<\/span>, <span class=\"pl-s1\">quartile<\/span>: <span class=\"pl-smi\">float<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">NORMAL_QUARTILE<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span>:\n    <span class=\"pl-s\">\"\"\"Modified z-score of every observation, which is its distance from the median in robust scales.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    No threshold is taken, because the score does not depend on one. A caller decides by comparing<\/span>\n<span class=\"pl-s\">    the absolute score against a cut-off, 3.5 by convention.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    Args:<\/span>\n<span class=\"pl-s\">        data: the sample, shape (n,).<\/span>\n<span class=\"pl-s\">        quartile: the constant the MAD is divided by, as in median_absolute_deviation.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    Returns:<\/span>\n<span class=\"pl-s\">        The modified z-scores, shape (n,).<\/span>\n<span class=\"pl-s\">    \"\"\"<\/span>\n    <span class=\"pl-s1\">values<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">_as_sample<\/span>(<span class=\"pl-s1\">data<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">data<\/span>)\n    <span class=\"pl-k\">return<\/span> (<span class=\"pl-s1\">values<\/span> <span class=\"pl-c1\">-<\/span> <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">median<\/span>(<span class=\"pl-s1\">values<\/span>)) <span class=\"pl-c1\">\/<\/span> <span class=\"pl-en\">_hampel_scale<\/span>(<span class=\"pl-s1\">data<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">values<\/span>, <span class=\"pl-s1\">quartile<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">quartile<\/span>)\n\n\n<span class=\"pl-k\">def<\/span> <span class=\"pl-en\">retained_interval<\/span>(<span class=\"pl-s1\">data<\/span>: <span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">ndarray<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">None<\/span>, <span class=\"pl-s1\">threshold<\/span>: <span class=\"pl-smi\">float<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">DEFAULT_THRESHOLD<\/span>,\n                      <span class=\"pl-s1\">quartile<\/span>: <span class=\"pl-smi\">float<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-c1\">NORMAL_QUARTILE<\/span>) <span class=\"pl-c1\">-&gt;<\/span> <span class=\"pl-s1\">tuple<\/span>&#91;<span class=\"pl-smi\">float<\/span>, <span class=\"pl-smi\">float<\/span>&#93;:\n    <span class=\"pl-s\">\"\"\"The decision rule written in the units of the data rather than in scales.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    An observation inside the interval is retained and an observation outside it is flagged.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    Args:<\/span>\n<span class=\"pl-s\">        data: the sample, shape (n,).<\/span>\n<span class=\"pl-s\">        threshold: the cut-off on the absolute modified z-score.<\/span>\n<span class=\"pl-s\">        quartile: the constant the MAD is divided by, as in median_absolute_deviation.<\/span>\n<span class=\"pl-s\"><\/span>\n<span class=\"pl-s\">    Returns:<\/span>\n<span class=\"pl-s\">        The lower and the upper end of the interval.<\/span>\n<span class=\"pl-s\">    \"\"\"<\/span>\n    <span class=\"pl-s1\">values<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">_as_sample<\/span>(<span class=\"pl-s1\">data<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">data<\/span>)\n    <span class=\"pl-k\">if<\/span> <span class=\"pl-s1\">threshold<\/span> <span class=\"pl-c1\">&lt;=<\/span> <span class=\"pl-c1\">0.0<\/span>:\n        <span class=\"pl-k\">raise<\/span> <span class=\"pl-en\">ValueError<\/span>(<span class=\"pl-s\">f\"threshold must be positive, got <span class=\"pl-s1\"><span class=\"pl-kos\">{<\/span><span class=\"pl-s1\">threshold<\/span><span class=\"pl-kos\">}<\/span><\/span>.\"<\/span>)\n    <span class=\"pl-s1\">centre<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-en\">float<\/span>(<span class=\"pl-s1\">np<\/span>.<span class=\"pl-c1\">median<\/span>(<span class=\"pl-s1\">values<\/span>))\n    <span class=\"pl-s1\">half_width<\/span> <span class=\"pl-c1\">=<\/span> <span class=\"pl-s1\">threshold<\/span> <span class=\"pl-c1\">*<\/span> <span class=\"pl-en\">_hampel_scale<\/span>(<span class=\"pl-s1\">data<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">values<\/span>, <span class=\"pl-s1\">quartile<\/span><span class=\"pl-c1\">=<\/span><span class=\"pl-s1\">quartile<\/span>)\n    <span class=\"pl-k\">return<\/span> <span class=\"pl-s1\">centre<\/span> <span class=\"pl-c1\">-<\/span> <span class=\"pl-s1\">half_width<\/span>, <span class=\"pl-s1\">centre<\/span> <span class=\"pl-c1\">+<\/span> <span class=\"pl-s1\">half_width<\/span><\/pre><\/div>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">Appendix C. Worked Example<\/h2><a id=\"user-content-appendix-c-worked-example\" class=\"anchor\" aria-label=\"Permalink: Appendix C. Worked Example\" href=\"#appendix-c-worked-example\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Every number in this appendix is produced by <code>hampel_worked_example.py<\/code>, invoked as\n<code>python3 hampel_worked_example.py --threshold 3.5<\/code>. The script reads the sample from\n<code>EDA\/Outlier\/data\/1d_esc_current.csv<\/code> and writes the points behind the figure beside the figure\nas CSV.<\/p>\n<p dir=\"auto\">Two rules are set against each other in C.1. <strong>The identifier<\/strong> is the method of section 2, which\nmeasures an observation against the median and the MAD. <strong>The classical rule<\/strong> measures it against\nthe mean and the standard deviation instead.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">C.1. Sample<\/h3><a id=\"user-content-c1-sample\" class=\"anchor\" aria-label=\"Permalink: C.1. Sample\" href=\"#c1-sample\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\"><strong>Table 2. Every observation with its score and its verdict<\/strong><\/p>\n<markdown-accessiblity-table><table>\n<thead>\n<tr>\n<th>Observation<\/th>\n<th>Value<\/th>\n<th>Value \u2212 median<\/th>\n<th>Modified z<\/th>\n<th>Flagged<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>0.0232<\/td>\n<td>0.0000<\/td>\n<td>0.0000<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>0.0232<\/td>\n<td>0.0000<\/td>\n<td>0.0000<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>0.0232<\/td>\n<td>0.0000<\/td>\n<td>0.0000<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>0.0220<\/td>\n<td>\u22120.0012<\/td>\n<td>\u22120.1109<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>0.0232<\/td>\n<td>0.0000<\/td>\n<td>0.0000<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>0.0232<\/td>\n<td>0.0000<\/td>\n<td>0.0000<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td><strong>0.6532<\/strong><\/td>\n<td><strong>+0.6300<\/strong><\/td>\n<td><strong>58.2094<\/strong><\/td>\n<td><strong>Yes<\/strong><\/td>\n<\/tr>\n<tr>\n<td>8<\/td>\n<td>0.0403<\/td>\n<td>+0.0171<\/td>\n<td>1.5800<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>9<\/td>\n<td>0.0293<\/td>\n<td>+0.0061<\/td>\n<td>0.5636<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>10<\/td>\n<td>0.0159<\/td>\n<td>\u22120.0073<\/td>\n<td>\u22120.6745<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>11<\/td>\n<td>0.0134<\/td>\n<td>\u22120.0098<\/td>\n<td>\u22120.9055<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>12<\/td>\n<td>0.0134<\/td>\n<td>\u22120.0098<\/td>\n<td>\u22120.9055<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>13<\/td>\n<td>0.0134<\/td>\n<td>\u22120.0098<\/td>\n<td>\u22120.9055<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>14<\/td>\n<td>0.0134<\/td>\n<td>\u22120.0098<\/td>\n<td>\u22120.9055<\/td>\n<td>No<\/td>\n<\/tr>\n<tr>\n<td>15<\/td>\n<td>0.0134<\/td>\n<td>\u22120.0098<\/td>\n<td>\u22120.9055<\/td>\n<td>No<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/markdown-accessiblity-table>\n<p dir=\"auto\">The flag is the rule of section 2.3 applied to the modified z beside it: an observation\nis flagged when the absolute value of that score exceeds the threshold of 3.5. Only observation 7\ndoes, at 58.2094. The next largest is 1.5800 at observation 8, less than half the threshold.<\/p>\n<p dir=\"auto\">The two middle columns lay out the arithmetic of section 2.1, so the flag can be checked rather\nthan taken. The deviation column is the numerator of the modified z, and the modified z is that\ndeviation divided by the scale of 0.010823 that Table 3 works out. Observation 7 reads\n0.6300 \/ 0.010823 = 58.2094, which is 16.6 times the threshold it has to clear.<\/p>\n<p dir=\"auto\"><strong>Table 3. The centre and the scale each rule computes<\/strong><\/p>\n<markdown-accessiblity-table><table>\n<thead>\n<tr>\n<th>Quantity<\/th>\n<th>Classical rule<\/th>\n<th>Identifier<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Centre<\/td>\n<td>mean = 0.062913<\/td>\n<td>median = 0.023200<\/td>\n<\/tr>\n<tr>\n<td>Raw scale<\/td>\n<td>standard deviation = 0.163469<\/td>\n<td>MAD = 0.007300<\/td>\n<\/tr>\n<tr>\n<td>Scale used in the score<\/td>\n<td>standard deviation = 0.163469<\/td>\n<td>MAD \/ 0.674490 = 0.010823<\/td>\n<\/tr>\n<tr>\n<td>Upper boundary at 3.5<\/td>\n<td>mean + 3.5 x standard deviation = 0.635053<\/td>\n<td>median + 3.5 x (MAD \/ 0.674490) = 0.061080<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/markdown-accessiblity-table>\n<p dir=\"auto\">The MAD is the median of the absolute deviations from 0.023200. Sorted, those 15 deviations are\n0 five times, then 0.0012, 0.0061, 0.0073, 0.0098 five times, 0.0171 and 0.6300. The eighth of\nfifteen is 0.0073, which is the MAD, and it comes from the observation 0.0159. Dividing it by\n0.674490 as section 2.2 requires gives the 0.010823 the score divides by.<\/p>\n<p dir=\"auto\">The two scales differ by a factor of 15.1, and the whole of that gap is the single observation\n0.6532 entering the standard deviation. The scale of the identifier describes the other 14\nobservations; the classical scale describes the outlier.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">C.2. Normality<\/h3><a id=\"user-content-c2-normality\" class=\"anchor\" aria-label=\"Permalink: C.2. Normality\" href=\"#c2-normality\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Normality enters the method only through the constant of section 2.2, and detection itself does\nnot need it. This sample is where that distinction matters, because it is not normal.<\/p>\n<p dir=\"auto\"><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"https:\/\/github.com\/ykim2718\/AIML\/blob\/main\/EDA\/Outlier\/Hampel\/hampel-identifier_fig\/hampel_normality.png\"><img src=\"https:\/\/ykim.synology.me\/wordpress\/wp-json\/gh-readme\/v1\/asset?user=ykim2718&#038;repo=AIML&#038;branch=main&#038;path=EDA\/Outlier\/Hampel\/hampel-identifier_fig\/hampel_normality.png&#038;sig=5f333120ed89ce81d035719a69da5e6146e476a68e98bf6ccef5913342eb75f4\" alt=\"Fig 1\" style=\"max-width: 100%;\"><\/a><\/p>\n<p dir=\"auto\"><strong>Fig 1. Normal quantile plots of the sample and of the sample without its extreme value<\/strong><\/p>\n<p dir=\"auto\">The observation is on the horizontal axis and the quantile a normal sample would put there is on\nthe vertical one, so a normal sample would fall along the line. The line runs through the first\nand third quartiles rather than being fitted by least squares, which keeps the extreme\nobservation from rotating it toward itself and hiding the departure the panel is drawn to show.<\/p>\n<p dir=\"auto\"><strong>Table 4. Normality under three views of the sample<\/strong><\/p>\n<markdown-accessiblity-table><table>\n<thead>\n<tr>\n<th>View<\/th>\n<th>Count<\/th>\n<th>Skewness<\/th>\n<th>Shapiro-Wilk p<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>All observations<\/td>\n<td>15<\/td>\n<td>3.462<\/td>\n<td>1.70e-07<\/td>\n<\/tr>\n<tr>\n<td>Without 0.6532<\/td>\n<td>14<\/td>\n<td>1.042<\/td>\n<td>9.91e-03<\/td>\n<\/tr>\n<tr>\n<td>All observations, log10<\/td>\n<td>15<\/td>\n<td>2.780<\/td>\n<td>1.97e-05<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/markdown-accessiblity-table>\n<p dir=\"auto\">The Shapiro-Wilk test takes as its null hypothesis that the sample was drawn from a normal\ndistribution. Its p-value is the probability of a departure at least as large as the one observed\nif that hypothesis were true, so a p-value below the chosen level says the observed shape is too\nunlikely under normality to be put down to sampling variation, and the hypothesis is rejected.<\/p>\n<p dir=\"auto\">All three p-values fall below 0.05, and all three fall below 0.01 as well, though the middle row\nfalls below the stricter level by only 0.0001 and should not be read as decisive there. What puts\neach view below the level is a different feature of the data.<\/p>\n<ul dir=\"auto\">\n<li>The full sample fails because of one observation. The value 0.6532 is 28 times the median, so panel (a) compresses the other 14 into a narrow column on the left and strands that one point far to the right of the line. The skewness of 3.462 is that point.<\/li>\n<li>The sample without it fails because the data are discrete. The remaining 14 observations take only 6 distinct values, with 5 tied at 0.0134 and 5 at 0.0232, so panel (b) stacks those ties into vertical columns instead of following the line. A normal distribution is continuous and produces no ties at all, so a sample carrying ten of them cannot look normal however its extremes are treated.<\/li>\n<li>The log view, computed but not plotted, fails for the same reason as the first. A logarithm compresses ratios, but 0.6532 remains 48.7 times the smallest observation afterwards, so it stays isolated and the skewness falls only from 3.462 to 2.780.<\/li>\n<\/ul>\n<p dir=\"auto\">The second row is the one that matters for this document, because it is the reason the sample\ncannot be rescued by treating 0.6532. The p-values are also approximate rather than exact here,\nsince two thirds of the observations are tied and the Shapiro-Wilk statistic assumes a continuous\ndistribution; the size of the departure does not rest on that approximation.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h2 class=\"heading-element\" dir=\"auto\">Appendix D. Consistency Constant of the MAD<\/h2><a id=\"user-content-appendix-d-consistency-constant-of-the-mad\" class=\"anchor\" aria-label=\"Permalink: Appendix D. Consistency Constant of the MAD\" href=\"#appendix-d-consistency-constant-of-the-mad\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Section 2.2 divides the MAD by 0.674490 and says the raw MAD converges to that multiple of\n<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\sigma$<\/math-renderer> on a normal sample. This appendix derives the number, says how well a small sample\nreaches it, and shows that it belongs to the normal distribution rather than to the MAD.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">D.1. Derivation<\/h3><a id=\"user-content-d1-derivation\" class=\"anchor\" aria-label=\"Permalink: D.1. Derivation\" href=\"#d1-derivation\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">Take <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$X$<\/math-renderer> from a normal distribution with mean <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\mu$<\/math-renderer> and standard deviation <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\sigma$<\/math-renderer>. Its median is\n<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\mu$<\/math-renderer>, so the population MAD is the number <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$m$<\/math-renderer> with half the probability lying within <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$m$<\/math-renderer> of the\ncentre.<\/p>\n<p dir=\"auto\"><math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$$P\\left( \\left| X - \\mu \\right| \\le m \\right) = \\frac{1}{2}$$<\/math-renderer><\/p>\n<p dir=\"auto\">The probability inside that band is what lies below <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\mu + m$<\/math-renderer> less what lies below <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\mu - m$<\/math-renderer>.\nSymmetry about <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\mu$<\/math-renderer> is what then collapses the two terms into one, since the lower tail is the\nmirror of the upper.<\/p>\n<p dir=\"auto\"><math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$$\\Phi\\left( \\frac{m}{\\sigma} \\right) - \\Phi\\left( -\\frac{m}{\\sigma} \\right) = 2 \\Phi\\left( \\frac{m}{\\sigma} \\right) - 1 = \\frac{1}{2}$$<\/math-renderer><\/p>\n<ul dir=\"auto\">\n<li>\n<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\Phi$<\/math-renderer> (capital phi) \u2014 the cumulative distribution function of the standard normal, so <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\Phi(u)$<\/math-renderer> is the probability of falling below <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$u$<\/math-renderer> standard deviations.<\/li>\n<li>\n<math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$m$<\/math-renderer> \u2014 the population MAD, the half-width of the band holding half the probability.<\/li>\n<\/ul>\n<p dir=\"auto\">Rearranging leaves <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\Phi(m\/\\sigma) = 3\/4$<\/math-renderer>, and inverting it leaves the constant.<\/p>\n<p dir=\"auto\"><math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$$m = \\Phi^{-1}(0.75) \\sigma = 0.674490 \\sigma$$<\/math-renderer><\/p>\n<p dir=\"auto\">That is where the third quartile comes from: <strong>half the probability inside <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\pm m$<\/math-renderer> is the same\nstatement as three quarters of it below <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$+m$<\/math-renderer>.<\/strong> The quartile is not chosen for the MAD. It is what\nthe MAD turns out to be.<\/p>\n<p dir=\"auto\">The same number placed twice gives the interquartile range, since the first and the third quartile\neach sit <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$0.674490 \\sigma$<\/math-renderer> from the centre.<\/p>\n<p dir=\"auto\"><math-renderer class=\"js-display-math\" style=\"display: block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$$\\mathrm{IQR} = 2 \\cdot 0.674490 \\sigma = 1.348980 \\sigma$$<\/math-renderer><\/p>\n<p dir=\"auto\">A rule built on the interquartile range therefore rescales by the same constant this one does,\ntaken twice rather than once.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">D.2. Finite Samples<\/h3><a id=\"user-content-d2-finite-samples\" class=\"anchor\" aria-label=\"Permalink: D.2. Finite Samples\" href=\"#d2-finite-samples\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">The derivation is a statement about the distribution, not about a sample drawn from it. The sample\nMAD converges to <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$m$<\/math-renderer>, but in a small sample it lands low: the median of a short list of deviations\nsits below the population median more often than above it, and rescaling does not repair that.<\/p>\n<p dir=\"auto\"><strong>Table 5. Mean of the rescaled MAD over 60,000 normal samples, true <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\sigma = 1$<\/math-renderer><\/strong><\/p>\n<markdown-accessiblity-table><table>\n<thead>\n<tr>\n<th>Sample size n<\/th>\n<th>Mean of MAD \/ 0.674490<\/th>\n<th>Bias<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>10<\/td>\n<td>0.9129<\/td>\n<td>\u22128.7%<\/td>\n<\/tr>\n<tr>\n<td>15<\/td>\n<td>0.9459<\/td>\n<td>\u22125.4%<\/td>\n<\/tr>\n<tr>\n<td>30<\/td>\n<td>0.9739<\/td>\n<td>\u22122.6%<\/td>\n<\/tr>\n<tr>\n<td>100<\/td>\n<td>0.9920<\/td>\n<td>\u22120.8%<\/td>\n<\/tr>\n<tr>\n<td>1000<\/td>\n<td>0.9992<\/td>\n<td>\u22120.1%<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/markdown-accessiblity-table>\n<p dir=\"auto\">The bias runs one way, so the robust scale of a short sample is too small and every modified\nz-score built on it is too large. Fifteen observations is a common size for a measurement run, and\nat that size the scale is understated by about 5%, which lifts a score of 3.3 to 3.5 with nothing\nhaving happened to the data.<\/p>\n<div class=\"markdown-heading\" dir=\"auto\"><h3 class=\"heading-element\" dir=\"auto\">D.3. Other Distributions<\/h3><a id=\"user-content-d3-other-distributions\" class=\"anchor\" aria-label=\"Permalink: D.3. Other Distributions\" href=\"#d3-other-distributions\"><svg data-component=\"Octicon\" class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"><path d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"><\/path><\/svg><\/a><\/div>\n<p dir=\"auto\">The constant is a property of the normal distribution and nothing else. Repeating the derivation\nunder another shape gives another number, and using 0.674490 there would rescale the MAD to\nsomething that is not the standard deviation of anything.<\/p>\n<p dir=\"auto\"><strong>Table 6. The ratio of the population MAD to the standard deviation<\/strong><\/p>\n<markdown-accessiblity-table><table>\n<thead>\n<tr>\n<th>Distribution<\/th>\n<th>MAD \/ <math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\sigma$<\/math-renderer>\n<\/th>\n<th>Value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Normal<\/td>\n<td><math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\Phi^{-1}(0.75)$<\/math-renderer><\/td>\n<td>0.674490<\/td>\n<\/tr>\n<tr>\n<td>Laplace<\/td>\n<td><math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\ln 2 \/ \\sqrt{2}$<\/math-renderer><\/td>\n<td>0.490129<\/td>\n<\/tr>\n<tr>\n<td>Uniform<\/td>\n<td><math-renderer class=\"js-inline-math\" style=\"display: inline-block\" data-run-id=\"382c7787941c40bda8d61017bdf6bd8a\">$\\sqrt{3} \/ 2$<\/math-renderer><\/td>\n<td>0.866025<\/td>\n<\/tr>\n<\/tbody>\n<\/table><\/markdown-accessiblity-table>\n<p dir=\"auto\">This is the sense in which section 2.2 calls the constant the one place normality enters the\nmethod. Detection does not need it, since scaling every score by one factor leaves the order\nalone. Reading a threshold as a false-positive rate does need it, and that reading is only as\ngood as the shape assumed here.<\/p>\n<\/article><\/div><\/div><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<div style='text-align:center' class='yasr-auto-insert-overall'><\/div><div style='text-align:center' class='yasr-auto-insert-visitor'><\/div>","protected":false},"excerpt":{"rendered":"<p>An outlier inflates the standard deviation it is measured against. The Hampel identifier swaps the mean and standard deviation for the median and the rescaled MAD, so the scale still describes the bulk of the sample. Covers the consistency constant, the 3.5 threshold, the retained interval, and the 50% breakdown point.<\/p>\n","protected":false},"author":4,"featured_media":6802,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_kadence_starter_templates_imported_post":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","yasr_overall_rating":0,"yasr_post_is_review":"","yasr_auto_insert_disabled":"","yasr_review_type":"","fifu_image_url":"","fifu_image_alt":"","iawp_total_views":17,"footnotes":""},"categories":[56,384],"tags":[386,425],"class_list":["post-6796","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-science-slug","category-eda-slug","tag-github-hosted","tag-outlier"],"yasr_visitor_votes":{"stars_attributes":{"read_only":false,"span_bottom":false},"number_of_votes":2,"sum_votes":9},"jetpack_featured_media_url":"https:\/\/ykim.synology.me\/wordpress\/wp-content\/uploads\/2026\/08\/hillside-plaza-stone-columns.jpg","_links":{"self":[{"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/posts\/6796","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/comments?post=6796"}],"version-history":[{"count":4,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/posts\/6796\/revisions"}],"predecessor-version":[{"id":7459,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/posts\/6796\/revisions\/7459"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/media\/6802"}],"wp:attachment":[{"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/media?parent=6796"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/categories?post=6796"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ykim.synology.me\/wordpress\/wp-json\/wp\/v2\/tags?post=6796"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}