Lab 9 · Parameter Recovery for a Single-Season Occupancy Model

Worth: 20 points  |  Due: end of Day 5 (morning)  |  Files to submit: all R scripts, the simulation result RDS, recovery_plots.png, your CLAUDE.md and prompts.md, and a 1-page PDF.
Pre-reading: a section on single-season occupancy (MacKenzie et al. 2002; ?unmarked::occu).

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:

  1. The mean of the 500 ψ̂ estimates is close to the true ψ.
  2. The mean of the 500 estimates is close to the true p.
  3. The empirical 95% interval covers the truth ~95% of the time.
  4. 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:

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:

ScenarioSKψp
A: typical6060.40.3
B: low p6060.40.1
C: few sites2060.40.3
D: many visits60120.40.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

ComponentPoints
Project setup and CLAUDE.md2
Quality of prompts (plan-mode usage, specificity) saved in prompts.md4
Working sim + fit code; reproducible with one command5
All four scenarios run; results saved3
2x2 recovery plot with bias and coverage2
Interpretation4
Total20

Starter sketch: lab9_skeleton.R (intentionally minimal — Claude should fill it in).