Dynamic modelling in SpaDES - a simple example

A Lotka-Volterra-type model

Lotka-Volterra predator-prey models are simple models that simulate the population dynamics of a prey and a predator, relying on quite a few assumptions. In this case we assume that: * in the absence of predators, the prey population density follows a logistic growth equation, that depends on its intrinsic growth rate, r, and the environment’s carrying capacity K. * in the presence of predators, the number of prey consumed is a function of the hunting/consumption efficiency if the predator, beta, and the number of predators. * the predator population density is solely dependent on the availability of prey, the predator’s ability to convert prey into energy (predation efficiency), delta, and the intrinsic death rate of the predators in the absence of prey, gamma.

Th code bellow simulates these dynamics in a for-loop in the following steps:

  1. Load necessary libraries;
  2. Define parameters entering the model;
  3. Loop the model a number of times and save the results in two vectors;
  4. Plot the results.

You’ll notice that the model is extremely sensitive to parameter values - this is a well-know feature of the Lotka-Volterra model. The ones bellow will ensure an oscillating equilibrium between prey and predator populations.

Convert this to a SpaDES module

Now to the actual exercise. Try to convert this model into a 2-module SpaDES project/model. Here are a few tips:

  1. Use newModule() (twice) to create the blank templates for your predator and prey population modules.
  2. Open the .R files that show up in the module folders.
  3. Fill in metadata:
  • Indicate libraries that are needed
  • Indicate parameters and provide their defaults
  • Indicate objects that are expected as an inputs, and objects that are created as outputs
  1. Fill in .inputObjects section to create the needed inputs.
  2. Put all the code that creates the distFromSource and establish in the “init” event.
  3. Put Plot stuff in plot event.

Build a controller for this module.

  1. Open the .Rmd file that we will use.
  2. Run one line at a time, confirming that it will run your model. You will likely need to update the module path so it knows where to find the module on your computer.

Advanced – Add space

Try to make these modules spatially explicit if you have extra time. Hints: 1. You can use raster layers, instead of vectors, to save/track preyPop and predPop and use raster-based operations to calculate how many prey and consumed in each pixel. 2. You can use data.tables to speed up the computations, where each line corresponds to a pixel in a template raster and the columns are preyPop, predPop and consumedPrey. Remaining paratemers can be in a separate data.table, or simply left as numeric vectors. Then, for plotting, you can create and replace values in rasters to show spatial variation in predator and prey densities.

One possible solution:

For prey module For predator module

This solution follows the a-spatial option.