Skip to content
svgdist-id-grid

Distribution ID plot

Which lifetime family fits: Weibull, log-normal, exponential or log-logistic?

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

How to read it

  1. Each panel is one family's probability paper, and the panel title gives how well the points follow its line.
  2. Look for the panel where the points lie straightest, across the whole range.
  3. Read it with the AIC table: agreement between them is stronger evidence than either alone.
  1. Callout 1: The family and how straight its points are: r nearer 1 is straighter.
  2. Callout 2: A family that fits: the points stay on the line.
  3. Callout 3: Points bending away from the line: this family misses the early failures.

Watch out

  • With few failures several panels look straight. Compare the B-lives before you pick one, because the choice matters most in the tails.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Median ranks with adjusted order numbers on each paper; r is the plot correlation of the points.
  • Lines are the engine's maximum-likelihood fits when it sends them, otherwise rank regression.
  • Gamma, generalized gamma and Gompertz have no straight-line paper, so they appear only in the AIC table.
# Distribution ID plot — Codesplash Chart Lab (recipe "dist-id-grid")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats

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("dist-id-grid-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")
T = "hours"
E = "failed"
F = None
FAM = None
def median_ranks(t, e=None):
    """Johnson's adjusted order numbers with Benard's median ranks; failures before suspensions at a tie."""
    t = np.asarray(t, dtype=float)
    e = np.ones(t.size, dtype=bool) if e is None else np.asarray(e, dtype=float) > 0
    keep = np.isfinite(t) & (t > 0)
    t, e = t[keep], e[keep]
    o = np.lexsort((~e, t))
    t, e = t[o], e[o]
    n, prev, ts, fs = t.size, 0.0, [], []
    for i in range(n):
        if e[i]:
            prev += (n + 1 - prev) / (n - i + 1)
            ts.append(t[i])
            fs.append((prev - 0.3) / (n + 0.4))
    return np.array(ts), np.array(fs)
def paper_x(paper, t):
    return t if paper in ("exponential", "normal") else np.log(t)

def paper_y(paper, f):
    if paper == "weibull":
        return np.log(-np.log1p(-f))
    if paper == "exponential":
        return -np.log1p(-f)
    if paper == "loglogistic":
        return np.log(f / (1 - f))
    return stats.norm.ppf(f)

def paper_line(rows, paper, x):
    """The engine's fitted curve for this family when present, else rank regression of paper y on paper x."""
    if rows is not None and len(rows):
        curve = rows[(rows[F] > 0) & (rows[F] < 1)].sort_values(T)
        return paper_x(paper, curve[T].to_numpy(float)), paper_y(paper, curve[F].to_numpy(float))
    xs, ys = x
    b, a = np.polyfit(xs, ys, 1)
    return np.array([xs.min(), xs.max()]), a + b * np.array([xs.min(), xs.max()])

def split_rows(df):
    is_data = df[FAM].astype(str).str.lower().eq("data") if FAM else pd.Series(True, index=df.index)
    return df[is_data], df[~is_data]
sample, curves = split_rows(df)
tt, ff = median_ranks(sample[T], sample[E] if E else None)
fig, axes = plt.subplots(2, 2, figsize=(9, 6))
for i, (ax, paper) in enumerate(zip(axes.flat, ["weibull", "lognormal", "exponential", "loglogistic"])):
    xs, ys = paper_x(paper, tt), paper_y(paper, ff)
    lx, ly = paper_line(curves[curves[FAM].astype(str) == paper] if FAM and F else None, paper, (xs, ys))
    ax.plot(lx, ly, color=REF, linewidth=1.4)
    ax.scatter(xs, ys, s=12, color=PALETTE[i % len(PALETTE)], alpha=0.8)
    ax.set_title(f"{paper}: r = {np.corrcoef(xs, ys)[0, 1]:.3f}", fontsize=9, loc="left")
plt.tight_layout()
plt.show()

Needs pandas, numpy, matplotlib, scipy · reads dist-id-grid-demo.csv · app theme from the optional codesplash helper