Lab 9 · Parameter Recovery for a Single-Season Occupancy Model
Biological motivation
The most important question to answer about any statistical pipeline is: "does it return the right answer when I know what the right answer is?" This is parameter recovery via simulation. Every model you publish should have one. In this lab you'll do it for the workhorse model of camera-trap analysis — the single-season occupancy model — and you'll do it with Claude Code as your collaborator.
What you'll prove
Given S sites, K repeat visits, true occupancy
ψ and true detection probability
p, simulate detection/non-detection histories, fit
unmarked::occu, repeat 500 times, and show:
- The mean of the 500 ψ̂ estimates is close to the true ψ.
- The mean of the 500 p̂ estimates is close to the true p.
- The empirical 95% interval covers the truth ~95% of the time.
- The estimator is reliable for a realistic (S, K) but degrades for small designs.
Tasks
Task 1 — project + CLAUDE.md (2 pts)
Create lab9/, git init, write a CLAUDE.md that says:
- The biological scenario (a hypothetical 4-week single-season cougar survey).
- The R packages you'll use (
unmarked,tidyverse,furrrfor parallel). - Random seed: 42.
- Your reproducibility policy: results must be re-creatable by
Rscript run.Rwith no manual steps.
Task 2 — ask Claude to write the simulator (5 pts)
In plan mode, prompt Claude Code with:
Write an R function `simulate_occu(S, K, psi, p, seed)` that:
- draws S latent occupancy indicators z[i] ~ Bernoulli(psi),
- draws S x K detection matrix y[i,j] ~ Bernoulli(z[i] * p),
- returns an unmarkedFrameOccu object.
Also write a separate function `fit_occu(uf)` that fits the constant-psi,
constant-p occupancy model and returns the back-transformed psi and p
estimates plus their 95% Wald CIs.
Review the plan. Approve. Save Claude's response in prompts.md.
Task 3 — run 500 sims, four scenarios (5 pts)
Ask Claude to run 500 simulations under each of these scenarios:
| Scenario | S | K | ψ | p |
|---|---|---|---|---|
| A: typical | 60 | 6 | 0.4 | 0.3 |
| B: low p | 60 | 6 | 0.4 | 0.1 |
| C: few sites | 20 | 6 | 0.4 | 0.3 |
| D: many visits | 60 | 12 | 0.4 | 0.3 |
Task 4 — plot recovery (4 pts)
Produce recovery_plots.png: a 2x2 panel, one per scenario, showing histograms of
the 500 ψ̂ estimates with the true value
marked. Below each panel: the empirical bias (mean estimate − true) and the empirical
95% CI coverage.
Task 5 — written interpretation (4 pts)
In 250 words, answer: under which scenario does unmarked::occu show the most
bias? When does coverage break down? Which is the more dangerous regime — low
detectability or few sites? What does this mean for designing a real survey?
Go-further
Add covariates: simulate ψ as a function of elevation; fit the model with elevation as a covariate; show that the slope coefficient is recovered without bias.
Rubric
| Component | Points |
|---|---|
| Project setup and CLAUDE.md | 2 |
| Quality of prompts (plan-mode usage, specificity) saved in prompts.md | 4 |
| Working sim + fit code; reproducible with one command | 5 |
| All four scenarios run; results saved | 3 |
| 2x2 recovery plot with bias and coverage | 2 |
| Interpretation | 4 |
| Total | 20 |
Starter sketch: lab9_skeleton.R (intentionally minimal — Claude should fill it in).