Skip to content
svgbrushableoutlier-consensus

Outlier consensus

Which values look unusual, and do the common outlier rules agree?

Demo data · seed 20261101 · 405 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read rows as how many of the three rules flag a value: the top row is flagged by all three.
  2. Read the vertical lines as each rule's cutoff.
  3. Investigate values flagged by all three first.
  1. Callout 1: Flagged by all three rules: look at these first.
  2. Callout 2: Bottom row: not flagged by any rule.
  3. Callout 3: Each dashed line: one rule's cutoff.

Watch out

  • Being flagged doesn't make a value wrong: check the source before removing it.

Defaults

Log x axis (positive values)
Off
Display only; the rules use the raw values.

Pinned in the code

  • Tukey: outside [Q1 − 1.5·IQR, Q3 + 1.5·IQR] with type-7 quartiles.
  • z: |x − x̄| / s > 3 with s on n − 1; not applied when n ≤ 10 (max |z| ≤ (n − 1)/√n).
  • Modified z (Iglewicz & Hoaglin): |x − median| / (1.4826·MAD) > 3.5; when MAD = 0 the scale is 1.253314·mean absolute deviation.
  • Consensus = number of rules flagging a value (0–3). Flags are screening hints, never automatic deletions.
# Outlier consensus — Codesplash Chart Lab (recipe "outlier-consensus")
# controls: log=false
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("outlier-consensus-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
v = df["response_ms"].dropna().to_numpy(dtype=float)
q1, q3 = np.percentile(v, [25, 75])  # type-7 quartiles (numpy's default "linear")
iqr = q3 - q1
tukey = (v < q1 - 1.5 * iqr) | (v > q3 + 1.5 * iqr)
m, s = v.mean(), v.std(ddof=1)
z = (np.abs(v - m) > 3 * s) if len(v) > 10 and s > 0 else np.zeros(len(v), bool)  # not applied when n ≤ 10
med = np.median(v)
mad = np.median(np.abs(v - med))
scale = 1.4826 * mad if mad > 0 else 1.253314 * np.mean(np.abs(v - med))  # Iglewicz & Hoaglin; meanAD when MAD = 0
modz = (np.abs(v - med) > 3.5 * scale) if scale > 0 else np.zeros(len(v), bool)
votes = tukey.astype(int) + z + modz  # consensus 0–3: screening hints, never automatic deletions

rng = np.random.default_rng(11)  # deterministic jitter within each band
y = votes + rng.uniform(-0.3, 0.3, len(v))
fig, ax = plt.subplots(figsize=(8, 3.6))
for k, colour in zip(range(4), [GREY, PALETTE[1], PALETTE[3], DIV[0]]):
    m_k = votes == k
    ax.scatter(v[m_k], y[m_k], s=12, color=colour, alpha=0.8, edgecolors="none")
for lo, hi, colour, ls, label in [(q1 - 1.5 * iqr, q3 + 1.5 * iqr, REF, "-", "Tukey 1.5×IQR"), (m - 3 * s, m + 3 * s, PALETTE[0], "--", "|z| = 3"), (med - 3.5 * scale, med + 3.5 * scale, PALETTE[2], ":", "|mod z| = 3.5")]:
    ax.axvline(lo, color=colour, linestyle=ls, linewidth=1.3, label=label)
    ax.axvline(hi, color=colour, linestyle=ls, linewidth=1.3)
ax.set_yticks(range(4), [f"{k} rule{'s' if k != 1 else ''} · {(votes == k).sum()}" for k in range(4)])
ax.set_xlabel("response_ms")
ax.legend(fontsize=8, loc="upper right")
plt.show()

Needs pandas, numpy, matplotlib · reads outlier-consensus-demo.csv · app theme from the optional codesplash helper