# The pitfalls of incidence-based time series regression for inferring the effects of weather on infectious diseases This repository hosts all the code needed to replicate the results of the study on the reliability of time series regressions in estimating the effect of weather on infectious diseases from incidence data. --- # Software versions This project relies on [renv](https://rstudio.github.io/renv/) for package management. In order to run the same package versions used originally, it is necessary to install `renv` and then run: ```R renv::restore() ``` # Hardware and sofware Simulations and fitting procedures were executed on the high-performance computing (HPC) [SLURM](https://slurm.schedmd.com/documentation.html) system Viper, of the Max Planck Computing and Data Facility, running Red Hat Enterprise Linux 9.4. Images and tables generation were carried out on a macOS 26.3 workstation equipped with an Apple M2 Pro processor (10 CPU cores) and 32 GB RAM. --- # Workflow The entire results of the work can be entirely reproduced using a SLURM cluster or locally, running a subset (or all) of simulations and analyses. --- ## Weather data and effect calibration First, in `m-Extract_weather_Popular.r`, the effects of temperature and relative humidity are calibrated based on previous studies ([Yaari et al., 2013](https://pubmed.ncbi.nlm.nih.gov/23676899/) and [Weber et al., 2001](https://pubmed.ncbi.nlm.nih.gov/11520501/)). Then, 10 years of weather data are pulled for selected locations and stored inside their independent [folder](weather_data). --- ## Main analysis via HPC cluster All combinations of variables are defined in `config.sh`. Each unique combination results in one job. Mind that `main_HPC.sh`,`copy_rds_parallel.sh` and `run_aggregate.sh` need to be adjusted in the cluster settings (in resources, limits and personal email) specifically. ### Job execution Each cluster array job: - determines its variables' combination (1 scenario x 1 location x 1 parameter set) - exports variables to the environment - runs `m-Main.r` - writes outputs to `Rout/`,`logs/` and `temp/` - results are saved in `Results` folder ### Job batch submission The [master](master_HPC.sh) script: - computes the total number of simulations - submits jobs in batches - waits for active jobs to be completed before submitting new ones - logs progress - supports safe stopping ### Results generation Once on an HPC SLURM cluster, run the line: ```bash nohup ./master_HPC.sh > logs/master_HPC.out 2>&1 & ``` This will start the entire analysis for all parameter combinations defined in `config.sh`. Running `master_HPC.sh`, which iteratively sources `main_HPC.sh`, [embarrassingly parallel](https://en.wikipedia.org/wiki/Embarrassingly_parallel) jobs are submitted to the cluster until all are completed. Each job will consist of running `m-Main.r` with a selected parameter set, location and scenario. This latter script will generate simulations and fit the tested models. Finally, performance measures are computed and everything is stored as .RData in a folder named using specific identifiers for that particular analysis. **Mind to tune the HPC bash settings according to the rules and resources of the cluster used**. For diagnostic purposes, the pipeline outputs runtime and execution logs to the directories `logs`, `temp`, and `Rout`. These record workflow progress and R session output, and can be inspected to monitor execution or troubleshoot failures. ### Data aggregation and download Once all jobs are completed, execute: ```bash batch aggregation_copy.sh ``` This will, for each parameter set and location, run on the cluster `run_aggregate.sh` that will generate in each `Results` subfolder: * `sims_tot.rds` $\rightarrow$ all simulations * `sims_reg_tot.rds` $\rightarrow$ all regressions' results * `final_pars.rds` $\rightarrow$ all combinations of parameters used Once this is finished, `copy_rds_parallel.sh`, will automatically start to copy all `.rds` files in the subfolders of `Results` in `Results_Aggregated`. In this way, one can now quickly download the latter folder ($\approx 5$ GB) on a local machine via `rsync`(more information on this [here](https://rsync.samba.org)), or any other preferred software. --- ## Main analysis on local machine It is also possible to run the entire analysis locally. ### Results' subset generation Editing `m-local_master.r`, it is possible to select the combination of parameters to use in the full analysis. The entire core pipeline will still find `m-Main.r` at its core. The running time for the simulation and fit on 100 replicates for one single parameter set, location and scenario is just under 8 seconds locally (see [here](#Hardware-and-software) for harware and sofware) utilizing 5 workers for parallel simulation and 2 for the fitting. ### Data aggregation Once this has been executed, it is possible to aggregate the results via execution of `m-Final_Analysis.r`, which will generate of each `Results` subfolder (specific for one location and parameter set): * `sims_tot.rds` $\rightarrow$ all simulations * `sims_reg_tot.rds` $\rightarrow$ all regressions' results * `final_pars.rds` $\rightarrow$ all combinations of parameters used ## Paper content ### Figures In order to reproduce the main and supplementary materials, it is sufficient to execute `Figures_Manuscript.r`, which will use the data and results present in the [folder](Results_Aggregated) with the complete aggregated results. This will create and save all figures in [Figures](`Figures`), as Portable Document Format. ### Tables All the code used to format the tables is present in `Table_Maker.r`. ### Reproducibility of reported statistics The summary statistics reported in the manuscript are derived from the same underlying data presented and can be reproduced using the script `Summ_stats.r`. --- ## License This repository is released under the [MIT License](https://opensource.org/license/mit). --- ## Contact For questions about the simulation workflow, contact gemo@mpiib-berlin.mpg.de.