Note that this repository is not updated anymore by me (@FriedaRosa). I hold no responsibily, nor was I involved in making any changes after July 2025. The Czech University of Life Sciences, Prague and the ERC hold all rights and ownerships of this study. For any questions regarding this project, please reach out to @petrkeil (keil@fzp.czu.cz) as he holds the full responsibility for this project now.
-
Project title: Static Predictors
-
Author: Friederike Johanna Rosa Wölke, MSc
-
Date: 2025-05-28
-
Location: Prague, Czech Republic
-
License: CC BY-NC-ND 4.0 (until publication) (https://creativecommons.org/licenses/by-nc-nd/4.0/)
-
R Package versions: registered in file
renv.lock -
Computational demands:
- Estimated total run time: 50 h
locally on laptop without parallelization;
can be significantly enhanced by running predictor scripts in parallel or enable multiple cores to approx. 6 h
- Estimated total run time: 50 h
-
Manual to the folder:
Folder_metadata.xlsx- has a list of A) scripts, input and output files, figure locations, run times, etc. and B) Files and their sources
- install
renvandherepackages if not already installed - open the Git.Rproj in RStudio or VScode and set
here::here()as working directory to the root folder (“Git”) - use
renv::restore()to restore packages & dependencies from the lockfile (this will lead in a huge downloading session of packages) - there are rendered .html files for all code (see/click links below to see)
- click here for advanced Project Description (incl. figs, results, predictor table)
- A_01_NY_Preprocess_data.html
- A_02_NY_Calculate_atlas_variables.html
- A_03_NY_Calculate_predictors.html
- B_01_NY_Machine_learning.html
- A_01_Get_data.html
- A_02_Preprocess_data.html
- A_03_Taxon_matching_across_datasets.html
- A_04_Calculate_atlas_variables.html
- A_05_Predictors_avonet.html
- A_06_Predictors_phylogenetic_metrics.html
- A_07_Predictors_IUCN.html
- A_08_Predictors_geometry.html
- A_09_Predictors_spatial_autocorrelation.html
- A_10a_Predictors_lacunarity_rasterize_ranges.html
- A_10b_Predictors_lacunarity_calculation.html
- A_11_Predictors_global_range_size.html
- A_12_Merge_predictors.html
- A_13_Data_viz.html
- B_01_RandomForest_all_data.html
- B_02_RandomForest_split_data.html
- B_03_Phylogenetic_autocorrelation.html
- B_04_Model_performance_figures.html
- D_01_Make_change_maps.html
- D_02_Figure_1.html
- D_03_Figure_2.html
- D_04_Figure_3.html
- D_05_Figure_S12a.html
- D_05_Figure_S12b.html
- D_05_Figure_S12c.html
fs::dir_tree(here::here(), recurse = F)C:/Users/wolke/OneDrive - CZU v Praze/Frieda_PhD_files/02_StaticPatterns/Git
├── Code
├── Data
├── Demo_NewYork
├── Figures
├── Folder_metadata.xlsx
├── Git.Rproj
├── Project_Description.html
├── Project_Description.qmd
├── README.md
├── README.qmd
├── README.rmarkdown
├── README_files
├── renv
├── renv.lock
└── StaticPatterns_Results_all.xlsx
There are three sections in this project: The first part (A) produces the predictors and data needed for modelling. It starts by grabbing data from the database, cleaning it, filtering it, ad then producing the predictors. The second part (B) uses the predictors to train a randomForest model and evaluate it using xAI (explainable AI), interaction effects and variable importance. In the last part (C), the model predictions are checked against the latest replication of the empirical data.
Additionally, the project contains several sensitivity analyses and robustness checks, which are not part of the main analysis but were used to aid interpretation of the results and determine patterns of stochasticity in the data.
Each R script is labelled by part (A,B,C) and script sequence (1-14).
The 00_Configuration.R script is needed for almost all other scripts. It
ensures that packages are installed and has file paths and global
variables and lookup tables needed for many steps.
-
Get data from MOBI database for first two replications (Cz, Ny, Jp, Eu)
-
Remove cells and species that were not sampled twice; filter species based on expert knowledge and introduced status
-
Prepare predictors for H1 and H2, use datasetID as H3 to determine effect of atlas in the ‘full model’
H1: Body mass, Habitat_5, Threatened_01, Generalism_01, Phylodistinct, Migration_123, Global range size
H2: Fractal dimension, Lacunarity, Spatial autocorrelation, circularity, AOO, minimum distance to the border from the centroid
H3: datasetID -
Calculate responses:
- Jaccard_dissimilarity,
- log Ratio AOO,
- log Ratio AOO per year
-
Make simulations of Jaccard_dissimilarity based on different combinations of parameters and evaluate the effect of these on the Jaccard values. Certain combinations of parameters restrict Jaccard_dissimilarity to a range of values. This can be used to determine the effect of mathematical constraints on the Jaccard_dissimilarity values.
Parameters:- initially occupied cells,
- total number of cells possible,
- number of changes
-
Train model with
- ‘all data’ and
- subsets for each datasetID (‘split data’) using random forest
-
Extract for all three responses:
- rsq, rmse,
- hyper-parameters,
- predictions,
- variable importance,
- interactions
- partial dependence plots
-
Test for phylogenetic autocorrelation for each datasetID in the model residuals (and the raw data)
-
Calculate responses from third atlas replication (Cz, Jp), use predictors calculated from second period to predict responses for the third period and get residuals
-
80/20 split (80 training, 20 testing)
-
3x repeated 10-fold cross validation
-
permutation importance (not impurity)
-
always split variables : datasetID
-
respect unordered factors = T
-
Bayesian hyperparameter tuning:
-
mtry = 2-10
-
min_n = 5-15
-
trees = 1000-5000
-
initial values = 5
-
iterations = 50
-
no improve = 10
-
set a seed.
-
-
Jaccard_dissimilarity
-
log_R2_1 (log ratio between sampling period 2 and 1)
-
log_R2_1_per_year (log ratio between sampling period 2 and 1 divided by the number of years between sampling)
-
The higher J_dissim, the more variable log_R2_1 and log_R2_1_per_year
-
The smaller AOO, the more variable log_R2_1 and log_R2_1_per_year
-
The lower D, the more variable (and more positive?) log_R2_1
-
The higher mean_lnLac, the more variable (and more positive?) log_R2_1
-
The higher mean_lnLac, the lower Jaccard_dissim
-
Species in New York and Japan are more dissimilar than species in Czechia and Europe