diff --git a/AGENTS.md b/AGENTS.md
index 5f0464b..f9284e6 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -109,6 +109,7 @@ samples/fixture/ synthetic workbooks for tests/CI (committed)
- `analytics/catchModel.ts`: negative-binomial counts per timed gillnet set, offset log(net-hours), natural-spline day of season (knots at the 0/25/50/75/100% quantiles), nursery and season as effect-coded fixed effects (each level vs the average; no random effects), and nine environment terms per +1 SD. Complete cases only; nurseries need ≥ 30 complete sets, and a species gets a nursery effect only where ≥ 10 of it were caught (otherwise the estimate runs off to zero or infinity).
- The headline: sea temperature's raw link with catch rate (≈ −25% per °C) vanishes once day of the season is in the model. Don't describe SST as a driver of catches on other pages.
+- Fit diagnostics (#125, `analytics/modelDiagnostics.ts`) reuse each fit's own rows, design matrix, counts and offsets, so they can't drift from the model. NB2 variance is μ + μ²/θ; P(0) falls back to Poisson when θ is infinite. Calibration rates are summed sharks over summed net-hours per group of sets. They are in-sample checks: not forecasting skill, and no leave-one-season-out (season is a fixed effect). Only rounded columns reach the page; keep it that way (the first draft sent 500 kB of JSON).
- `glm.ts` is generic (IRLS + ML θ, Wald intervals via `contrast`); reuse it rather than writing another fitter.
### Sex ratio mixed model (#117)
diff --git a/e2e/model-diagnostics.spec.ts b/e2e/model-diagnostics.spec.ts
new file mode 100644
index 0000000..5182702
--- /dev/null
+++ b/e2e/model-diagnostics.spec.ts
@@ -0,0 +1,26 @@
+import { expect, test } from '@playwright/test';
+import AxeBuilder from '@axe-core/playwright';
+
+test('model fit checks follow the catch model', async ({ page }) => {
+ await page.goto('/drivers');
+ const summary = page.getByText('How well does the model describe the catches?', { exact: true });
+ // The synthetic fixture has too few complete sets to fit the model, so there is nothing to check.
+ if (!(await page.getByRole('heading', { name: 'Sea temperature, step by step' }).count())) {
+ await expect(summary).toHaveCount(0);
+ return;
+ }
+ await summary.click();
+ const model = page.getByRole('combobox', { name: 'Model', exact: true });
+ await expect(model).toBeVisible();
+ for (const theme of ['light', 'dark'] as const) {
+ await page.emulateMedia({ colorScheme: theme });
+ const result = await new AxeBuilder({ page }).include('main').analyze();
+ expect(
+ result.violations.filter((v) => ['serious', 'critical'].includes(v.impact ?? ''))
+ ).toEqual([]);
+ }
+ for (const i of ['1', '2']) {
+ await model.selectOption(i);
+ await expect(page.locator('#model-fit figure').first()).toBeVisible();
+ }
+});
diff --git a/src/lib/components/ModelDiagnostics.svelte b/src/lib/components/ModelDiagnostics.svelte
new file mode 100644
index 0000000..b2afa7c
--- /dev/null
+++ b/src/lib/components/ModelDiagnostics.svelte
@@ -0,0 +1,190 @@
+
+
+
+ How well does the model describe the catches?
+
+ These checks compare the model with the same sets it was fitted to. They show where it expects
+ too many or too few sharks. They don't show how well it would forecast another season, and a
+ good fit doesn't make an effect a cause. Sets from the same night or nursery aren't independent,
+ so the charts carry no uncertainty bands.
+
+
+ {#if d}
+
+ {plural(d.n, 'set')} in this model's sample. Zero-catch charts leave out groups with fewer than
+ {MIN_GROUP_SETS} sets; their tables keep every group.
+