"""The two dot-and-whisker charts on the factchecked.science page, from our derived results. python3 -I chart_rows.py [] Chart 1: K (the share of the model's trend) under each analysis choice, with 95% ranges (Student's t with each fit's residual degrees of freedom; the paper's own value with 1.96). Chart 2: the gap between the eras' mean heights, in km, with 95% ranges (normal, except the season-level Welch test, which uses t). Rows marked post hoc were added after our first run. Derived numbers only. The optional snippet is the HTML the page uses for the two charts. """ import json import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) import refit as rf # noqa: E402 (our own module: numerics only) def tq(df, p=0.05): lo, hi = 0.0, 60.0 for _ in range(200): mid = (lo + hi) / 2 if rf.p_t(mid, df) > p: lo = mid else: hi = mid return (lo + hi) / 2 def row(label, sub, est, se, q, kind, note=""): return {"label": label, "sub": sub, "est": est, "se": se, "q": q, "lo": est - q * se, "hi": est + q * se, "kind": kind, "note": note} def main(): R = json.load(open(sys.argv[1], encoding="utf-8")) P = json.load(open(sys.argv[2], encoding="utf-8")) k = [] k.append(row("The paper", "Table 1", 0.52, 0.18, 1.959964, "paper")) k.append(row("Our rebuild", "the paper’s model, 70 nights", R["R1"]["K"]["est"], R["R1"]["K"]["se"], tq(R["R1"]["df"]), "reg")) k.append(row("With the sunspot term", "as in Table 1", R["R1b"]["K"]["est"], R["R1b"]["K"]["se"], tq(R["R1b"]["df"]), "reg")) k.append(row("Nights grouped by summer", "clustered errors, 21 summers", R["R3a"]["K"]["est"], R["R3a"]["K_se_cr1"], tq(R["R3a"]["n_clusters"] - 1), "reg")) k.append(row("Each summer counted once", "21 summer averages", R["R3b"]["K"], R["R3b"]["K_se"], tq(R["R3b"]["df"]), "reg")) names = {1890: "Without 1890", 1932: "Without 1932–34", 1958: "Without 1958–67", 1979: "Without 1979–92"} for r in R["R5"]: n = r["n"] k.append(row(names[r["dropped_epoch"][0]], f"{n} nights", r["K"], r["K_se"], tq(n - 4), "reg")) r6 = [r for r in R["R6"] if r["dropped"] == "2025+2026"][0] k.append(row("Without 2025 and 2026", f"{r6['n']} nights", r6["K"], r6["K_se"], tq(r6["n"] - 4), "reg")) k.append(row("No seasonal terms", "70 nights", R["R7a"]["est"], R["R7a"]["se"], tq(R["R7a"]["df"]), "reg")) k.append(row("Season fitted on 2020s nights only", "70 nights", R["R7d"]["est"], R["R7d"]["se"], tq(R["R7d"]["df"]), "reg")) k.append(row("Adding the colour-based heights", "91 nights", R["R9"]["K"]["est"], R["R9"]["K"]["se"], tq(R["R9"]["df"]), "reg")) g = [] g.append(row("Simple difference", "each night counted once", R["R2"]["diff"], R["R2"]["diff_se"], 1.959964, "reg")) g.append(row("Each summer counted once", "14 summers against 7", R["R3c"]["diff"], R["R3c"]["se"], tq(R["R3c"]["df"]), "reg")) z = {round(x["tau"], 2): x for x in P["P3"]["z_by_tau"]} g.append(row("By era, no offset between eras", "random effects, τ = 0", z[0.0]["d"], z[0.0]["se"], 1.959964, "reg")) g.append(row("By era, offsets of 0.25 km", "τ = 0.25 km", z[0.25]["d"], z[0.25]["se"], 1.959964, "post")) g.append(row("By era, offsets of 0.5 km", "τ = 0.5 km", z[0.5]["d"], z[0.5]["se"], 1.959964, "post")) for name, sub in (("2025-2026", "33 nights"), ("2020-2024", "15 nights")): x = P["P6"][name] g.append(row(f"{name.replace('-', '–')} nights only", sub, x["diff"], x["se"], 1.959964, "post")) model_gap = P["P5"]["model_change_km"] out = {"K_rows": k, "gap_rows": g, "model_gap_km": model_gap, "K_axis": [-0.2, 1.4], "gap_axis": [-0.5, 2.0]} with open(sys.argv[3], "w", encoding="utf-8", newline="\n") as f: json.dump(out, f, indent=1, ensure_ascii=False) if len(sys.argv) > 4: with open(sys.argv[4], "w", encoding="utf-8", newline="\n") as f: f.write(snippet(k, out["K_axis"], [0.0, 1.0], [-0.2, 0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4], "K", 2)) f.write("\n\n") f.write(snippet(g, out["gap_axis"], [0.0, model_gap], [-0.5, 0, 0.5, 1.0, 1.5, 2.0], "km", 2)) f.write("\n") for r in k + g: print(f'{r["label"]:<36} {r["est"]:7.3f} [{r["lo"]:6.3f}, {r["hi"]:6.3f}] q={r["q"]:.3f} {r["kind"]}') def fmt(v, nd): s = f"{v:.{nd}f}" return s.replace("-", "−") def snippet(rows, axis, refs, ticks, unit, nd): a, b = axis pos = lambda v: 100.0 * (v - a) / (b - a) lines = ['
'] grid = "".join(f'' for t in ticks if t not in refs) grid += f'' grid += f'' lines.append(f'') for r in rows: cls = "dw-row" + (" is-ink" if r["kind"] == "paper" else "") + (" is-open" if r["kind"] == "post" else "") val = f'{fmt(r["est"], nd)} ({fmt(r["lo"], nd)} to {fmt(r["hi"], nd)})' sp = lambda v: f"minus {abs(v):.2f}" if v < 0 else f"{v:.2f}" aria = f'{r["label"]}, {r["sub"]}: {sp(r["est"])}, 95% range {sp(r["lo"])} to {sp(r["hi"])}' if r["kind"] == "post": aria += ", a check added after our first run" lo, hi = max(a, r["lo"]), min(b, r["hi"]) lines.append( f'

{r["label"]} {r["sub"]}

' f'' f'{val}
') lines.append("
") spans = [] for t in ticks: c = ' class="is-start"' if t == ticks[0] else ' class="is-end"' if t == ticks[-1] else "" lab = fmt(t, 1) if unit == "K" else (fmt(t, 1) if t % 1 else str(int(t))) spans.append(f'{lab}') lines.append(f'') return "\n".join(lines) if __name__ == "__main__": main()