`library(landsepi)`

*See also the tutorial on how
to simulate a simple simulation for details on basic
parameterisation.*

```
<- createSimulParams(outputDir = getwd())
simul_params #> Created output directory : /tmp/RtmpjPfK8V/Rbuild2a640f42182/landsepi/vignettes/simul_landsepi_2023-01-16_15-39-50
```

```
@Seed
simul_params#> [1] 1673879990
<- setSeed(simul_params, seed = 1)
simul_params @Seed
simul_params#> [1] 1
= 6
Nyears = 120
nTSpY <- setTime(simul_params, Nyears = Nyears, nTSpY = nTSpY) simul_params
```

`<- setInoculum(simul_params, val = 5e-4) simul_params `

```
<- loadLandscape(id = 1)
landscape <- setLandscape(simul_params, land = landscape) simul_params
```

*See also the tutorial on how to parameterise landscape and
dispersal to use your own landscape and compute your own dispersal
matrices.*

A built-in parameterisation for rust pathogens of cereal crops is
available using the function `loadPathogen()`

:

`<- loadPathogen(disease = "rust") basic_patho_param `

The built-in parameterisation for “rust” simulates a pathogen which reproduces purely clonally (repro_sex_prob = 0). It is also possible to simulate a pathogen which reproduces purely sexually, or both sexually and clonally at every timestep:

```
$repro_sex_prob <- 1 ## at every time step all pathogen individuals reproduces sexually
basic_patho_param
basic_patho_param#> $name
#> [1] "rust"
#>
#> $survival_prob
#> [1] 1e-04
#>
#> $repro_sex_prob
#> [1] 1
#>
#> $infection_rate
#> [1] 0.4
#>
#> $propagule_prod_rate
#> [1] 3.125
#>
#> $latent_period_mean
#> [1] 10
#>
#> $latent_period_var
#> [1] 9
#>
#> $infectious_period_mean
#> [1] 24
#>
#> $infectious_period_var
#> [1] 105
#>
#> $sigmoid_kappa
#> [1] 5.333
#>
#> $sigmoid_sigma
#> [1] 3
#>
#> $sigmoid_plateau
#> [1] 1
#>
#> $sex_propagule_viability_limit
#> [1] 1
#>
#> $sex_propagule_release_mean
#> [1] 1
#>
#> $clonal_propagule_gradual_release
#> [1] 0
$repro_sex_prob <- 0.5 ## at every time step half of the pathogen population
basic_patho_param## reproduce clonally and half sexually
basic_patho_param#> $name
#> [1] "rust"
#>
#> $survival_prob
#> [1] 1e-04
#>
#> $repro_sex_prob
#> [1] 0.5
#>
#> $infection_rate
#> [1] 0.4
#>
#> $propagule_prod_rate
#> [1] 3.125
#>
#> $latent_period_mean
#> [1] 10
#>
#> $latent_period_var
#> [1] 9
#>
#> $infectious_period_mean
#> [1] 24
#>
#> $infectious_period_var
#> [1] 105
#>
#> $sigmoid_kappa
#> [1] 5.333
#>
#> $sigmoid_sigma
#> [1] 3
#>
#> $sigmoid_plateau
#> [1] 1
#>
#> $sex_propagule_viability_limit
#> [1] 1
#>
#> $sex_propagule_release_mean
#> [1] 1
#>
#> $clonal_propagule_gradual_release
#> [1] 0
```

To simulate a pathogen with a mixed reproduction system composed of
multiple events of clonal reproduction during the epidemic phase,
followed by a single event of sexual reproduction at the end of the
cropping season, a vector of probabilities of sexual reproduction (one
for each timestep of the cropping season) can be given
(i.e. `repro_sex_prob = 0`

during the epidemic period
`[1:nTSpY]`

, and `repro_sex_prob = 1`

at the end
of the cropping season).

`<- c(rep(0.0, nTSpY), 1.0) repro_sex_probs `

The vector containing the probability of sexual reproduction for each
timestep is used to fuel the object `simul_params`

via the
function `setReproSexProb()`

:

```
<- setReproSexProb(simul_params, repro_sex_probs)
simul_params @ReproSexProb
simul_params#> [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> [38] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> [75] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> [112] 0 0 0 0 0 0 0 0 0 1
```

Sexual propagules may be released gradually during the following seasons (i.e. years). The following parameters set the average number of cropping seasons after which a sexual propagule is released and the maximum number of cropping seasons up to which a sexual propagule is viable:

```
$sex_propagule_release_mean = 1
basic_patho_param$sex_propagule_viability_limit = 5
basic_patho_param<- setPathogen(simul_params, basic_patho_param) simul_params
```

Within a cropping season, the day of release of every sexual propagule is sampled from a uniform distribution with parameters {0;nTSpY}.

Clonal propagules produced at the end of a cropping season are
released during the following season only, either altogether at the
first day of the season (by setting the parameter
`clonal_propagule_gradual_release = FALSE`

), or progressively
(`clonal_propagule_gradual_release = TRUE`

). In the second
case the day of release of each propagule is sampled from a uniform
distribution with parameters {0;nTSpY}.

```
$clonal_propagule_gradual_release = TRUE ## clonal propagules are progressively
basic_patho_param## released during the next cropping season
$clonal_propagule_gradual_release = FALSE ## clonal propagules are released at
basic_patho_param## the first day of the next cropping season
```

