Skip to content

Drivers: negative-binomial model of catches (#54) - #108

Merged
Luen merged 1 commit into
mainfrom
catch-model
Nov 3, 2026
Merged

Luen merged 1 commit into
mainfrom
catch-model

Conversation

@Luen

@Luen Luen commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Closes #54.

What

A joint model of catches on /drivers ("All together: a model of catches"):

  • Model: negative-binomial counts per timed gillnet set, log(net-hours) as the offset, natural cubic spline for day of the season, nursery and season as effect-coded fixed effects (each level vs the average), and nine environment terms per +1 SD (SST, moon illumination, tide height, wind, rain 24 h, cloud, waves, net-in vs sunset, crew size). Fitted for blacktips and sicklefin lemons separately; a species gets a nursery effect only where ≥ 10 of it were caught.
  • Charts (new ForestPlot component: rate ratios with 95% intervals on a log scale, CSV download, tooltips, labels wrap on phones):
    • Sea temperature step by step: alone → + day of season → full model
    • The environment, adjusted (per species, with a full table)
    • Through the season, adjusted (spline curve vs the season average)
    • Nurseries, adjusted and Seasons, adjusted
    • About the model: θ, AIC vs Poisson, knots, dropped sets, deviance explained
  • Finding sst-calendar: computed live; it only appears when the raw SST link is clearly negative and SST rises through the season.

What it shows (real data, computed live)

The −0.19 Spearman link between SST and catch rate (the strongest single correlate) is the calendar. Alone, each +1 °C goes with ~25% fewer sharks per net-hour. With day of the season in the model, the rate ratio is 1.00 (0.85–1.18). Nursery and season effects are large; among the environment terms, only net-in time vs sunset and tide height clear 1 for all sharks. The page copy builds these statements from the numbers, so none are hard-coded.

Notes

  • The issue asked for site random effects. This uses fixed effects coded against the average instead. With ~100 sets per nursery the two give nearly the same estimates, and fixed effects don't need a mixed-model fitter.
  • glm.ts is a small generic NB/Poisson GLM (IRLS + ML θ, Wald contrasts via contrast, natural spline basis). Tests check coefficient and θ recovery on simulated NB data, the Poisson pooled rate, Cholesky inversion and spline linearity.
  • seasonDayLabel moves to #lib/format (re-exported from analytics/common) so pages can label season days.
  • The synthetic fixture has too few sets for the model (it needs ≥ 200), so e2e renders /drivers without the section. I ran axe separately against the real-data page in light and dark: no serious violations.

Checks

pnpm lint, pnpm check, pnpm test (70), pnpm build, pnpm test:e2e (29), axe on real-data /drivers, desktop + 375 px layout checked in the browser. No importer change.

🤖 Generated with Claude Code

A joint model of sharks per gillnet set: negative binomial with
log(net-hours) as the offset, a natural-spline day of season, nursery
and season effects (each against the average) and nine environment
terms per +1 SD, fitted per species. New "All together" section on
/drivers with forest plots (new ForestPlot chart), the adjusted
seasonal curve, and a sea-temperature step-by-step comparison; a live
finding reports how the raw SST link changes once the calendar is in
the model.

glm.ts holds a small generic NB/Poisson GLM (IRLS, ML theta, Wald
contrasts, natural spline basis) with tests on simulated data.
seasonDayLabel moves to #lib/format so pages can use it.

Closes #54

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Luen
Luen merged commit 9690c2d into main Nov 3, 2026
5 checks passed
@Luen
Luen deleted the catch-model branch November 3, 2026 04:18
Luen added a commit that referenced this pull request Nov 3, 2026
Both branches added blocks at the same spots in stats.ts (normalP vs
the chi-square helpers), findings.ts (catch-model vs lavage finding)
and AGENTS.md; kept both. Restores the normalP assertions in
stats.test.ts now that both helpers are on one branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Luen added a commit that referenced this pull request Nov 3, 2026
AGENTS.md: both sides added a repo-map line and a section before
"Adding a new season"; kept both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Luen Luen mentioned this pull request Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analysis: negative-binomial GLM/GAM of catch with effort offset

1 participant