Data and code from: A continuous-time Random Encounter and Staying Time (REST) model: Moving beyond temporal aggregation in camera-trap density estimation
Abstract
Estimating wildlife population density is fundamental to ecology and conservation. While camera traps have revolutionized the monitoring of medium- to large-sized mammals, estimating the density of unmarked populations remains a major challenge. Current models rely on a critical and often-violated synchronized activity assumption. This assumption posits that all individuals in a sampled population are simultaneously active at the peak of their daily activity cycle. In natural settings, however, animal activity is highly plastic, shifting in response to environmental conditions. We develop a continuous-time Random Encounter and Staying Time (REST) model that treats animal detections as a temporal point process, enabling explicit tracking of temporal changes in active population density—the density of individuals available for detection. Our model links detection intensity to active population density by reformulating the original REST model. We model temporal dynamics using periodic components for diel activity patterns and spatio-temporal components for other variations. We evaluated model performance through simulations across scenarios with different densities and temporal patterns (static, linear trend, and pulse-like fluctuations) and applied the model to Japanese badger (Meles anakuma) data from Japan. Simulations demonstrated that the continuous-time REST model accurately recovered temporal fluctuations in active population density and yielded unbiased estimates across all scenarios. In contrast, conventional methods underestimated density under temporal variation because they averaged out these fluctuations, obscuring peak active population density. Application to badger data revealed seasonal declines in active population density, with daily maximum decreasing to approximately 30% of its initial value, consistent with the species' known behavioral ecology. The continuous-time REST model relaxes the conventional assumption that all individuals must be active simultaneously each day, requiring only that all individuals are active simultaneously at least once during the survey period. Under this weaker assumption, the maximum of active population density provides a more accurate estimate of true population density. More fundamentally, by moving beyond temporal aggregation to continuous-time modeling of active population density, this framework enables direct quantification of fine-scale population changes, providing richer ecological insights into population dynamics and responses to environmental change, opening avenues for studying fine-scale ecological processes.
Note: All files described in this README are contained in Supp.zip.
Overview
This repository contains the data and code used in the study on density estimation methods for unmarked populations using camera trap data.
The study consists of two main components:
- A simulation study to evaluate model performance under controlled scenarios
- An empirical analysis applying the models to Japanese badger (Meles anakuma) camera trap data
Simulation analyses and empirical analyses use different model implementations,
which are separated and documented below.
Data, code and file structure
.
├── simulation_scenarios.R # For simulation study
├── simulation_example.R # Example for simulation study
├── Simulation_RESULTS/
│ └── simulation_results_full.rds
├── Badger_DATA/
│ ├── BadgerData.csv
│ ├── BadgerDetections.csv
│ └── BadgerStayingTime.csv
├── Badger_RESULTS/
└── MODELS/ # TMB models
├── 01_FULL.cpp # TMB models for simulation study
├── 01_FULL_getmaximum.cpp
├── 02_REDUCED.cpp
├── 02_REDUCED_getmaximum.cpp
├── 03_ORIGINAL.cpp
├── Badger_FULL.cpp # TMB models for empirical study
├── Badger_FULL_getmaximum.cpp
├── Badger_REDUCED.cpp
├── Badger_REDUCED_getmaximum.cpp
└── Badger_ORIGINAL.cpp
Simulation study
simulation_scenarios.R
This script performs the main simulation study reported in the manuscript.
- Multiple simulation scenarios and repeated runs
- The file
simulation_results_full.rdscontains raw simulation outputs from all scenarios and repetitions - Results are saved to the
Simulation_RESULTS/directory - This script generates the primary simulation results presented in the paper
simulation_example.R
This script provides a simplified example of the simulation workflow.
- Illustrates data generation and model fitting
- Uses the same modelling framework as
simulation_scenarios.R - Intended as an explanatory and reproducibility aid
Empirical analysis: Japanese badger data
Badger_DATA/
This directory contains data for the empirical analysis:
- BadgerData.csv: Number of hourly badger passing events, environmental covariates (PC1-3), periodic components (SIN1-3, COS1-3), trend variable (Trend) and observation information.
Missing indicates periods excluded from the analysis when data were unavailable due to battery depletion or not valid due to camera angle changes or obstructed views.
| Variable | Description |
|---|---|
| id | Sequential row identifier |
| st_id | Station ID |
| t_id | Time ID |
| Station | Station Name |
| DateTime | Timestamp of hourly observation |
| Hour | Hour of day (0–23) |
| Hour_Pi | Hour transformed to radians (0–2π scale) |
| n | Number of passing events through a focal area |
| Missing | Logical missing indicator |
| PC1 | First principal component of land-use variables |
| PC2 | Second principal component of land-use variables |
| PC3 | Third principal component of land-use variables |
| SIN1 | sin(Hour_Pi); first sine component |
| SIN2 | sin(2 * Hour_Pi); second sine component |
| SIN3 | sin(3 * Hour_Pi); third sine component |
| COS1 | cos(Hour_Pi); first cosine component |
| COS2 | cos(2 * Hour_Pi); second cosine component |
| COS3 | cos(3 * Hour_Pi); third cosine component |
| x | Spatial coordinate (projected x-axis) (WGS 84 / UTM zone 54N) |
| y | Spatial coordinate (projected y-axis) (WGS 84 / UTM zone 54N) |
| Trend | Standardized temporal index scaled to [0,1], representing long-term temporal trend |
- BadgerDetections.csv: Detection timestamps for estimating activity levels.
| Variable | Description |
|---|---|
| DateTime | Timestamp for detection |
- BadgerStayingTime.csv: Staying time records with censoring indicator.
| Variable | Description |
|---|---|
| stay | Staying time in a focal area (seconds) |
| censored | Logical right-censoring indicator |
Badger_RESULTS/
This directory is intentionally left empty.
All figures and summaries reported in the manuscript are generated
directly from the raw data using the provided R scripts.
Models (TMB)
The MODELS/ directory contains Template Model Builder (TMB) C++ files used for both the simulation study and the empirical analysis.
Simulation and badger analyses use different model implementations.
Simulation models
The following models are used in the simulation study:
01_FULL.cpp02_REDUCED.cpp03_ORIGINAL.cpp
Corresponding _getmaximum.cpp files are used to estimate maximum of active population density values and associated uncertainty.
Badger data models
The following models are used exclusively for the empirical analysis of Japanese badger camera trap data:
Badger_FULL.cppBadger_REDUCED.cppBadger_ORIGINAL.cpp
Each model has a corresponding _getmaximum.cpp file for maximum of active population density estimation.
Software requirements
- R
- TMB (Template Model Builder) package for R
- C++ compiler compatible with TMB
- Additional R packages are listed in the respective scripts
