Skip to content

Biology: apparent survival in the nurseries with a Cormack–Jolly–Seber model (#42) - #139

Merged
Luen merged 1 commit into
mainfrom
biology-42-survival
Nov 4, 2026
Merged

Luen merged 1 commit into
mainfrom
biology-42-survival

Conversation

@Luen

@Luen Luen commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Closes #42.

What. Within-season apparent survival from the mark–recapture histories, using a Cormack–Jolly–Seber model. It's the share of pups still at a nursery some time after a capture, whether they died or left. Unlike the Schnabel abundance, it doesn't assume a closed nursery: each history starts at the pup's first capture, so pups born later in the season don't bias it.

Model (src/lib/server/analytics/survival.ts)

  • Occasions: 14-day blocks of the season, close to the median gap between sets at a nursery, which is 14 days. There is one history per pup, nursery and season.
  • Capture probability: depends on that fortnight's net-hours: p = 1 − exp(−exp(aₙ + β·log hours)). Each nursery gets its own intercept, and p = 0 in a fortnight with no set. Untimed sets count as a typical set.
  • Survival φ: shared across nurseries, or one per nursery. The likelihood-ratio test between the two answers "do nurseries differ?".
  • Transients: a separate φ for the first fortnight after tagging, also tested by likelihood ratio.
  • Fitting: maximum likelihood by BFGS. Wald intervals are on the logit scale, from a numerical Hessian. Nurseries need ≥ 10 pups seen again later in the same season.

survival.test.ts checks the fitter on simulated histories. It recovers a shared φ and the effort slope (β ≈ 1 for p = 1 − exp(−q·h)). It separates nurseries only when their φ really differs. It detects transients. There's no R in CI, so this is the check against a known answer.

What it shows on the real data (/recaptures, new "How long do pups stay?" section)

Blacktips Sicklefin lemons
Still at the nursery 30 days later 40% (35–46%) 64% (57–71%)
Average stay about 33 days about 68 days
Nurseries differ? yes, χ²(7) = 17.2, p = 0.02 no, p = 0.72
Newly tagged pups leave faster? no, p = 0.79 yes, 58% vs 85% a fortnight, p = 0.006
Pups present caught by one typical set 11% 12%

The copy says plainly that φ can't tell death from leaving, and that a pup that moves to another nursery counts as gone. The lemon transient result gets two explanations: passing through, or moving off after being handled.

Checks

  • pnpm lint, pnpm check and pnpm test all pass (four new tests). The real-data import test passes.
  • /recaptures renders against the real data in the dev server with no console errors. The fits take about 0.5 s (blacktips) and 0.05 s (lemons), and are memoised per import.
  • Import logic is unchanged, so IMPORTER_VERSION stays as it is.

🤖 Generated with Claude Code

…r model (#42)

Within-season apparent survival from capture histories: 14-day occasions at
each nursery, one history per pup, nursery and season from its first capture
there, capture probability from that fortnight's net-hours (cloglog, an
intercept per nursery, p = 0 without a set). Likelihood-ratio tests for
differences between nurseries and for transients (a separate φ in the first
fortnight after tagging).

- analytics/survival.ts: fitCjs (BFGS, numerical Hessian, Wald intervals on
  the logit scale) and survival(d, species)
- survival.test.ts: recovers φ, the effort slope, nursery differences and
  transients from simulated histories
- /recaptures: "How long do pups stay?" with the share still at each nursery
  30 days later, per species
- AGENTS.md: notes and repo map

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Luen Luen added enhancement New feature or request analytics Charts, statistics and analyses labels Nov 4, 2026
@Luen
Luen merged commit ad65cc6 into main Nov 4, 2026
5 checks passed
@Luen
Luen deleted the biology-42-survival branch November 4, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

analytics Charts, statistics and analyses enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analysis: apparent survival (Cormack–Jolly–Seber) from mark–recapture

1 participant