#!/usr/bin/env python3 # SPDX-License-Identifier: MIT # Copyright (c) 2026 Canopulse # Licensed under the MIT License. The full text is in LICENSE.md in this package. """Weighting-sensitivity checks for California UCRI CA_2026.10. Run by Canopulse. These are Canopulse's own checks, not an independent review. They test how much the fully scored ranking depends on the published weights (weight sensitivity only). They do not test whether UCRI predicts any outcome. Standard library only (Python 3.8+, no numpy or pandas), deterministic (fixed seed). Random draws are bit-identical on the same Python version. Usage (from the package folder): python3 robustness/ucri_robustness.py [--csv PATH] [--out DIR] --csv tract CSV to read. Default: ../ucri_ca_2026_10_tracts.csv relative to this script, i.e. the CSV in this package. --out folder for results.json, tract_stability.csv and REPORT.md (numbers in the report are filled in from the results). Default: the folder that holds this script, which overwrites the published files. Use, for example, --out rerun to write a fresh copy and compare it with them. """ from __future__ import annotations import csv import json import math import argparse import platform import random import statistics import sys from pathlib import Path HERE = Path(__file__).resolve().parent PACKAGE = HERE.parent CSV_NAME = "ucri_ca_2026_10_tracts.csv" COMPONENTS = ["cds", "hes", "iss", "svs", "ebs"] PUBLISHED = {"cds": 0.25, "hes": 0.25, "iss": 0.15, "svs": 0.20, "ebs": 0.15} THRESHOLDS = {"Low": 30.0, "Moderate": 44.0, "High": 56.9, "Extreme": 70.3} SEED = 20261008 DRAWS = 1000 # Dirichlet concentration: alpha_i = CONCENTRATION * published weight_i. # SD of weight i is sqrt(w_i (1 - w_i) / (CONCENTRATION + 1)): about 0.043 for # the 0.25 weights, 0.040 for 0.20 and 0.036 for 0.15, i.e. roughly 17% to 24% # of each weight, comparable to the +/-20% one-at-a-time scenarios. CONCENTRATION = 100.0 EPSILON = 2.220446049250313e-16 REGIONS = { "Bay Area": ["Alameda", "Contra Costa", "Marin", "Napa", "San Francisco", "San Mateo", "Santa Clara", "Solano", "Sonoma"], "Southern California coast": ["Los Angeles", "Orange", "San Diego", "Ventura", "Santa Barbara"], "Inland Empire and desert": ["Riverside", "San Bernardino", "Imperial", "Inyo"], "San Joaquin Valley": ["Fresno", "Kern", "Kings", "Madera", "Merced", "San Joaquin", "Stanislaus", "Tulare"], "Sacramento region": ["Sacramento", "Placer", "El Dorado", "Yolo", "Sutter", "Yuba"], "Central Coast": ["Monterey", "San Benito", "San Luis Obispo", "Santa Cruz"], "Northern, Sierra and rural": ["Alpine", "Amador", "Butte", "Calaveras", "Colusa", "Del Norte", "Glenn", "Humboldt", "Lake", "Lassen", "Mariposa", "Mendocino", "Modoc", "Mono", "Nevada", "Plumas", "Shasta", "Sierra", "Siskiyou", "Tehama", "Trinity", "Tuolumne"], } def round1(value: float) -> float: return math.floor((value + EPSILON) * 10 + 0.5) / 10 def quantile(sorted_values, q): index = (len(sorted_values) - 1) * q lower, upper = math.floor(index), math.ceil(index) return sorted_values[lower] + (sorted_values[upper] - sorted_values[lower]) * (index - lower) def priority_for(score, thresholds): for label in ("Extreme", "High", "Moderate", "Low"): if score >= thresholds[label]: return label return "Very Low" def average_ranks(values): order = sorted(range(len(values)), key=values.__getitem__) ranks = [0.0] * len(values) i = 0 while i < len(order): j = i while j + 1 < len(order) and values[order[j + 1]] == values[order[i]]: j += 1 avg = (i + j) / 2 + 1 for k in range(i, j + 1): ranks[order[k]] = avg i = j + 1 return ranks def pearson(x, y): n = len(x) mx, my = sum(x) / n, sum(y) / n sxy = sxx = syy = 0.0 for a, b in zip(x, y): da, db = a - mx, b - my sxy += da * db sxx += da * da syy += db * db return sxy / math.sqrt(sxx * syy) def spearman(x, y): return pearson(average_ranks(x), average_ranks(y)) def ordinal_ranks(scores, geoids): order = sorted(range(len(scores)), key=lambda i: (-scores[i], geoids[i])) ranks = [0] * len(scores) for position, i in enumerate(order): ranks[i] = position + 1 return ranks def top_mask(scores, q): cut = round1(quantile(sorted(scores), q)) return [s >= cut for s in scores] def pct(numerator, denominator): return numerator / denominator if denominator else None def summarize(values): ordered = sorted(values) return { "min": round(ordered[0], 4), "p5": round(quantile(ordered, 0.05), 4), "median": round(quantile(ordered, 0.5), 4), "mean": round(sum(ordered) / len(ordered), 4), "p95": round(quantile(ordered, 0.95), 4), "max": round(ordered[-1], 4), } class Base: def __init__(self, rows): self.rows = rows self.geoids = [r["geoid"] for r in rows] self.comp = [[float(r[c]) for c in COMPONENTS] for r in rows] self.score = [float(r["ucri"]) for r in rows] self.priority = [r["priority"] for r in rows] self.rank = [int(r["state_rank"]) for r in rows] self.top20 = [p == "Extreme" for p in self.priority] self.top10 = top_mask(self.score, 0.9) self.region = [region_of(r["county"]) for r in rows] self.n = len(rows) def scenario_scores(self, weights): w = [weights[c] for c in COMPONENTS] out = [] for values in self.comp: total = 0.0 for v, wi in zip(values, w): total += v * wi out.append(round1(total)) return out def evaluate(self, weights, full=True): scores = self.scenario_scores(weights) top20 = top_mask(scores, 0.8) top10 = top_mask(scores, 0.9) n20 = sum(self.top20) n10 = sum(self.top10) kept20 = sum(1 for a, b in zip(self.top20, top20) if a and b) kept10 = sum(1 for a, b in zip(self.top10, top10) if a and b) result = { "spearman": spearman(self.score, scores), "top10_retention": kept10 / n10, "top20_retention": kept20 / n20, "priority_change_share": sum( priority_for(s, THRESHOLDS) != p for s, p in zip(scores, self.priority)) / self.n, } if full: sorted_scores = sorted(scores) own = {label: round1(quantile(sorted_scores, q)) for label, q in (("Low", 0.2), ("Moderate", 0.4), ("High", 0.6), ("Extreme", 0.8))} result["priority_change_share_requintiled"] = sum( priority_for(s, own) != p for s, p in zip(scores, self.priority)) / self.n ranks = ordinal_ranks(scores, self.geoids) result["median_abs_rank_change"] = statistics.median(abs(a - b) for a, b in zip(ranks, self.rank)) result["region_top20_retention"] = {} result["region_top20_count"] = {} for name in REGIONS: result["region_top20_count"][name] = sum( 1 for i in range(self.n) if self.region[i] == name and top20[i]) base = [i for i in range(self.n) if self.region[i] == name and self.top20[i]] result["region_top20_retention"][name] = pct(sum(1 for i in base if top20[i]), len(base)) return result, top20, top10 def region_of(county): for name, counties in REGIONS.items(): if county in counties: return name raise SystemExit(f"County {county} is not assigned to a region") def normalized(weights): total = sum(weights.values()) return {c: weights.get(c, 0.0) / total for c in COMPONENTS} def rounded(result): out = {} for key, value in result.items(): if isinstance(value, dict): out[key] = {k: (round(v, 4) if isinstance(v, float) else v) for k, v in value.items()} elif isinstance(value, float): out[key] = round(value, 4) else: out[key] = value return out def parse_args(argv=None): parser = argparse.ArgumentParser(description="Weighting-sensitivity checks for UCRI CA_2026.10.") parser.add_argument("--csv", type=Path, default=PACKAGE / CSV_NAME, help="tract CSV (default: ../%s next to this script)" % CSV_NAME) parser.add_argument("--out", type=Path, default=HERE, help="output folder (default: the folder that holds this script)") return parser.parse_args(argv) def main(argv=None): args = parse_args(argv) csv_path = args.csv out_dir = args.out all_counties = sorted(c for counties in REGIONS.values() for c in counties) if len(all_counties) != 58 or len(set(all_counties)) != 58: raise SystemExit("Region lists must cover the 58 counties exactly once") with csv_path.open(newline="", encoding="utf-8") as handle: rows = [r for r in csv.DictReader(handle) if r["score_kind"] == "frozen"] base = Base(rows) print(f"fully scored tracts: {base.n:,}; published top class: {sum(base.top20):,}; published top 10%: {sum(base.top10):,}") # Sanity: published weights reproduce the release exactly. check, _, _ = base.evaluate(PUBLISHED) assert abs(check["spearman"] - 1) < 1e-12 and check["priority_change_share"] == 0, check scenarios = {"equal_weights": normalized({c: 1.0 for c in COMPONENTS})} for c in COMPONENTS: for label, factor in (("plus20", 1.2), ("minus20", 0.8)): w = dict(PUBLISHED) w[c] *= factor scenarios[f"{c}_{label}"] = normalized(w) for c in COMPONENTS: scenarios[f"drop_{c}"] = normalized({k: v for k, v in PUBLISHED.items() if k != c}) scenario_results = {} for name, weights in scenarios.items(): result, _, _ = base.evaluate(weights) scenario_results[name] = {"weights": {c: round(w, 4) for c, w in weights.items()}, **rounded(result)} print(f"{name:16s} rho={result['spearman']:.4f} top10={result['top10_retention']:.3f} " f"top20={result['top20_retention']:.3f} class={result['priority_change_share']:.3f} " f"medrank={result['median_abs_rank_change']}") # Monte Carlo rng = random.Random(SEED) metrics = {k: [] for k in ("spearman", "top10_retention", "top20_retention", "priority_change_share", "median_abs_rank_change")} region_draws = {name: [] for name in REGIONS} region_counts = {name: [] for name in REGIONS} weight_draws = {c: [] for c in COMPONENTS} in20 = [0] * base.n in10 = [0] * base.n for draw in range(DRAWS): gammas = {c: rng.gammavariate(CONCENTRATION * PUBLISHED[c], 1.0) for c in COMPONENTS} weights = normalized(gammas) for c in COMPONENTS: weight_draws[c].append(weights[c]) result, top20, top10 = base.evaluate(weights) for k in metrics: metrics[k].append(float(result[k])) for name, value in result["region_top20_retention"].items(): region_draws[name].append(value) for name, value in result["region_top20_count"].items(): region_counts[name].append(value) for i in range(base.n): in20[i] += top20[i] in10[i] += top10[i] if (draw + 1) % 100 == 0: print(f" draws {draw + 1}/{DRAWS}", file=sys.stderr) share20 = [x / DRAWS for x in in20] share10 = [x / DRAWS for x in in10] pub_extreme = [i for i in range(base.n) if base.top20[i]] stability = { "tracts_top20_in_at_least_95pct_of_draws": sum(s >= 0.95 for s in share20), "tracts_top20_in_every_draw": sum(s == 1.0 for s in share20), "published_extreme_count": len(pub_extreme), "published_extreme_top20_in_at_least_95pct": sum(share20[i] >= 0.95 for i in pub_extreme), "published_extreme_top20_in_at_least_50pct": sum(share20[i] >= 0.5 for i in pub_extreme), "published_extreme_top20_in_under_50pct": sum(share20[i] < 0.5 for i in pub_extreme), "not_published_extreme_but_top20_in_at_least_50pct": sum( share20[i] >= 0.5 for i in range(base.n) if not base.top20[i]), "tracts_ever_top20": sum(s > 0 for s in share20), "tracts_top20_in_5_to_95pct_of_draws": sum(0.05 <= s < 0.95 for s in share20), "tracts_top10_in_at_least_95pct_of_draws": sum(s >= 0.95 for s in share10), } # Component correlation (Spearman) among the five components and with UCRI. columns = {c: [v[i] for v in base.comp] for i, c in enumerate(COMPONENTS)} matrix = {a.upper(): {b.upper(): round(spearman(columns[a], columns[b]), 4) for b in COMPONENTS} for a in COMPONENTS} with_ucri = {c.upper(): round(spearman(columns[c], base.score), 4) for c in COMPONENTS} high_pairs = [ {"pair": f"{a.upper()}-{b.upper()}", "spearman": matrix[a.upper()][b.upper()]} for i, a in enumerate(COMPONENTS) for b in COMPONENTS[i + 1:] if abs(matrix[a.upper()][b.upper()]) > 0.7 ] equal = scenario_results["equal_weights"] regions = {} for name, counties in REGIONS.items(): idx = [i for i in range(base.n) if base.region[i] == name] regions[name] = { "counties": counties, "fully_scored_tracts": len(idx), "published_extreme": sum(base.top20[i] for i in idx), "published_extreme_mean_components": { c.upper(): round(statistics.mean(base.comp[i][k] for i in idx if base.top20[i]), 1) for k, c in enumerate(COMPONENTS) } if any(base.top20[i] for i in idx) else None, "equal_weights_top20_retention": equal["region_top20_retention"][name], "equal_weights_top20_count": equal["region_top20_count"][name], "monte_carlo_top20_count": summarize(region_counts[name]), "monte_carlo_top20_retention": summarize([v for v in region_draws[name] if v is not None]) if any(v is not None for v in region_draws[name]) else None, } one_at_a_time = [scenario_results[f"{c}_{s}"] for c in COMPONENTS for s in ("plus20", "minus20")] leave_one_out = {c.upper(): scenario_results[f"drop_{c}"] for c in COMPONENTS} results = { "schema": "canopulse.ucri_robustness.v1", "release": "CA_2026.10", "run_by": "Canopulse", "independent_review": False, "label": "Run by Canopulse. Not an independent review.", "scope": "Weighting sensitivity of the fully scored ranking. Not a test of whether UCRI predicts outcomes.", "script": "robustness/ucri_robustness.py", "input": CSV_NAME, "tracts": base.n, "published_top10_count": sum(base.top10), "published_top20_count": sum(base.top20), "python_version": platform.python_version(), "published_weights": PUBLISHED, "published_thresholds": THRESHOLDS, "definitions": { "scenario_score": "Sum of component x renormalized weight, rounded half up to 0.1 like the release.", "top20": "Published: top class (stored value Extreme, displayed as Very high screening priority; UCRI >= 70.3, 1,814 tracts). Scenario: score >= its own 80th percentile (linear interpolation, rounded to 0.1).", "top10": "Score >= its own 90th percentile (linear interpolation, rounded to 0.1), for published and scenario scores alike.", "retention": "Share of the published top set that is also in the scenario top set.", "priority_change_share": "Share of the 9,041 tracts whose class changes when the scenario score is classified with the published thresholds (30, 44, 56.9, 70.3).", "priority_change_share_requintiled": "Same, but each scenario is classified with its own quintile thresholds.", "median_abs_rank_change": "Median of |scenario statewide rank - published statewide rank|, ranks 1 to 9,041, ties by GEOID.", "spearman": "Spearman rank correlation between scenario and published scores (average ranks for ties).", }, "scenarios": scenario_results, "one_at_a_time_summary": { "min_spearman": min(r["spearman"] for r in one_at_a_time), "min_top20_retention": min(r["top20_retention"] for r in one_at_a_time), "max_priority_change_share": max(r["priority_change_share"] for r in one_at_a_time), "max_median_abs_rank_change": max(r["median_abs_rank_change"] for r in one_at_a_time), }, "leave_one_out": leave_one_out, "monte_carlo": { "draws": DRAWS, "seed": SEED, "distribution": "Dirichlet(alpha = concentration x published weights)", "concentration": CONCENTRATION, "weight_draw_summary": { c.upper(): {**summarize(weight_draws[c]), "mean_abs_relative_deviation": round( sum(abs(w - PUBLISHED[c]) for w in weight_draws[c]) / DRAWS / PUBLISHED[c], 4)} for c in COMPONENTS }, "metrics": {k: summarize(v) for k, v in metrics.items()}, "stability": stability, }, "component_spearman": matrix, "component_spearman_with_ucri": with_ucri, "component_pairs_above_0_7": high_pairs, "regions": regions, } out_dir.mkdir(parents=True, exist_ok=True) (out_dir / "results.json").write_text(json.dumps(results, indent=2) + "\n", encoding="utf-8", newline="\n") with (out_dir / "tract_stability.csv").open("w", newline="", encoding="utf-8") as handle: writer = csv.writer(handle, lineterminator="\n") writer.writerow(["geoid", "county", "region", "ucri", "priority", "state_rank", "share_of_draws_top20", "share_of_draws_top10"]) for i, r in enumerate(rows): writer.writerow([r["geoid"], r["county"], base.region[i], r["ucri"], r["priority"], r["state_rank"], f"{share20[i]:.3f}", f"{share10[i]:.3f}"]) (out_dir / "REPORT.md").write_text(render_report(results), encoding="utf-8", newline="\n") print(json.dumps({k: results[k] for k in ("one_at_a_time_summary", "component_pairs_above_0_7")}, indent=2)) print(json.dumps(results["monte_carlo"]["metrics"], indent=2)) print(json.dumps(stability, indent=2)) print(json.dumps({k: {kk: vv for kk, vv in v.items() if kk != "counties"} for k, v in regions.items()}, indent=2)) print(json.dumps(matrix, indent=2), json.dumps(with_ucri)) def p1(x): if x is None: return "n/a" text = f"{x * 100:.1f}%" return text.replace(".0%", "%") if x in (0, 1) else text def n0(x): return f"{int(round(x)):,}" def render_report(r): sc = r["scenarios"] mc = r["monte_carlo"] m = mc["metrics"] st = mc["stability"] oat = r["one_at_a_time_summary"] names = {"cds": "CDS", "hes": "HES", "iss": "ISS", "svs": "SVS", "ebs": "EBS"} ext = st["published_extreme_count"] min_top10_oat = min(sc[f"{c}_{s}"]["top10_retention"] for c in COMPONENTS for s in ("plus20", "minus20")) loo = r["leave_one_out"] loo_class = sorted(v["priority_change_share"] for v in loo.values()) rel = sorted(v["mean_abs_relative_deviation"] for v in mc["weight_draw_summary"].values()) w25 = mc["weight_draw_summary"]["CDS"] corr = r["component_spearman"] keys = list(corr) pairs = [(a, b, corr[a][b]) for i, a in enumerate(keys) for b in keys[i + 1:]] strongest = max(pairs, key=lambda t: t[2]) with_ucri = sorted(r["component_spearman_with_ucri"].items(), key=lambda kv: -kv[1]) regions = r["regions"] region_order = sorted(regions, key=lambda k: -regions[k]["published_extreme"]) ie = regions["Inland Empire and desert"] ie_mean = ie["published_extreme_mean_components"] small = [k for k in region_order if regions[k]["published_extreme"] < 30] def row(label, v): return (f"| {label} | {v['spearman']:.4f} | {p1(v['top10_retention'])} | {p1(v['top20_retention'])} | " f"{p1(v['priority_change_share'])} | {n0(v['median_abs_rank_change'])} |") lines = [] add = lines.append add("# UCRI CA_2026.10: internal robustness checks") add("") add("**Run by Canopulse. Not an independent review. Tests weight sensitivity only.**") add("") add("Class names: the stored class value \"Extreme\" is displayed as \"Very high screening priority\" " "(top fifth statewide) on the Canopulse website and in its reports. This report calls it the top class; " "the data files keep the stored value.") add("") add("Generated by `robustness/ucri_robustness.py`, published in this package (standard library Python, " f"fixed seed {mc['seed']}). Machine-readable results: `results.json`. Per-tract stability: " "`tract_stability.csv`. Every number below is filled in from `results.json` by the script.") add("") add("## What was tested") add("") add("UCRI combines five statewide percentile components with fixed weights (0.25 canopy deficit, " "0.25 heat, 0.15 impervious, 0.20 social vulnerability, 0.15 environmental burden). The weights " "are a judgment, not an estimate from data. These checks ask one question: **if the weights were " "reasonably different, would the same tracts come out on top?**") add("") add(f"All checks use the {n0(r['tracts'])} fully scored tracts and the released component values. " "Every alternative score is computed and rounded exactly like the released score, then compared " "with the published ranking:") add("") add("* **Spearman correlation** of the two rankings (1 means identical order).") add(f"* **Top 10% and top 20% retention**: of the tracts in the published top 10% ({n0(r['published_top10_count'])} " f"tracts) or top 20% (the {n0(ext)} tracts in the top class), the share that stays in the alternative's own " "top 10% or top 20%.") add("* **Class change**: the share of all tracts whose priority class changes when the alternative " "score is classified with the published thresholds (30, 44, 56.9, 70.3).") add(f"* **Median rank change**: the typical move in statewide rank, out of {n0(r['tracts'])}.") add("") add("## Results") add("") header = "| Scenario | Spearman | Top 10% kept | Top 20% kept | Class change | Median rank change |" rule = "|---|---|---|---|---|---|" add("### Equal weights (0.2 each)") add("") add(header) add(rule) add(row("Equal weights", sc["equal_weights"])) add("") add("### Each weight 20% higher or lower (others rescaled to sum to 1)") add("") add(f"Across all ten scenarios: Spearman at least {oat['min_spearman']:.4f}, top 20% retention at least " f"{p1(oat['min_top20_retention'])}, top 10% retention at least {p1(min_top10_oat)}, class change at most " f"{p1(oat['max_priority_change_share'])}, median rank change at most " f"{n0(oat['max_median_abs_rank_change'])} places.") add("") add(header) add(rule) for c in COMPONENTS: add(row(f"{names[c]} +20%", sc[f"{c}_plus20"])) add(row(f"{names[c]} -20%", sc[f"{c}_minus20"])) add("") add("### Leave one component out (remaining weights rescaled)") add("") add(header.replace("Scenario", "Dropped")) add(rule) for c in COMPONENTS: add(row(names[c], sc[f"drop_{c}"])) add("") add(f"Every component matters: removing any one changes {p1(loo_class[0])} to {p1(loo_class[-1])} of " "priority classes. Dropping one of the two 0.25 components (canopy deficit or heat) moves the most " "tracts, as expected from their weights.") add("") add(f"### {n0(mc['draws'])} random weightings") add("") add(f"Weights were drawn from a Dirichlet distribution centered on the published weights, with " f"concentration {mc['concentration']:g} (alpha = {mc['concentration']:g} x published weight). The typical " f"draw moves each weight by {p1(rel[0])} to {p1(rel[-1])} of its value (mean absolute relative change); " f"the 0.25 weights fall between {w25['p5']:.2f} and {w25['p95']:.2f} in 90% of draws.") add("") add("| Metric | Worst draw | 5th percentile, worst side | Median |") add("|---|---|---|---|") add(f"| Spearman | {m['spearman']['min']:.3f} | {m['spearman']['p5']:.3f} | {m['spearman']['median']:.3f} |") add(f"| Top 10% kept | {p1(m['top10_retention']['min'])} | {p1(m['top10_retention']['p5'])} | " f"{p1(m['top10_retention']['median'])} |") add(f"| Top 20% kept | {p1(m['top20_retention']['min'])} | {p1(m['top20_retention']['p5'])} | " f"{p1(m['top20_retention']['median'])} |") add(f"| Class change | {p1(m['priority_change_share']['max'])} | {p1(m['priority_change_share']['p95'])} | " f"{p1(m['priority_change_share']['median'])} |") add(f"| Median rank change | {n0(m['median_abs_rank_change']['max'])} | " f"{n0(m['median_abs_rank_change']['p95'])} | {n0(m['median_abs_rank_change']['median'])} |") add("") add("For class change and rank change the worst side is the high end (maximum and 95th percentile).") add("") add("Tract-level stability:") add("") outside95 = st["tracts_top20_in_at_least_95pct_of_draws"] - st["published_extreme_top20_in_at_least_95pct"] add(f"* **{n0(st['published_extreme_top20_in_at_least_95pct'])} of the {n0(ext)} top-class tracts " f"({p1(st['published_extreme_top20_in_at_least_95pct'] / ext)})** are in the top 20% in at least 95% of " f"draws; {n0(st['tracts_top20_in_every_draw'])} are in it in every draw. " + ("No tract outside the published top class reaches 95%." if outside95 == 0 else f"{n0(outside95)} tracts outside the published top class reach 95%.")) add(f"* {n0(st['published_extreme_top20_in_at_least_50pct'])} of the {n0(ext)} top-class tracts are in the top 20% " f"in at least half of the draws. {n0(st['published_extreme_top20_in_under_50pct'])} fall out more often than " f"not, and {n0(st['not_published_extreme_but_top20_in_at_least_50pct'])} tracts outside the top class get in more " "often than not.") add(f"* {n0(st['tracts_top20_in_5_to_95pct_of_draws'])} tracts sit on the boundary (top 20% in 5% to 95% of " "draws). For these the top-class label depends on the exact weights and is best read as near the " f"top-class threshold (UCRI {r['published_thresholds']['Extreme']:g}).") add("") add(f"### Component correlation (Spearman, {n0(r['tracts'])} tracts)") add("") add("| | " + " | ".join(keys) + " |") add("|---" * (len(keys) + 1) + "|") for a in keys: add(f"| {a} | " + " | ".join("1" if a == b else f"{corr[a][b]:.2f}" for b in keys) + " |") add("") if r["component_pairs_above_0_7"]: add("Pairs above 0.7 (possible redundancy): " + ", ".join( f"{p['pair']} ({p['spearman']:.2f})" for p in r["component_pairs_above_0_7"]) + ".") else: add("No pair exceeds 0.7, so no two components are close to redundant.") add(f"The strongest link is {strongest[0]} with {strongest[1]} ({strongest[2]:.2f}). Correlation of each " "component with UCRI: " + ", ".join(f"{k} {v:.2f}" for k, v in with_ucri) + ".") add("") add("### By region") add("") add("Retention is measured statewide (a tract must stay in the statewide top 20%), then broken down by " "where the tract is. The random-weighting column is the median over draws.") add("") add("| Region | Fully scored | Top class (published) | Top 20% kept, equal weights | Top 20% kept, random weights | " "Top 20% count, equal weights |") add("|---|---|---|---|---|---|") for k in region_order: v = regions[k] mcv = v["monte_carlo_top20_retention"] add(f"| {k} | {n0(v['fully_scored_tracts'])} | {n0(v['published_extreme'])} | " f"{p1(v['equal_weights_top20_retention'])} | {p1(mcv['median']) if mcv else 'n/a'} | " f"{n0(v['equal_weights_top20_count'])} |") add("") add("County lists:") add("") for k, counties in REGIONS.items(): add(f"* {k}: {', '.join(counties)}.") add("") add(f"Inland Empire and desert top-class tracts score high on heat (mean HES {ie_mean['HES']:.0f}) and canopy " f"deficit ({ie_mean['CDS']:.0f}) but lower on impervious surface ({ie_mean['ISS']:.0f}). Equal weights " "lower heat and canopy from 0.25 to 0.20 and raise impervious from 0.15 to 0.20, so this region is the " f"most exposed to that particular change: {p1(ie['equal_weights_top20_retention'])} of its top-class tracts " f"stay in the top 20%, against a median of {p1(ie['monte_carlo_top20_retention']['median'])} under moderate " "random weightings.") add("") add("These rows rest on very few top-class tracts, so their percentages are not meaningful on their own: " + "; ".join(f"{k} ({regions[k]['published_extreme']} in the top class)" for k in small) + ".") add("") add("## What these checks show") add("") add(f"* The published ranking is not fragile to moderate weight changes. Changing any one weight by 20% keeps " f"at least {p1(oat['min_top20_retention'])} of the top-class tracts and moves the typical tract by at most " f"{n0(oat['max_median_abs_rank_change'])} places out of {n0(r['tracts'])}.") add(f"* {p1(st['published_extreme_top20_in_at_least_95pct'] / ext)} of top-class tracts are in the top 20% under " f"at least 95% of moderate random weightings. The {n0(st['tracts_top20_in_5_to_95pct_of_draws'])} boundary " "tracts should be treated as near the threshold.") add("* The five components carry distinct information, and removing any one changes a large share of classes.") add("* Of the scenarios tested, the weighting choice matters most for heat-dominated inland desert tracts " "compared with dense coastal tracts.") add("") add("## What these checks do not show") add("") add("* **They do not show that UCRI is correct or that it predicts anything.** They test sensitivity to " "weights, not whether high-UCRI tracts have worse heat illness, mortality or other outcomes. No outcome " "data were used.") add("* They do not test the inputs. Errors in the canopy, temperature, impervious, SVI or CalEnviroScreen " "layers pass straight through every scenario.") add("* They do not test other design choices: percentile scaling instead of raw values, statewide instead of " "regional percentiles, the tract as the unit, or the quintile class cut points.") add("* Comparing UCRI with Landsat temperature, CDC SVI or CalEnviroScreen is not independent evidence, " "because those datasets are inputs to UCRI. Agreement with them is built in.") add("* These checks were designed, run and interpreted by Canopulse. They are not an independent review, " "and no independent review of UCRI has been completed.") add("") add("## Reproduce") add("") add("From the package folder: `python3 robustness/ucri_robustness.py --out rerun`. It reads " "`ucri_ca_2026_10_tracts.csv`, needs only the Python standard library (3.8 or later), takes about " "a minute, and writes `results.json`, `tract_stability.csv` and `REPORT.md` to a new folder `rerun/` " f"for comparison with the published files in `robustness/` (seed {mc['seed']}). Without `--out` it " "overwrites the files in `robustness/`. Random draws are bit-identical on the same Python version; " f"this run used Python {r['python_version']}.") add("") return "\n".join(lines) if __name__ == "__main__": main()