Dispersal for both sexual and clonal propagules is given by
vectorised matrices giving the probability of dispersal from any field
of the landscape to any other field. The size of these matrices must be
the square of the number of fields in the landscape. It is thus specific
to both the pathogen and the landscape. For rusts pathogens, built-in
dispersal matrices (for sexual and clonal propagules) are available for
each landscape using the function
`loadDispersalPathogen()`

:

`<- loadDispersalPathogen(id = 1) disp_patho `

The first element of the list `disp_patho`

contains the
vectorized dispersal matrix for clonal propagules, while the second
element contains the vectorized dispersal matrix for sexual propagules
(by default this is a diagonal matrix, thus no between-field dispersal
of sexual propagules, i.e. sexual spores spread only locally).

```
<- disp_patho[[1]]
disp_patho_asex <- disp_patho[[2]]
disp_patho_sex head(disp_patho_asex)
#> [1] 8.814254e-01 9.525884e-04 7.079895e-10 1.594379e-10 3.285800e-06
#> [6] 3.634297e-11
head(disp_patho_sex)
#> [1] 1 0 0 0 0 0
```

Dispersal matrices can be modified, for example, to simulate a pathogen whose sexual propagules have the same dispersal ability as clonal propagules:

```
<- disp_patho[[1]]
disp_patho_asex <- disp_patho[[1]]
disp_patho_sex head(disp_patho_asex)
#> [1] 8.814254e-01 9.525884e-04 7.079895e-10 1.594379e-10 3.285800e-06
#> [6] 3.634297e-11
head(disp_patho_sex)
#> [1] 8.814254e-01 9.525884e-04 7.079895e-10 1.594379e-10 3.285800e-06
#> [6] 3.634297e-11
```

Then, the object `simul_params`

is updated with the
dispersal matrices via the function
`setDispersalPathogen()`

:

`<- setDispersalPathogen(simul_params, disp_patho_asex, disp_patho_sex) simul_params `

For a given parental pair, the genotype of each propagule is issued
from random loci segregation of parental qualitative resistance genes.
For each quantitative resistance gene, the value of each propagule trait
is issued from a normal distribution around the average of the parental
traits, with standard deviation defined by the parameter
`recombination_sd`

, following the infinitesimal model (Fisher
1919).

```
# Resistance genes
<- loadGene(name = "gene 1", type = "majorGene")
gene1 <- loadGene(name = "gene 2", type = "QTL")
gene2
#gene2$recombination_sd <- 0.8
$Nlevels_aggressiveness <- 3
gene2<- data.frame(rbind(gene1, gene2), stringsAsFactors = FALSE) genes
```

All the other steps (e.g. setting croptypes, cultivars, resistance genes …) are not impacted by pathogen reproduction system, they are fully described in running a simple simulation

```
# Cultivars
<- loadCultivar(name = "Susceptible", type = "growingHost")
cultivar1 <- loadCultivar(name = "Resistant1", type = "growingHost")
cultivar2 <- loadCultivar(name = "Resistant2", type = "growingHost")
cultivar3 <- data.frame(rbind(cultivar1, cultivar2, cultivar3)
cultivars stringsAsFactors = FALSE)
,
# Allocating genes to cultivars
<- setGenes(simul_params, dfGenes = genes)
simul_params <- setCultivars(simul_params, dfCultivars = cultivars)
simul_params
<- allocateCultivarGenes(simul_params
simul_params cultivarName = "Resistant1"
, listGenesNames = c("gene 1"))
, <- allocateCultivarGenes(simul_params
simul_params cultivarName = "Resistant2"
, listGenesNames = c("gene 2"))
,
# Allocating cultivars to croptypes
<- loadCroptypes(simul_params, names = c("Susceptible crop"
croptypes "Resistant crop 1"
, "Resistant crop 2"))
,
<- allocateCroptypeCultivars(croptypes
croptypes croptypeName = "Susceptible crop"
, cultivarsInCroptype = "Susceptible")
, <- allocateCroptypeCultivars(croptypes
croptypes croptypeName = "Resistant crop 1"
, cultivarsInCroptype = "Resistant1")
, <- allocateCroptypeCultivars(croptypes
croptypes croptypeName = "Resistant crop 2"
, cultivarsInCroptype = "Resistant2")
,
<- setCroptypes(simul_params, dfCroptypes = croptypes)
simul_params
# Allocating croptypes to fields of the landscape
<- croptypes$croptypeID ## No rotation -> 1 rotation_sequence element
rotation_sequence <- 0 # number of years before rotation of the landscape
rotation_period <- c(1/3,1/3,1/3) # proportion (in surface) of each croptype
prop <- 0 # level of spatial aggregation
aggreg <- allocateLandscapeCroptypes(simul_params
simul_params rotation_period = rotation_period
, rotation_sequence = rotation_sequence
, prop = prop
, aggreg = aggreg
, graphic = FALSE)
,
# Define fungicide treatments
# treatment <- list(treatment_reduction_rate = 1,
# treatment_efficiency = 0.8,
# treatment_timesteps = vector() ,
# #treatment_timesteps = c(7,21,35) ,
# treatment_cultivars = vector(),
# #cultivars= c(0),
# treatment_cost = 0)
# simul_params <- setTreatment(simul_params, treatment)
# Choosing output variables
<- loadOutputs(epid_outputs = "all", evol_outputs = "all")
outputlist
<- setOutputs(simul_params, outputlist) simul_params
```

```
checkSimulParams(simul_params)
runSimul(simul_params, graphic = TRUE, videoMP4 = FALSE)
```