This repository provides the R code and data to reproduce the results for the
paper, "drmr: A Bayesian approach to Dynamic Range Models in R."
Before running any analysis, please follow these steps to set up the required environment.
-
Install CmdStan: This project depends on
CmdStan(version >= 2.36). Please install it and the R packagecmdstanrby following the official instructions. -
Restore R Environment: This repository uses
renvto manage R package dependencies (including the version ofdrmrin thepkg/directory). To install all required packages, open this project in R and run:yrenv::restore()
-
System Dependencies (Optional): If you wish to regenerate the raw environmental data for the red-bellied woodpecker case study, you must also have the
bashinterface to GDAL set up in your system. This is not required if you use the provided, pre-processed data.
The analyses for the two case studies can be run using the scripts in the
code/ directory.
To reproduce the full analysis for the summer flounder, run the
code/01-summer-flounder.R script.y
For convenience, the final processed dataset for this study is already provided
at data/birds/processed.parquet.
-
To run the analysis using the provided data, execute the
code/04-rbw.Rscript. -
(Optional) To regenerate the processed data from raw sources, run the following scripts in order:
code/02-download-bbs.R: Downloads Breeding Bird Survey (BBS) data via thebbsBayes2package.chelsa-download.sh: Abashscript to download and crop CHELSA air temperature data.code/03-chelsa-env4bbs.R: Aggregates the temperature data and creates the finalprocessed.parquetfile.
Please be aware that results from CmdStan may vary slightly across different
operating systems and hardware platforms due to minor differences in random
number generator implementations. Full reproducibility is only guaranteed when
using an identical computational environment.
The analyses were conducted on a macOS machine with the following specifications:
- Processor: Apple M2 Pro
- Memory: 16GB RAM
The R session information is provided below for full reproducibility.
> sessionInfo()
#> R version 4.4.1 (2024-06-14)
#> Platform: aarch64-apple-darwin20
#> Running under: macOS 15.5
#>
#> Matrix products: default
#> BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Vers#> ions/A/libBLAS.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0