# Simulation scripts and data for the stochastic modelling of evolutionary rescue in resistance to pesticides

## Abstract

Evolutionary rescue occurs when the genetic evolution of adaptation saves a population from extinction after environmental change. The evolution of resistance to pesticides is a special scenario of abrupt environmental change, where rescue occurs under strong selection for one or a few *de novo* resistance mutations of large effect. Here, we develop continuous-time approximations that accurately predict classic discrete-time dynamics in population genetics and population ecology in an integrated eco-evolutionary model of adaptive rescue through pesticide resistance. We derive analytical approximations for the key distributions and statistics that characterise the results, including the probability density function for the time to resistance and the probability of population extinction. The time to resistance shows a lag period, a narrow peak and a long tail, which implies that it can be difficult to predict when resistance will arise. The probability of population extinction shows a sharp transition, in that when extinction is possible, it is also highly likely, which can make eradication a theoretically achievable goal. Alongside these results contributing to the theory of evolutionary rescue, the methods have produced powerful approximations that lay the foundations of a flexible modelling framework for the applied study of eco-evolutionary dynamics to improve scientific resistance management.

## README: Datasets for 'Evolutionary rescue in resistance to pesticides'

https://doi.org/10.1098/rspb.2024.0805 ; https://doi.org/10.5061/dryad.n02v6wx41

There are four datasets that are used to plot the figures in the paper and the supplementary figures, which are tagged with a file name that starts with:

- ScenarioMS = multiple selection coefficients; having run the simulation under standard conditions with 6 representative selection coefficient values;
- ScenarioAS = across selection coefficients; having run the simulation under standard conditions for a large number of selection coefficient values;
- ScenarioPV = parameter variation; having run the simulation under a large number of parameter combinations;
- SpreadingProbability = simulations across selection coefficients to generate the spreading (or fixation) probability

### Description of the data and file structure

For the ScenarioMS/AS/PV datasets are generated with different inputs of the same simulation model, so the data has a repeated structure of file outputs, which are tagged with a file name that ends with:

- Input = the parameter combination inputs for the simulations
- EmergenceTimes = raw emergence times for each (stochastic) replicate and each input
- EmergenceTimePDF = probability density function of emergence times for each input
- SpreadingTimes = raw spreading times for each (stochastic) replicate and each input
- SpreadingTimePDF = probability density function of spreading times for each input
- ResistanceTimes = raw resistance times for each (stochastic) replicate and each input
- ResistanceTimePDF = probability density function of resistance times for each input
- ExtinctionTimes = raw extinction times for each (stochastic) replicate and each input
- ExtinctionTimePDF = probability density function of extinction times for each input
- MeanPopulationSizes = the mean population size across the duration of each simulation for each input

For the SpreadingProbability dataset, a smaller number of outputs are recorded as appropriate, which are tagged with a file name that contains:

- MF = maximum probability of population frequency for each input
- P = probability of extinction, fixation and other for each input
- TF = probability density function of resistance/spreading times for each input
- XT = probability density function of extinction times for each input

### Code/Software

The R code used to generate the data is included as FileS1_MainSimulations.R, FileS2_OtherSimulations.R and FileS3_Predictions.R. The R files that are used to produce the figures in the main-text and the supplement are also included: FileS4_FigureFunctions.R and FileS5_FigurePlots.R.

## Methods

The dataset was collected by running R scripts that describe a stochastic model of evolutionary rescue in resistance to pesticides. The R scripts are also included alongside the dataset.