Data and code from: Microclimate mediates the strength and direction of avian biotic interactions
Data files
Jul 18, 2026 version files 1.59 MB
-
checkpoint_inputs.rds
77.46 KB
-
Frey_et_al_models_and_helpers.R
17.21 KB
-
Frey_et_al_phylogenetic_analysis.R
7.18 KB
-
Frey_et_al_phylogenetic_tree.R
2.07 KB
-
Frey_et_al_prob_comp_facil_persist.R
6.29 KB
-
Frey_et_al_prob_comp_facil_settle.R
6.28 KB
-
Frey_et_al_sp_int_persistence.R
7.44 KB
-
Frey_et_al_sp_int_settlement.R
4.20 KB
-
global_inputs.rds
1.39 MB
-
junMxYr_2010.2023.C.csv
31.86 KB
-
manuscript_summary_table.csv
347 B
-
phylogenetic_analysis_complete_dataset.csv
3.43 KB
-
phylogenetic_correlation_with_CI.csv
385 B
-
README.md
16.88 KB
-
TA_hja_birds.tre
17.28 KB
Abstract
Code in this repository implements Bayesian dynamic occupancy models to estimate settlement (colonization) and persistence (survival) probabilities for 20 species pairs of montane forest birds. Models account for the presence or absence of a heterospecific, local vegetation structure, microclimate, interannual variation, and survey‑specific detection covariates (day‑of‑year and time‑of‑day). Additional scripts extract, from the MCMC output, the probability that settlement or persistence of a focal species is higher in the absence of its heterospecific (i.e., the probability of competition) across a microclimate gradient and identify temperature ranges where this probability exceeds 0.8 (strong competition) or falls below 0.2 (strong facilitation). A final set of scripts tests for phylogenetic signal in the interaction outcomes using cophenetic distances derived from a published bird tree. The repository includes seven annotated R scripts, three core input data files (detection histories, environmental covariates, and microclimate temperatures), a phylogenetic tree file, and summary output tables used in the manuscript. All models were fitted using JAGS (version ≥ 4.0) via the R package ‘rjags’, with MCMC post‑processing performed using ‘coda’ and ‘MCMCvis’.
Dataset DOI: 10.5061/dryad.pg4f4qs58
This repository contains the R code, JAGS model definitions, and input data required to reproduce the analyses presented in ‘Microclimate mediates the strength and direction of avian biotic interactions’ (Frey et al. 2026).
Description of the data and file structure
R code and input data required to reproduce the multi‑season dynamic occupancy models used to estimate settlement (colonization) and persistence (survival) probabilities for co‑occurring montane forest bird species. The models account for species interactions (presence vs. absence of a heterospecific), local vegetation structure, microclimate, interannual variation, and imperfect detection (via survey‑specific covariates: day‑of‑year and time‑of‑day). All analyses were implemented in a Bayesian framework using JAGS (Just Another Gibbs Sampler) via the 'rjags' package in R.
The data consist of detection/non‑detection histories for multiple species pairs, along with site‑level environmental covariates (vegetation PCA scores, microclimate temperatures) and survey‑level covariates (day of year and start time). The code is structured to run the same model for each species pair in parallel, saving MCMC samples, and summarizing the interaction effects for both settlement and persistence.
Files and variables
File: Frey_et_al_models_and_helpers.R
Description: Shared helper functions and the core JAGS model definition. This script contains:
z_from_y()– initialises latent occupancy states from observed detections.make_data_base()– builds the JAGS data list for a given species pair.add_detcov()– appends DOY and survey‑time covariates to the data list.fit_jags()– wrapper to compile and run the JAGS model.delta_summary()– computes posterior summaries of the settlement interaction effect.ensure_maps()andcheck_pairs_ready()– build and validate per‑pair covariate lists.coerce_clima_2009()– formats the year‑1 climate vector.model_text_det– JAGS model code for settlement (with detection covariates).params_det– vector of parameters to monitor for the settlement model.
File: Frey_et_al_sp_int_settlement.R
Description: The main script for fitting the settlement (colonization) model. It:
- Loads
checkpoint_inputs.rdsandglobal_inputs.rds. - Sources
models_and_helpers.R. - Defines the list of species pairs to analyze.
- Builds per‑pair covariate objects via
ensure_maps(). - Runs the JAGS model in parallel using
pbmcapply::pblapply()(multiple chains, thinning, burn‑in). - Saves MCMC samples as
.rdsfiles (e.g.,samp_det_<pair>.rds). - Computes delta summaries (difference in settlement with vs. without heterospecific) and saves them as
delta_summaries.rds. - Outputs a run status CSV.
File: Frey_et_al_sp_int_persistence.R
Description: The main script for fitting the persistence (survival) model. It uses the same infrastructure as Frey_et_al_sp_int_settlement.R but substitutes:
model_text_persist– JAGS model code where persistence (φ) depends on heterospecific presence, vegetation, mircoclimateclimate, and random annual effects.params_persist– the corresponding set of parameters to monitor (includingphiAwB.b0,phiAwoB.b0, etc.).delta_summary_persist()– a separate summary function that computes the difference in persistence with vs. without the heterospecific.
All other data loading, map building, and parallel execution steps are identical to the settlement script.
File: Frey_et_al_prob_comp_facil_settle.R
Description: Extracts MCMC samples from the settlement model and calculates, for each species pair, the probability that settlement of species A is higher when heterospecific B is absent than when B is present (i.e., competition). Identifies temperature ranges where this probability ≥ 0.8 (strong competition) or ≤ 0.2 (strong facilitation). Outputs post_prob_min_max_SETTLE_2010_2023.csv.
File: Frey_et_al_prob_comp_facil_persist.R
Description: Identical logic to the settlement probability script, but extracts parameters from the persistence model (phiAwB.b0, phiAwoB.b0, mu.phi.year1, mu.phi.year2). Outputs post_prob_min_max_PERSIST_2010_2023.csv.
File: Frey_et_al_phylogenetic_tree.R
Description: Reads the ultrametric tree (TA_hja_birds.tre), standardizes tip labels, computes pairwise cophenetic distances, and saves the full distance matrix. The final distance values used in the analysis are hard‑coded in the phylogenetic analysis script.
File: Frey_et_al_phylogenetic_analysis.R
Reads the two probability CSV files (from the settlement and persistence scripts), merges them with the hard‑coded phylogenetic distances, and performs correlations with bootstrap confidence intervals. Outputs several summary CSVs used in the manuscript: phylogenetic_analysis_complete_dataset.csv, phylogenetic_correlation_with_CI.csv, manuscript_summary_table.csv, and others.
File: checkpoint_inputs.rds
Description: Detection histories (pair_arrays) and detection covariates (cov_arrays) for all species pairs. Created from raw field data.
File: global_inputs.rds
Description: Site‑level environmental covariates: vegetation scores (veg_master), climate matrix (clim_ext), and year‑1 climate (clima_2009).
File: junMxYr_2010.2023.C.csv
Description: Microclimate temperatures (June maximum) for all sites and years (2010–2023). Used to define the temperature gradient for the probability scripts. Sites are row names; years are column names.
File: TA_hja_birds.tre
Description: Ultrametric tree file (Nexus format) from TreeAnnotator, derived from the birdtree.org posterior sample. Used in Frey_et_al_phylogenetic_tree.R to compute distances.
File: post_prob_min_max_SETTLE_2010_2023.csv
Description: Probability of competition and facilitation, and temperature ranges (0.8/0.2 cutoffs) for settlement. Generated by Frey_et_al_prob_comp_facil_settle.R
| Column name | Description | Units / format |
|---|---|---|
species_pair |
Species pair identifier (four‑letter code for species A and species B, separated by an underscore). First code = focal species (A), second code = heterospecific (B). | Character string |
prob_comp |
Maximum probability of competition (i.e., probability that settlement of species A is higher when species B is absent than when B is present). Ranges from 0 to 1. | Probability (0–1) |
minT_comp |
Minimum temperature (°C) at which the probability of competition ≥ 0.8. NA if no such temperature exists within the observed range. |
Degrees Celsius |
maxT_comp |
Maximum temperature (°C) at which the probability of competition ≥ 0.8. NA if no such temperature exists. |
Degrees Celsius |
prob_attract |
Maximum probability of facilitation (i.e., 1 – minimum probability of competition). Ranges from 0 to 1. | Probability (0–1) |
minT_attract |
Minimum temperature (°C) at which the probability of competition ≤ 0.2 (i.e., strong facilitation). NA if no such temperature exists. |
Degrees Celsius |
maxT_attract |
Maximum temperature (°C) at which the probability of competition ≤ 0.2. NA if no such temperature exists. |
Degrees Celsius |
File: post_prob_min_max_PERSIST_2010_2023.csv
Description: Probability of competition and facilitation, and temperature ranges (0.8/0.2 cutoffs) for persistence. Generated by Frey_et_al_prob_comp_facil_persist.R
| Column name | Description | Units / format |
|---|---|---|
species_pair |
Species pair identifier (four‑letter code for species A and species B, separated by an underscore). | Character string |
prob_comp |
Maximum probability of competition (i.e., probability that persistence of species A is higher when species B is absent than when B is present). | Probability (0–1) |
minT_comp |
Minimum temperature (°C) at which probability of competition ≥ 0.8. NA if none. |
Degrees Celsius |
maxT_comp |
Maximum temperature (°C) at which probability of competition ≥ 0.8. NA if none. |
Degrees Celsius |
prob_attract |
Maximum probability of facilitation (1 – minimum probability of competition). | Probability (0–1) |
minT_attract |
Minimum temperature (°C) at which probability of competition ≤ 0.2. NA if none. |
Degrees Celsius |
maxT_attract |
Maximum temperature (°C) at which probability of competition ≤ 0.2. NA if none. |
Degrees Celsius |
Missing value notation: In the probability tables (post_prob_min_max_*.csv), NA values in temperature columns (minT_comp, maxT_comp, minT_attract, maxT_attract) indicate that the specified probability threshold (≥ 0.8 for competition, ≤ 0.2 for facilitation) was not reached at any point across the observed temperature gradient. These are not missing values – they are analytically derived absent ranges. All other columns contain complete data.
File: phylogenetic_analysis_complete_dataset.csv
Description: Merged dataset with probabilities and phylogenetic distances for all pairs and processes.. Generated by Frey_et_al_phylogenetic_analysis.R
| Column name | Description | Units / format |
|---|---|---|
species_pair |
Species pair identifier (four‑letter code for species A and species B). | Character string |
prob_comp |
Maximum probability of competition (from either settlement or persistence table). | Probability (0–1) |
minT_comp |
Minimum temperature (°C) at which probability of competition ≥ 0.8. | Degrees Celsius |
maxT_comp |
Maximum temperature (°C) at which probability of competition ≥ 0.8. | Degrees Celsius |
prob_attract |
Maximum probability of facilitation. | Probability (0–1) |
minT_attract |
Minimum temperature (°C) at which probability of competition ≤ 0.2. | Degrees Celsius |
maxT_attract |
Maximum temperature (°C) at which probability of competition ≤ 0.2. | Degrees Celsius |
process |
Ecological process: Colonization (settlement) or Survival (persistence). | Categorical |
phylo_distance |
Phylogenetic distance (cophenetic distance) between the two species, derived from a published bird tree (Jetz et al. 2012). | Branch length (unitless) |
dominant_interaction |
Classification of the dominant interaction type based on thresholds: Strong Competition, Competition, Strong Facilitation, Facilitation, or Mixed/Weak. |
Categorical |
File: phylogenetic_correlation_with_CI.csv
Description: Correlation coefficients with bootstrap 95 % confidence intervals. Generated by Frey_et_al_phylogenetic_analysis.R
| Column name | Description | Units / format |
|---|---|---|
process |
Ecological process: Colonization (settlement) or Survival (persistence). | Categorical |
competition_r |
Pearson correlation coefficient between phylogenetic distance and probability of competition. | Correlation coefficient |
competition_ci_lower |
Lower 95 % bootstrap confidence interval for competition_r. |
Correlation coefficient |
competition_ci_upper |
Upper 95 % bootstrap confidence interval for competition_r. |
Correlation coefficient |
facilitation_r |
Pearson correlation coefficient between phylogenetic distance and probability of facilitation. | Correlation coefficient |
facilitation_ci_lower |
Lower 95 % bootstrap confidence interval for facilitation_r. |
Correlation coefficient |
facilitation_ci_upper |
Upper 95 % bootstrap confidence interval for facilitation_r. |
Correlation coefficient |
File: manuscript_summary_table.csv
Description: Summary table used directly in the manuscript (means, correlations, counts). Generated by Frey_et_al_phylogenetic_analysis.R
| Column name | Description | Units / format |
|---|---|---|
process |
Ecological process: Colonization (settlement) or Survival (persistence). | Categorical |
n_pairs |
Number of species pairs included. | Integer |
mean_phylo_distance |
Mean phylogenetic distance across pairs. | Branch length (unitless) |
sd_phylo_distance |
Standard deviation of phylogenetic distance. | Branch length (unitless) |
mean_comp_prob |
Mean probability of competition across pairs. | Probability (0–1) |
mean_facil_prob |
Mean probability of facilitation across pairs. | Probability (0–1) |
comp_phylo_cor |
Pearson correlation between phylogenetic distance and competition probability. | Correlation coefficient |
comp_phylo_p |
P‑value for comp_phylo_cor. |
Probability |
facil_phylo_cor |
Pearson correlation between phylogenetic distance and facilitation probability. | Correlation coefficient |
facil_phylo_p |
P‑value for facil_phylo_cor. |
Probability |
pairs_strong_comp |
Number of pairs with strong competition (prob_comp > 0.8). | Integer |
pairs_strong_facil |
Number of pairs with strong facilitation (prob_attract > 0.8). | Integer |
Code/software
Required Software and R packages
- R (version ≥ 4.0)
- Required R packages (install from CRAN):
- rjags (4‑17)
- coda (0.19‑4.1)
- MCMCvis (0.16.5)
- parallel (base R)
- pbmcapply (1.5.1)
- tidyverse (for phylogeny analysis)
- broom (for regression summaries)
- ape (for tree reading)
- JAGS (version ≥ 4.0) must be installed separately on your system.
Workflow
- Install JAGS on your system (separate from R).
- Install the required R packages as listed above.
- Place all files (*.R, *.rds, *.csv, *.tre) in the same working directory.
- Open Frey_et_al_sp_int_settlement.R (or Frey_et_al_sp_int_persistence.R) in R.
- Edit the pairs_to_run vector to include the species pairs you wish to analyse.
- Run the script – the model will compile, run MCMC in parallel, and save outputs to a timestamped folder.
- Run the probability extraction scripts (Frey_et_al_prob_comp_facil_settle.R and Frey_et_al_prob_comp_facil_persist.R) to generate the probability tables.
- Run the phylogenetic analysis script (Frey_et_al_phylogenetic_analysis.R) to produce the correlation summaries.
Access information
Other publicly accessible locations of the data:
