DOI: 10.5281/zenodo.17019728
title: Repository for: Little long-term change in regional species richness of tropical butterflies over the past 166 years masks turnover in community composition.

description:  

This repository is associated with:

Ki, T.L.T., Beale, C.M., Huertas, B. & Hill, J.K. (2025). Little long-term change in regional species richness of tropical butterflies over the past 166 years masks turnover in community composition. Proceedings of the Royal Society B: Biological Sciences, doi: 10.1098/rspb.2025.1772.

In this study, we obtained species records of butterfly species from Sulawesi (Indonesia) either directly through digitisation of museum specimens or indirectly through the Global Biodiversity Information Facility. We used dynamic occupancy modelling to model changes in species occurrences for three regions of Sulawesi over time, and analysed changes in regional species richness from 1857 to 2022. 

This repository covers the scripts, functions and data files underlying all the analyses undertaken in R Studio.

Instructions:

The scripts should be run sequentially and the paths will need to be updated based on the users.

Files and variables

File: ZENODO.zip

Description: 

Subfolders:

1) data_files/

This folder contains the raw data files.



XXX_PAP_updated.shp or XXX_SAT_updated.shp - species records for swallowtail or satyrine butterflies of the Makassar & Maros (MAK_MAROS), Manado & Minahassa (MAN_MIN) and Palu Bay (WIDER_PALU) regions. Each row is a species record, and the columns refer to the species record's:



ID - Unique identifier in full dataset

Source - Source

Collection - Collection within Museum source

Location_I - Location within Museum source

Verbatim_D - Verbatim Data

Year - Year

Month - Month

Day - Day

Named_Loca - Named locality

Georeferen - Georeferenced locality

Island - Island

Lat_DD - Latitude (DD)

Long_DD - Longitude (DD)

Collector - Collector/Recorder

species - Species name

geometry - Point geometry



sulawesi_papilionidae_ecological_traits.csv - swallowtail species ecological traits used in this study. Each row is a species.



Species - Species name

Sulawesi.Endemic - Species Endemism

HP.Specificity - Species Host-plant Specificity

Forest.Dep - Species Forest Dependence



sulawesi_satyrinae_ecological_traits.csv - satyrine species ecological traits used in this study. Each row is a species.



Species - Species name

Sulawesi.Endemic - Species Endemism



XXX_annual_HADCRUT5_tas_mean.csv - annual estimates of temperature for Makassar & Maros (makassar), Manado & Minahassa (manado) and Palu Bay (palu) regions. Each row is a year.



years - Year

annual_tas - Annual temperature estimate



estimated_forest_prop_1853_2022_updated.csv - annual estimates of forest proportion for each of the three regions used in this study. Each row is a year.



year - Year

site - Region

forest_prop - Annual forest proportion estimate




2) scripts/

This folder contains the scripts for the analyses and are numbered sequentially, with a brief summary at the beginning of the purpose of the script. Where the script has been run separately for Papilionidae (a) and Satyrinae (b), the respective scripts are denoted by letters a or b.



script_01_formatting_datasets_for_SOM.R The purpose of this script is to get all the datasets in the correct format ready for the species occupancy modelling in Script 02.

script_02a_selecting_best_model_for_each_species_papilionidae.R script_02b_selecting_best_model_for_each_species_satyrinae.R The purpose of this script is to identify parameters for best species occupancy model for each species.

script_03a_extract_col_ext_occ_prob_from_best_model_papilionidae.R script_03b_extract_col_ext_occ_prob_from_best_model_satyrinae.RThe purpose of this script is to build species occupancy models (using best parameters), and then extract probabilities of occurrence (OCC), colonisation (COL) and extinction (EXT) per species per site per year.

script_04a_create_simulated_dataset_for_GOF_testing_papilionidae.R script_04b_create_simulated_dataset_for_GOF_testing_satyrinae. The purpose of this script is to create a simulated dataset for goodness-of-fit testing. We use the estimated model parameters from the occupancy modelling with the scaled covariates to create the simulated dataset.

script_05a_PAP_SOM_GOF_testing.R script_05b_SAT_SOM_GOF_testing.R The purpose of this script is to evaluate the goodness-of-fit of species occupancy models by comparing the simulated datasets from the species occupancy models from Script_04 to the real dataset.

script_06_convert_annual_site_probabilities_to_tidy_format.R The purpose of this script is to convert annual probabilities of occurrence into a tidy format ready for the main analyses. 

script_07a_PAP_gam_analyses_to_test_for_changes_across_time.R script_07b_SAT_gam_analyses_to_test_for_changes_across_time.R The purpose of this script is to run the analyses to test the research questions. 

script_8a_PAP_analyses_to_test_for_changes_across_time_inc_sp_with_poor_GOF.R script_8b_SAT_analyses_to_test_for_changes_across_time_inc_sp_with_poor_GOF.R The purpose of this script is to run the analyses again to see if including the species with poor goodness-of-fit changes our findings.

script_09_generating_species_site_occupancy_trends.R The purpose of this script is to make the plots of individual species trends for the supplementary material.


3) functions/

This folder contains the functions used for the analyses.



simDynoccProperly.R is an adapted version of code for the simDynocc function from the AHMbook package, which allowed us to supply the recording effort and environment covariate data for the data simulation process in Script 04.

stopifnot.R is downloaded from https://github.com/mikemeredith/AHMbook/blob/main/R/stopifnot.R and needs to be stored locally to allow simDynoccProperly.R above to run. 


The folders SOM_inputs/, SOM_outputs/ and analyses_outputs/  contain empty subfolders to hold intermediate files that are generated from scripts.



SOM_inputs/ will contain intermediate files that are generated from the raw data files in initial scripts (01 and 02), and are then fed into the species occupancy modelling.

SOM_outputs/ will contain intermediate files that are generated by the species occupancy modelling scripts (03, 04, 05, 06) and are then fed into the main analyses.

analyses_outputs/ will contain intermediate files that are generated by the scripts in the main analyses (07, 08, 09).