svgesd-sequence
Generalized ESD sequence
How many outliers does Rosner's generalized ESD test find?
How to read it
- Read the points left to right as the most extreme values removed one by one.
- Compare each with its dashed critical value.
- The count of outliers is the last step above the line, even if earlier ones dip.
- Callout 1: The most extreme value and its studentized deviation.
- Callout 2: The dashed line: critical values.
- Callout 3: Red: flagged outliers.
Watch out
- It assumes normal data apart from the outliers, and the count you allow affects the result.
Defaults
No settings: the chart draws one way.
Pinned in the code
- Draws the engine's numbers as given (precomputed by the Python or R analysis); the chart computes nothing inferential.
- The number of outliers is max{i : Rᵢ > λᵢ}, not the count of steps above the line — an earlier step below its λ can still be an outlier (masking).
- Critical values use Rosner's t-approximation at the engine's α for the declared maximum number of outliers.
# Generalized ESD sequence — Codesplash Chart Lab (recipe "esd-sequence")
# controls: defaults
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("esd-sequence-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")
S = "step"
R = "R"
L = "lambda"
VAL = "value"
d = df.dropna(subset=[S, R]).sort_values(S)
above = d.loc[d[R] > d[L], S]
n_out = int(above.max()) if len(above) else 0 # Rosner: max{i : R_i > λ_i}, not a count
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.plot(d[S], d[L], color="#c13e2e", linestyle="--", label="critical λ")
ax.plot(d[S], d[R], color=plt.rcParams["text.color"], marker="o", label="R")
out = d[d[S] <= n_out]
ax.scatter(out[S], out[R], s=50, color="#c13e2e", zorder=3, label=f"outliers: {len(out)}")
if VAL:
for _, r in d.iterrows():
ax.annotate(f"{r[VAL]:g}", (r[S], r[R]), xytext=(0, 7), textcoords="offset points", ha="center", fontsize=8, color=REF)
ax.set_xlabel("points removed (step i)")
ax.set_ylabel("R (studentized deviation)")
ax.legend(fontsize=8)
plt.show()Needs pandas, numpy, matplotlib · reads esd-sequence-demo.csv · app theme from the optional codesplash helper
# Generalized ESD sequence — Codesplash Chart Lab (recipe "esd-sequence")
# controls: defaults
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
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 px.colors.qualitative.Plotly
df = pd.read_csv("esd-sequence-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")
S = "step"
R = "R"
L = "lambda"
VAL = "value"
d = df.dropna(subset=[S, R]).sort_values(S)
above = d.loc[d[R] > d[L], S]
n_out = int(above.max()) if len(above) else 0
fig = go.Figure()
fig.add_scatter(x=d[S], y=d[L], mode="lines", line=dict(color="#c13e2e", dash="dash"), name="critical λ")
fig.add_scatter(x=d[S], y=d[R], mode="lines+markers+text", text=d[VAL].map(lambda v: f"{v:g}") if VAL else None, textposition="top center",
marker=dict(color=["#c13e2e" if s <= n_out else REF for s in d[S]], size=9), line_color=REF, name="R")
fig.update_layout(xaxis_title="points removed (step i)", yaxis_title="R (studentized deviation)")
fig.show()Needs pandas, numpy, plotly · reads esd-sequence-demo.csv · app theme from the optional codesplash helper
# Generalized ESD sequence — Codesplash Chart Lab (recipe "esd-sequence")
# controls: defaults
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("esd-sequence-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
tok <- if (has_cs) codesplashr::cs_palette(dark = FALSE) else list()
seq_ramp <- if (is.null(tok$sequential)) c("#eff6fd", "#1a469d") else tok$sequential # low → high
div_ramp <- if (is.null(tok$diverging)) c("#c13e2e", "#f3f5f8", "#0859ac") else tok$diverging # −, 0, +
ref_col <- if (is.null(tok$reference)) "#4e5661" else tok$reference
grey_col <- if (is.null(tok$dim)) "#ced1d6" else tok$dim
s_col <- "step"
r_col <- "R"
l_col <- "lambda"
v_col <- "value"
d <- df[!is.na(df[[s_col]]) & !is.na(df[[r_col]]), ]
d <- data.frame(i = d[[s_col]], r = d[[r_col]], l = d[[l_col]], v = if (is.null(v_col)) NA_real_ else d[[v_col]])
d <- d[order(d$i), ]
n_out <- if (any(d$r > d$l, na.rm = TRUE)) max(d$i[which(d$r > d$l)]) else 0 # Rosner: max{i : R_i > λ_i}
d$outlier <- d$i <= n_out
p <- ggplot(d, aes(i, r)) + geom_line(aes(y = l), colour = "#c13e2e", linetype = "dashed") + geom_line() +
geom_point(aes(colour = outlier), size = 2.6, show.legend = FALSE) + scale_colour_manual(values = c("FALSE" = ref_col, "TRUE" = "#c13e2e")) +
{ if (!all(is.na(d$v))) geom_text(aes(label = format(v)), vjust = -1, size = 3, colour = ref_col) } +
labs(x = "points removed (step i)", y = "R (studentized deviation)") + theme_cs
print(p)Needs ggplot2 · reads esd-sequence-demo.csv · app theme from the optional codesplashr helper