Codes for recent papers can be found on my GitHub page.
Population / community dynamics
The codes and data for 2014 Journal of Animal Ecology papers are deposited at Dryad:
- Territorial long-tailed skuas and their variable lemming prey in Greenland. Mostly Matlab.
- French common vole cycles. Mix of R and Matlab.
2013, Theoretical ecology. Stochastic predator-prey models for modelling population cycles (little pieces of code for my own use)
- Matlab code for numerical integration of a SDE version of Turchin & Hanski's 1997 vole-weasel model.
- Matlab code for MAR(1) predator-prey simulation. See the very detailed paper/SI of Ives et al. 2003 for the estimation with worked examples.
Predator-prey point process models (IBMs in continuous space and time) and moment equations
Please contact me if you plan to use these codes for further work, or if you encounter problems. The codes are annotated, but as I did not design them initially for public release, more information is probably needed to modify them.
I do not guarantee the programs will work outside the range of parameters we have considered in the papers (more work and debugging might be needed for new questions).
The basic predator-prey model can be found here: Murrell, D. (2005). Local spatial structure and predator-prey dynamics: Counterintuitive effects of prey enrichment. American Naturalist, 166, 354–367 [M1 , 1 predator - 1 prey model]
David has some code for that here.
Because David Murrell and I used invasion analyses later on, we had to complexify a little bit the model by adding predator and prey "species" [i.e. compartments in the model]
Barraquand, F. & Murrell, D. (2011). Evolutionarily stable consumer home range size in relation to resource demography and consumer spatial organization. Theoretical Ecology [BM1 2 predator - 1 prey model]
Barraquand, F. & Murrell, D. (2012). Intense or spatially heterogeneous predation can select against prey dispersal. PloS one, 7, e28924 [BM2, 1 predator - 2 prey model]
Unfortunately, there are very few technical documents available on how to implement point process IBMs and corresponding moment equations. For a course on the derivation of moment equations in continuous space and time, see Dieckmann, U. & Law, R. (2000). Relaxation projections and the method of moments. In: The geometry of ecological interactions: symplifying spatial complexity (eds. Dieckmann, U., Law, R. & Metz, J.). Cambridge University Press, New York, pp. 412–455.
This is for competition equations. I am hoping to prepare a tutorial with the full derivation for the predator-prey model.
Below, computer code on
- how to numerically integrate moment equations, once they have been mathematically derived
- how to simulate the corresponding IBMs
The programs are in C/C++. That's actually mostly C code, because we use struct instead of class, but I used a few C++ features to simplify notations with pointers.
See also the programs by Ben Bolker, notably to derive the moment equations with Mathematica.
Numerical integration of moment equations
The code for the numerical integration of moment equations is long but rather straightforward:
we solve an integrodifferential system, using a modifed Euler scheme for derivatives and the rectangle rule for integrals. So the code uses mostly arrays and loops. Difficulties occur however in the small details of the numerical integration (for instance, when computing integrals, the grid for distances has to include distance zero). If you have a background in numerical analysis, I am sure you'll find more efficient ways of integrating these equations (and we will be very happy to hear about it).
Here's the code to produce the deterministic trajectories of Fig. 2 in [BM1]. Another one to produce the PIP plots of Fig. 2 in [BM2].
Stochastic simulation of dynamic spatial point processes
The basic algorithm is a variant of Gillespie's algorithm [J. Phys. Chem., 1977, 81 (25), pp 2340–2361]. The algorithm in itself is not very complex, provided some familiarity with the simulation of stochastic processes (see e.g. the book by L. Devroye).
However, David Murrell and I use data structures called doubly linked lists to store the characteristics of individuals (you will find this in papers by R. Law and B. Bolker too), and these can be challenging. For more on pointers, doubly linked lists and dynamic memory, I would recommend the excellent tutorials of Nick Parlante, Stanford. The reason for using linked lists is "you have to kill in the computer memory the individuals that die in the simulation". Otherwise, the number of locations stored in the computer memory grows exponentially. Doubly linked lists are great because they allow you to remove any individual without changing the data structure, which can shrink or expand in size (useful if population size fluctuates).
The code for the IBM "invasion experiment" in Fig. 2, [BM1] is here. A more general version of this code is used to produce point patterns in Fig. S3 in [BM2] . If you are a real computer programmer, I suspect you'll find ways to improve the programming or the data structures. Please feel free to let me know...
Cautionary note: memory checking and profiling
Because the IBM simulations use dynamic memory allocation, they are very flexible but also quite prone to segmentation errors. You may check the programs with tools such as Valgrind.
Animal movement
Simon Benhamou and I deposited our code in the Ecological archives of ESA. It is in Pascal. See also adehabitatLT where Clement Calenge adapted our code for R.