Advanced Exercises in Dispersal - Simulating an Epidemic

Throughout the exercises in dispersal, the focus has been on examining and comparing the mechanisms and assumptions that would lead to approximate exponential or power law distribution, or related distributions of propagules or disease as a function of distance from source. We can also study dispersal by asking questions that pertain to the source of inoculum. For instance, when would the starting distribution of infections be random? The distribution of initial infection is a function of the type of inoculum that initiates an epidemic. If infested seed is the source of initial infection, this would result in a random distribution to the extent that infested seed is randomly mixed with clean seed. If aerial dispersal of propagules into a field initiates the epidemic, the resulting distribution would tend to be approximately random if propagules have moved a substantial distance from the original source. By contrast, if the source of propagules is an adjacent field, propagules will tend to be deposited more heavily near that field. The distribution of infection will also differ from random, even if the distribution of propagules is random, when the biotic and abiotic environment is not homogeneous. For example, if some areas of a field are wetter, these patches will favor infection for many types of pathogens. Also, if different genotypes or species are planted across the field, such that there are different levels of resistance present, infection may be patchy.

Such concepts about dispersal can be studied via simulation. In the R code that follows, dispersal within a field will be explored, beginning with the case of random positioning of initial infections. First, a simple model of disease spread will be considered. For these exercises, we recommend that you work through this section-by-section, especially spending time to understand what the R code does. The information presented in this section on dispersal also provides an introduction to how exploration of disease processes may be handled through spatial statistics (Sparks et al. (2008).

To begin, suppose you would like to generate a simulated map of individual plants and their infection status, where infections are randomly assigned to individuals in the initial map and the number of infections per individual is tallied. One way to do this in R is as follows. Check out the contents of the different objects along the way. Use the help(sample) command to understand the sample function better.

# First generate a matrix of dimension 10x10 containing # zeroes, where zero indicates no infectionmap1 <-matrix(0,10,10)# Randomly select row and column coordinates for n1 initial# infections, where n1 can be assigned any valuen1 <-3row1 <-sample(1:10,size=n1, replace=T)col1 <-sample(1:10, size=n1, replace=T)# Assign the infections to the plants corresponding to the # randomly drawn coordinates, and look at the new mapfor(j in1:n1) { map1[row1[j],col1[j]] <- map1[row1[j],col1[j]] +1}map1

For example, here is one representation of three initial randomly infected plants:

Repeat this step a few times each for different values of n1, the initial number of infections, to get a feel for the appearance of a random distribution of infection. If you pick very large numbers of n1, the results may start to become unrealistic for many host-pathogen systems because host tissue would become limiting.

As a first step to modeling dispersal of pathogens, you might consider even simpler functions to describe the dispersal gradient than the exponential and power law models. Suppose we start with a scenario much simpler than dispersal following some probability distribution. For most dispersal modeling, nearer dispersal is more likely and distant dispersal is less likely. Instead, suppose that pathogens always disperse in equal numbers to the plants directly adjacent to an infected plant on a square grid. This is sometimes described as one "rook's move", with reference to the moves possible for the chess piece.

To consider this type of movement, start by generating a map of a small number of initial infections using the method above to generate map1.

Next simulate one generation of pathogen reproduction and dispersal. The following simulation has five successful propagules produced for each existing infection and one of these disperses one step to the north, one disperses one step to the south, one disperses one step to the east, one disperses one step to the west, and one infects the same host. Note that following this method, some pathogen propagules will effectively be lost off the edge of the map.

To simulate n2 generations of dispersal, try the following. This also relies on having map1 generated as above with a small number of initial infections. Check out the objects created in each step (for each step that is not within a loop). Note that this is essentially the same set of commands as the example for the creation of map2, but executed n2 - 1 times.

#Assign the number of generations of # dispersal to be studied, n2n2 <-5#Set up mapn as a list that includes n2 mapsmapn <-as.list(1:n2)#Initialize each of the n2 maps to contain zeroesfor(j in1:n2){mapn[[j]] <-matrix(0,10,10)}#For each of the next mapsmapn[[1]] <- map1for(j in2:n2){#Temporarily make the map the same as one generation back mapn[[j]] <- mapn[[j-1]]#Then add the new infections following the rooks' movesfor(xrow in1:10){for(xcol in1:10){ numprop <- mapn[[j-1]][xrow,xcol] if(xrow > 1){mapn[[j]][xrow-1,xcol] <- mapn[[j]][xrow-1,xcol] + numprop}if(xrow < 10){mapn[[j]] [xrow+1,xcol] <- mapn[[j]][xrow+1,xcol] + numprop}if(xcol < 10){mapn[[j]] [xrow,xcol+1] <- mapn[[j]][xrow,xcol+1] + numprop}if(xcol > 1){mapn[[j]] [xrow,xcol-1] <- mapn[[j]][xrow,xcol-1] + numprop} mapn[[j]][xrow,xcol] <- mapn[[j]][xrow,xcol] + numprop } }}#See what mapn looks likemapn

The output mapn is a list in which each matrix is a map after a new generation of dispersal.

Suggested exercise

Try this for a series of different initial maps generated as map1. To do this, you could cut and paste the material from above when needed. Alternatively, you could create a function that performs these steps, as below.

You could use this function as in the following examples (which assume you have a matrix map1 already created). You could try this command after generating different versions of map1 to compare the patterns.

disperse(map1,n2=3)disperse(map1,n2=5)

In the above examples, locations were randomly selected individual hosts where the number of infections was tallied. It might be more realistic to consider a situation where the initial infections are randomly applied to a continuous map. That is, nstart infections are assigned to continuous x and y coordinates in a 1000 m by 1000 m map. The random assignment is performed using the runif function. This function generates random numbers with a uniform distribution across the range requested. Try help(runif) for more information.

#Assign the number of initial infections, nstartnstart <-20#Randomly draw x and y coordinates for the initial infectionsrow1 <-runif(n=nstart, min=0, max=1000)col1 <-runif(n=nstart, min=0, max=1000)#Plot the initial infectionsplot(row1, col1, xlab="East-West", ylab="North-South", pch=19, col="red")

Click on the image for larger version.

Next, suppose that each infection produces nnew new infections in the next pathogen generation. These new infections are equally likely to occur in any direction from the source infection. (When would this assumption not be reasonable?) The coordinates for a randomly-drawn direction can be generated as follows, again using the runif function, but ranging from -? to ?. Here the random variables are transformed with functions sin and cos to generate points in all possible directions from a source in two dimensions.

#Assign the new number of infections from # each initial infection, nnewnnew <-50#Generate nnew random directions from a sourcetemp <-runif(n=nnew, min=-pi, max=pi)#Plot the points in the different directions, # for wno equidistant from sourceplot(sin(temp),cos(temp))

Suppose the distance from the source at which a new infection occurs is described by an exponential model. R supplies a function to generate random numbers generated from an exponential distribution, as well as the uniform distribution used above and many others (see Garrett et al. In Press). The rexp function generates random variables drawn from an exponential distribution with parameter rate. You can get a feel for how the rate parameter affects the shape of the distribution by trying the following. The hist command produces a histogram of the variables generated. If n=500 or more variables are generated, this gives a pretty clear idea of the shape of the distribution. If a small number of variables are generated, the shape is not so clear. But it is also informative to try drawing just a small number n of samples from the distribution to get a feel for what it means to "draw from a distribution".

hist(rexp(n=500, rate=1),col="blue")

Click on the image for larger version.

Now, combine the initial random map of infections, the random direction of new infections, and the exponential model describing the distance at which new infections occur. The following function is the first step for generating maps of infection for ngen generations.

# nstart is the number of initial infections# nnew is the number of new infections produced by each # pre-existing infection each generation# ngen is the number of generations# exppar is the rate parameter for # the exponential distributiondisperse2 <-function(nstart, nnew, ngen, exppar){ coord <-matrix(runif(n=2*nstart, min=0, max=1000),nrow=nstart, ncol=2) ntot <- nstartfor(i in1:ngen){for(j in1:ntot){ tempx <- coord[j,1] tempy <- coord[j,2] newdir <-runif(n=nnew, min=-pi, max=pi) newdist <-rexp(n=nnew, rate=exppar) newx <- tempx + newdist *sin(newdir) newy <- tempy + newdist *cos(newdir) newcoord <-cbind(newx,newy) coord <-rbind(coord,newcoord) } ntot <-length(coord[,1]) }coord}

Try the following commands, varying the values of the input parameters. Especially try different values of the exponential paramater, exppar. More fun than a video game?

As a more advanced exercise, try generating different maps using R functions that generate random numbers from the related gamma and Weibull distributions, too: rgamma and rweibull. Try different values of the shape and scale parameters for both these distributions too. Here are examples to remind you of the shape of those distributions; you can change the shape parameters to plot histograms representing the different parameter combinations.

Note that there are several different ways to get similar-looking spatial patterns. In a practical application, such as trying to model a real epidemic, it may not matter greatly which of these models you use. This exercise is intended to give you an idea of some of the tools available.

Get ALL the Latest Updates for ICPP2018: PLANT HEALTH IN A GLOBAL ECONOMY. Follow APS!