Occupancy modelling in R
Presence-absence data almost never record absence. They record that nobody saw the species on the day they looked, which is a different thing, and the gap between the two is not noise you can average away. It is a downward bias on every occupancy figure, it gets worse with fewer visits, and it moves with anything that affects detection: observer, weather, season, habitat structure. If detection is correlated with the covariate you care about, the naive analysis does not just lose precision, it attenuates the slope you are trying to measure.
Occupancy models exist to take that apart. The idea is small: visit a site more than once inside a period when its status cannot change, and the pattern of detections and non-detections across visits carries enough information to estimate the probability of detection and the probability of occupancy separately. Everything else on this page is that idea with more structure bolted on.
This page collects every occupancy tutorial on this site. All of them build the likelihood by hand in base R, with optim or a hand-coded sampler, so you can see exactly which assumption is doing the work.
What you get, and what it costs
The basic model buys you an unbiased occupancy estimate at the price of repeat visits, and the price is real: a fixed budget spent on more visits is a budget not spent on more sites. That trade-off has an answer, and it depends on how detectable the species is, so it is worth working out before the field season rather than after.
The assumptions are where the interest is. Closure means the site cannot change status between visits within a season, and a species that comes and goes turns occupancy into “use”. Independence between visits fails as soon as one observer’s judgement carries across the day. Unmodelled detection heterogeneity is the recurring villain: it does not always announce itself in the fit, and several of the more ambitious variants read it as something else entirely. That is the honest limit worth stating plainly. Each extension buys another quantity from the same detection table, and each one rests on an assumption the table itself cannot test.
The variants, and what each one is for
Multiple seasons turn a static picture into colonisation and extinction, and stop naive year-to-year turnover from charging imperfect detection to local extinction. Multiple species let rare species borrow strength from common ones, and let you count the species nobody detected at all. Multiple scales separate whether the site is used from whether the species was available at the moment you sampled. Space matters when occupancy is spatially structured: a latent gradient inflates the significance of any covariate that shares its shape.
Two variants are more ambitious still: the Royle-Nichols model reads abundance out of bare detections, and a two-species model reads interaction out of co-occurrence. Both work. Both also have a slot where unmodelled heterogeneity or a shared gradient can arrive wearing the label you were hoping for.
The tutorials
Start here
- Imperfect detection and occupancy bias - why the sites where you saw it undercount the sites where it lives, and how the gap grows with fewer visits.
- Fitting single-season occupancy models - the MacKenzie likelihood built from scratch and fitted with optim.
- Occupancy and detection covariates - habitat on occupancy, effort on detection, and what the naive fit does to the slope.
Design, and the Bayesian version
- How many visits? Occupancy survey design - the sites-versus-visits trade-off under a fixed budget, answered before the field season.
- Bayesian occupancy with latent-state MCMC - the same model as a Gibbs sampler with data augmentation, written out by hand.
More than one season
- Dynamic occupancy: colonisation and extinction - the multi-season forward likelihood, and why naive turnover overstates extinction.
- Covariates in dynamic occupancy models - and what leaks into the state process when a detection covariate is left out.
- Occupancy turnover and equilibrium - derived quantities, and the transient trend that is not a change.
- Checking a dynamic occupancy model - a bootstrap fit test for the heterogeneity the estimates hide.
More than the basic model
- The Royle-Nichols model - abundance from bare detections, and the slot heterogeneity arrives in.
- Two-species occupancy and interactions - the Rota model, and the shared gradient that manufactures an interaction.
- False positives in occupancy models - misidentification, the Royle-Link repair, and the label swap it leaves behind.
- Checking an occupancy variant - four latent stories, one detection table, and what model selection can settle.
More than one species
- Multi-species occupancy models - a community model with a hand-coded Gibbs sampler, and what partial pooling does for sparse species.
- Species richness by data augmentation - counting the species nobody detected.
- Community covariates and species traits - a slope per species, with a trait to explain the spread.
- Checking a community occupancy model - a posterior predictive check for unmodelled detection heterogeneity.
Scale and space
- Multi-scale occupancy models - site use, local availability and detection, and the cost of skipping the middle scale.
- Spatial autocorrelation in occupancy models - Moran eigenvector filtering when a latent gradient inflates false positives.
Where this connects
- N-mixture models for abundance asks the same question of counts rather than detections, with reliability and checking as its honest companions.
- Integrated species distribution models put an occupancy survey and presence-only records in one likelihood, and checking an integrated SDM looks for the conflict between them.
- Species distribution modelling with GLM is the presence-background approach that ignores detection on purpose.
- Capture-recapture in R is where the same detection problem goes once individuals are marked.