Data and code from: Inferring the abundance of an island megaherbivore from semi-structured distance sampling
Data files
Sep 29, 2026 version files 99.42 KB
-
AnalysisCode.R
9.29 KB
-
M.rds
10.07 KB
-
README.md
12.52 KB
-
torts.rds
67.53 KB
Abstract
This dataset supports the manuscript “Inferring the abundance of an island megaherbivore from semi-structured distance sampling”. It contains the processed transect-level count data, individual distance observations, habitat classifications, analysis code, and supporting files used to estimate the abundance and habitat-specific density of Aldabra giant tortoises (Aldabrachelys gigantea) on Aldabra Atoll, Seychelles.
The data derive from long-term wet-season transect monitoring conducted between 2018 and 2022. Transects were divided into 50 m sections, with tortoise observations recorded as perpendicular distances from the transect line and linked to habitat type and survey year. These data were analysed using a hierarchical Bayesian distance-sampling model to estimate detection-corrected section-level abundance, habitat-specific density, and atoll-wide population size. The repository also includes code for model fitting, posterior diagnostics, population extrapolation, sensitivity checks, and figure generation.
Dataset DOI: 10.5061/dryad.0p2ngf2hj
This repository contains the data and R code used to estimate the abundance and habitat-specific density of Aldabra giant tortoises (Aldabrachelys gigantea) on Aldabra Atoll, Seychelles, using hierarchical Bayesian distance sampling.
The data and code support the manuscript:
Inferring the abundance of an island megaherbivore from semi-structured distance sampling
Repository contents
AnalysisCode.R
Main R script containing data preparation, model definition, MCMC fitting, posterior extrapolation, and figure generation.torts.rds
Individual tortoise observation data. Each row represents one tortoise detected during a transect survey, including perpendicular distance from the transect line and associated survey metadata.M.rds
Transect-section level survey data. Each row represents one sampled transect section during a survey occasion, including observed count, habitat type, survey year/season, and transect metadata.
File formats
The data are stored as .rds files, which are native R serialized data objects. They can be read into R using:
readRDS("torts.rds")
readRDS("M.rds")
Study design and key terminology
Transects were divided into 50 m analytical units. In the manuscript these are referred to as transect sections. In parts of the model code, the same 50 m units are referred to as sites. These terms therefore refer to the same analytical sampling unit in this repository.
Perpendicular distances from the transect line were recorded for detected tortoises and used to fit a distance-sampling detection function. The main analysis focuses on wet-season surveys, when tortoise availability for detection is expected to be higher and more consistent than in the dry season.
The abundance estimates should be interpreted as applying primarily to visible adult and sub-adult tortoises. Small juveniles are likely to be under-represented because they are cryptic and less consistently detectable during transect surveys.
Habitat codes
The following habitat codes occur in the data and/or analysis:
| Code | Habitat name | Description |
|---|---|---|
MAN |
Mangroves | Homogeneous areas of mangrove tree species. |
OMX |
Open mixed scrub | Low-density woody vegetation with ground-layer vegetation often including tortoise turf. |
SMX |
Standard mixed scrub | Similar to open mixed scrub but with higher density woody vegetation and an herbaceous/tortoise-turf component. |
MSC |
Mixed scrub | Legacy/raw habitat label harmonised to SMX in the analysis code. |
PEM |
Pemphis scrub | Habitat dominated by Pemphis acidula. |
GRA |
Grassland | Homogeneous areas of tortoise-turf grass. |
EXP |
Exposed surface | Limited or absent vegetation cover; where present, vegetation is dominated by tortoise turf. |
CRB |
Coral rubble / exposed surface | Legacy/raw habitat label harmonised to EXP in the analysis code. |
CHP |
Champignon | Champignon rock with minimal vegetation. |
SND |
Sand | Sand substrate with some ground-level vegetation in places; includes dried-out seasonal pools on Grande Terre. |
CSB |
Coastal scrub / sand-associated habitat | Legacy/raw habitat label harmonised to SND in the analysis code where present. |
The analysis code harmonises some historical habitat labels before model fitting:
CRB -> EXP
CSB -> SND
MSC -> SMX
Data dictionary: torts.rds
torts.rds contains individual-level tortoise observations. Each row is a single detected tortoise.
| Variable | Description | Units / format | Notes |
|---|---|---|---|
TransectID |
Identifier for the transect survey record. | Character or factor | Field/survey identifier used in the original dataset. |
TransectCode |
Identifier for the transect route or transect line. | Character or factor | Broader transect code; individual 50 m sections are identified by SectionCode. |
DateOfTransect |
Date on which the transect was surveyed. | Date | Used as survey metadata. |
SectionCode |
Identifier for the 50 m transect section where the tortoise was observed. | Character or factor | Examples include codes such as GTA01, GTB15, etc. This links observations to section-level data in M.rds. |
VegType |
Habitat type recorded for the transect section. | Categorical code | See habitat-code legend above. Some historical labels are harmonised in AnalysisCode.R. |
DistFromTransect |
Perpendicular distance from the active transect line to the detected tortoise. | Metres | Used in the distance-sampling observation model. The analysis uses a truncation distance of 50 m. |
occasion |
Numeric survey-occasion identifier. | Integer | Used to link individual detections to section-level survey occasions. In the analysis script this is regenerated after data cleaning. |
season |
Survey season. | Categorical | Usually Wet or Dry. The main analysis filters to Wet. This column is renamed to Season in AnalysisCode.R. |
Year |
Survey year. | Numeric/integer | For wet-season surveys, this refers to the year assigned to the wet-season sampling period. |
Occasion |
Combined year-season identifier. | Character/factor | For example, a combined label such as 2018_Wet. The script separates this into Year and Season where required. |
SectionCode_factored |
Numeric/factor coding of SectionCode. |
Numeric or factor | Helper variable retained from earlier processing; not essential for interpretation. |
VegType_factored |
Numeric/factor coding of VegType. |
Numeric or factor | Helper variable retained from earlier processing; not essential for interpretation. |
Data dictionary: M.rds
M.rds contains transect-section level count data. Each row represents a sampled 50 m transect section during a survey occasion.
| Variable | Description | Units / format | Notes |
|---|---|---|---|
site |
Identifier for the 50 m transect section. | Character or factor | Renamed to SectionCode in AnalysisCode.R. This is the same analytical unit described as a transect section in the manuscript. |
Occasion |
Combined year-season identifier. | Character/factor | Separated in the analysis into Year and Season. |
count |
Number of tortoises observed in the transect section during that survey occasion. | Count; non-negative integer | Used as the observed count in the abundance component of the hierarchical model. |
Transect |
Identifier for the broader transect route or transect line. | Character or factor | Groups multiple 50 m sections belonging to the same transect. |
VegType |
Habitat type for the transect section. | Categorical code | See habitat-code legend above. |
Year |
Survey year. | Numeric/integer | In the analysis script, this is derived from Occasion after separating the combined year-season label. |
Season |
Survey season. | Categorical | Usually Wet or Dry. The main analysis filters to Wet. |
Note that variable M within the dataframe M.rds is a legacy/helper index column retained from earlier data preparation. This column is not used in the final analysis and is removed in AnalysisCode.R before model fitting. It should not be confused with M_super, the fixed superpopulation size used in the Bayesian data-augmentation model.
Required R packages
The analysis uses the following R packages:
library(tidyverse)
library(nimble)
library(coda)
library(ggforce)
library(patchwork)
library(scales)
Install any missing packages before running the analysis, for example:
install.packages(c("tidyverse", "coda", "ggforce", "patchwork", "scales"))
install.packages("nimble")
How to run the analysis
- Download this repository.
- Open R or RStudio and set the working directory to the folder containing:
AnalysisCode.R
torts.rds
M.rds
- Run the full script:
source("AnalysisCode.R")
Alternatively, open AnalysisCode.R in RStudio and run the code section by section.
Analysis workflow
The script performs the following steps:
- Load and prepare data
The script readstorts.rdsandM.rds, filters surveys to the wet season, harmonises habitat labels, creates survey occasion identifiers, and links individual tortoise observations to transect-section metadata. - Define the hierarchical distance-sampling model
The model is implemented innimble. The observation component uses a half-normal detection function and a custom distance likelihood implemented via the zeros trick. The state process estimates latent abundance for each transect section and survey year using a superpopulation formulation. - Run MCMC
The model is fitted usingnimbleMCMC. The default settings in the script are:
nburnin = 75000
niter = 250000
nchains = 2
thin = 20
This step is computationally intensive and may take a long time depending on the computer used.
- Extrapolate to atoll-wide abundance
Posterior samples of section-level abundance are aggregated by habitat and year, converted to density using the surveyed strip area, and scaled by mapped habitat area to estimate total population size. The extrapolation uses habitat-specific mapped proportions and excludes areas not included in the abundance calculation as described in the manuscript. - Generate figures
The script produces visualisations of:- annual atoll-wide population estimates,
- habitat-specific detection coefficients,
- habitat-specific section-level abundance,
- fitted detection functions and observed distance data,
- the posterior distribution of the global abundance-variation parameter.
Model outputs
The fitted MCMC object can be saved by uncommenting the following line in AnalysisCode.R:
saveRDS(out1, "Hybrid_Model_Final_Run.rds")
Once saved, the model can be reloaded without refitting:
out1 <- readRDS("Hybrid_Model_Final_Run.rds")
This is recommended because the full MCMC run is computationally expensive.
Reproducibility
The analysis is fully reproducible from the included .rds files and AnalysisCode.R, provided the required R packages are installed. Results may vary slightly between runs because the MCMC initial values are randomly generated unless a random seed is set before model fitting.
To improve reproducibility, users may set a seed before running the model:
set.seed(123)
Citation
When using these data or code, please cite the associated manuscript:
Hillyard et al. Inferring the abundance of an island megaherbivore from semi-structured distance sampling. Ecology and Evolution.
