Using R to Estimate Animal Population Densities

Melissa Bather

Some problems with simply counting animals

  • Animals move
  • Tiny animals or camouflaging animals can be very difficult to spot
  • Double counting can be hard to avoid when relying on our sight alone

Spatially explicit capture-recapture (SECR)

Binary capture history

Binary capture history

Binary capture history

Binary capture history

Detection methods

  • Physical traps
  • Microphones
  • Cameras
  • Hair snares

Relevant R packages

secr

Authors: Murray Efford, Philipp Jund, David Fletcher

https://www.otago.ac.nz/density/

https://github.com/MurrayEfford/secr/

https://www.stats.otago.ac.nz/secrapp/

ascr

Author: Ben Stevenson

https://github.com/b-steve/ascr

acre

Authors: Ben Stevenson, Joseph Reps, Lingyu Hao

https://github.com/b-steve/acre

Example dataset

install.packages(“secr”)
library(secr)

# List available example datasets
data(package = "secr")

The Brushtail Possum Trapping Dataset

From the secr vignette:

Description: Data from a trapping study of brushtail possums at Waitarere, North Island, New Zealand.

Source: Landcare Research, New Zealand

The Brushtail Possum Trapping Dataset

The components of the dataset:

  • Capture histories (possumCH)
  • Mask (possummask)
  • Habitat perimeter (possumarea)

The Mask

A mask is a defined habitat region around the detectors/traps, divided into ‘cells’.

https://www.otago.ac.nz/density/pdfs/secr-habitatmasks.pdf

head(possummask)
         x       y
58 2698543 6077080
59 2698563 6077080
60 2698583 6077080
61 2698603 6077080
62 2698623 6077080
63 2698643 6077080

The Study Area

The study area is simply the coordinates of the perimeter of the survey region.

head(possumarea)
        x       y
1 2697117 6075605
2 2697197 6075953
3 2697260 6076226
4 2697284 6076351
5 2697316 6076513
6 2697359 6076799

Visualize the study area

Code from the secr vignette

plot(possummask)
plot(possumCH, tracks = TRUE, add = TRUE)
plot(traps(possumCH), add = TRUE)
lines(possumarea)

Detection Function

A detection function models the probability of detection from the distance of the animal to the detector.

Common detection functions:

  • Halfnormal
  • Hazard rate
  • Exponential
  • Uniform

Halfnormal Detection Function

\(g(d) = g_0 \exp(-d^2/2\sigma^2)\),

where,

  • \(d\) is the distance between the animal and the detector/trap,
  • \(g_0\) is the probability of trapping/detecting the animal when its distance from the trap is zero,
  • \(\sigma\) is the scale at which the detection probability decreases as the distance between the animal and the detector/trap decreases

Halfnormal Detection Function

Creating a Null Model

possum.null <- secr.fit(
  capthist = possumCH, 
  model = list(D~1, g0~1, sigma~1), 
  mask = possummask, 
  trace = F
  )
summary(possum.null)
$versiontime
[1] "5.4.3, run 13:56:38 04 Jul 2026, elapsed 1.4 s"

$traps
 Detector Number Spacing UsagePct
   single    180      20      100

$capthist
 Occasions Detections    Animals  Detectors      Moves   Animals2 
         5        305        112        180        184         80 

$mask
 Cells Spacing  Area
  5120      20 204.8

$modeldetails
    CL fixed distribution hcov relativeD
 FALSE  none      poisson          FALSE

$AICtable
            model   detectfn npar    logLik      AIC     AICc
 D~1 g0~1 sigma~1 halfnormal    3 -1097.107 2200.214 2200.437

$coef
            beta    SE.beta        lcl        ucl
D      0.5257907 0.10283425  0.3242392  0.7273421
g0    -1.4355017 0.14051867 -1.7109132 -1.1600901
sigma  3.9415019 0.04961721  3.8442539  4.0387498

$predicted
       link   estimate SE.estimate        lcl        ucl
D       log  1.6917960  0.17443553  1.3829781  2.0695726
g0    logit  0.1922429  0.02182052  0.1530453  0.2386509
sigma   log 51.4958827  2.55665522 46.7238116 56.7553426

Thank you!

Find these slides at: https://melbather.github.io/useR-2026-slides

Find me at: https://statisticsmelissa.netlify.app

References

  1. Borchers, D. and Efford, M. (2008). Spatially explicit maximum likelihood methods for capture–recapture studies. Biometrics 64: 377-385.

  2. Efford, M. (2025) secr: Spatially explicit capture–recapture models. R package version 5.3.0.

  3. Stevenson, B., Reps, J., Hao, L. (2026, April 14). acre. GitHub. https://github.com/b-steve/acre

  4. Stevenson, B. (2025, July 9). ascr. GitHub. https://github.com/b-steve/ascr.

  5. University of Otago, New Zealand. (2026, May 28). Software for spatially explicit capture–recapture. https://www.otago.ac.nz/density/

Presentation made with Quarto