Wageningen University & Research | FEM-31806 | Models for Ecological Systems | FEM | PPS | WEC

Here, we provide a basic R script template that you can use as backbone to implement an ODE model in order to solve it numerically. To solve the model, we will be using the R package deSolve. The template will be split into separate parts, starting with a very basic template, and over the course of the next days we add additional template files that will expand the basic template to accommodate additional functionality and analyses, e.g. the inclusion of driving variables, mass balance checks, sensitivity analysis, calibration and model evaluation.

Each template consists of (at least) 4 steps:

  1. defining a function to create a named vector with initial state values
  2. defining a function to create a named vector with parameter values
  3. defining a function that returns the rates of change of the state variables with respect to time
  4. solving the model numerically using the ode function in the deSolve package.

Here, we use the convention that we give a model an informative name, for example Modelname, so that we can give the functions in steps 1-3 as listed above the names InitModelname, ParmsModelname, RatesModelname, respectively. Thus, we will replace “Modelname” in the name of these 3 functions with the name of the model we are working on: in the example of template 1 these functions will thus be called InitLogistic, ParmsLogistic and RatesLogistic.