svghalf-normal-effects
Half-normal plot of effects
Which factor effects in an unreplicated factorial stand out from noise?
How to read it
- Read points near the line through the origin as noise.
- Read points far above and to the right as active effects.
- The labels name the factors.
- Callout 1: Active effects, far from the line.
- Callout 2: Inactive effects, on the line.
- Callout 3: The line through the inactive ones.
Watch out
- Effects are aliased in a fraction: a labelled effect may be another one in disguise.
Defaults
No settings: the chart draws one way.
Pinned in the code
- Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
- Quantiles are Φ⁻¹(0.5 + 0.5·(i − 0.5)/m) for the i-th smallest of m effects (Daniel 1959); activity is the engine's decision (Lenth's ME by default).
- The reference line is least squares through the origin on the inactive effects.
# Half-normal plot of effects — Codesplash Chart Lab (recipe "half-normal-effects")
# 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("half-normal-effects-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")
E = "effect"
A = "|effect|"
Q = "half-normal quantile"
S = "active"
d = df.dropna(subset=[A, Q])
sig = d[S].astype(bool)
inert = d[~sig]
slope = (inert[A] * inert[Q]).sum() / (inert[A] ** 2).sum() # least squares through the origin
fig, ax = plt.subplots(figsize=(8, 4.5))
xs = np.array([0, d[A].abs().max() * 1.1])
ax.plot(xs, slope * xs, color=REF, linestyle="--", linewidth=1)
ax.scatter(d.loc[~sig, A].abs(), d.loc[~sig, Q], color="grey", s=18)
ax.scatter(d.loc[sig, A].abs(), d.loc[sig, Q], color=PALETTE[1], s=30)
for _, r in d[sig].iterrows():
ax.annotate(str(r[E]), (abs(r[A]), r[Q]), xytext=(-6, 0), textcoords="offset points", ha="right", va="center", fontsize=9, fontweight="bold")
ax.set_ylim(0, d[Q].max() * 1.08)
ax.set_xlabel(A)
ax.set_ylabel(Q)
plt.show()Needs pandas, numpy, matplotlib · reads half-normal-effects-demo.csv · app theme from the optional codesplash helper
# Half-normal plot of effects — Codesplash Chart Lab (recipe "half-normal-effects")
# 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("half-normal-effects-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
E = "effect"
A = "|effect|"
Q = "half-normal quantile"
S = "active"
d = df.dropna(subset=[A, Q])
sig = d[S].astype(bool)
fig = go.Figure()
fig.add_scatter(x=d.loc[~sig, A].abs(), y=d.loc[~sig, Q], mode="markers", name="inactive", marker_color="grey")
fig.add_scatter(x=d.loc[sig, A].abs(), y=d.loc[sig, Q], mode="markers+text", text=d.loc[sig, E], textposition="middle left", name="active", marker=dict(color=PALETTE[1], size=10))
fig.update_layout(xaxis_title=A, yaxis_title=Q)
fig.show()Needs pandas, numpy, plotly · reads half-normal-effects-demo.csv · app theme from the optional codesplash helper
# Half-normal plot of effects — Codesplash Chart Lab (recipe "half-normal-effects")
# 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("half-normal-effects-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["active"]] <- as.logical(df[["active"]])
df[["effect"]] <- factor(df[["effect"]])
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
e_col <- "effect"
a_col <- "|effect|"
q_col <- "half-normal quantile"
s_col <- "active"
d <- data.frame(e = as.character(df[[e_col]]), a = abs(df[[a_col]]), q = df[[q_col]], sig = as.logical(df[[s_col]]))
slope <- with(d[!d$sig, ], sum(a * q) / sum(a^2)) # least squares through the origin
p <- ggplot(d, aes(a, q)) + geom_abline(slope = slope, intercept = 0, colour = ref_col, linetype = "dashed") +
geom_point(aes(colour = sig), size = 2.4) + geom_text(data = d[d$sig, ], aes(label = e), hjust = 1.4, fontface = "bold", size = 3.2) +
scale_colour_manual(values = c("grey55", cs_cat[2]), labels = c("inactive", "active"), name = NULL) +
labs(x = a_col, y = q_col) + theme_cs
print(p)Needs ggplot2 · reads half-normal-effects-demo.csv · app theme from the optional codesplashr helper