Code to model and analyse random, cascade, and niche food web models. These sit alongside the group’s broader work on predicting the architecture of food webs with mechanistic models such as the ADBM.
Download the code and example data files (skip the ADBM_shiny folder) from this folder on GitHub. None of this code comes with any guarantee — it’s fairly rough and not optimised. Get in touch if you spot issues or possible corrections.
All the code is written for R. Virtually every type of ecological analysis is already available in base R and/or extension packages; R’s default graphics are of publication quality (and easily edited); it’s free, runs on Windows, Linux and Mac, and tends to be faster than many alternatives. The one real downside is the learning curve — but small steps get you up it, and the effort is rewarded.
With the code, you can:
Model food webs using random, cascade, or niche algorithms.
Plot a predation matrix of the food web.
Calculate structural properties of food webs.
Instructions
Learn how to use R.
Get the code from the GitHub folder linked above.
Source FoodWebFunctions.r into R — it contains the food-web-related functions.
Check FoodWebExamples.r for worked examples of how to use them.
A small illustration of the idea below: a “niche model” food web is generated by giving each species a random position and feeding range along a single niche axis, then connecting predators to the prey whose niche values fall within their range.
set.seed(42)niche_model <-function(S, C) {# S = number of species, C = target connectance n <-sort(runif(S)) beta <- (1/ (2* C)) -1 r <- n *rbeta(S, 1, beta) c <-runif(S, r /2, n) links <-matrix(0, S, S)for (i inseq_len(S)) { lo <- c[i] - r[i] /2 hi <- c[i] + r[i] /2 prey <-which(n >= lo & n <= hi) links[i, prey] <-1 } links}S <-25web <-niche_model(S, C =0.15)image(t(web[nrow(web):1, ]),col =c("grey95", "#0028A5"),axes =FALSE,xlab ="Prey", ylab ="Predator",main =paste0(S, "-species niche-model food web"))box()
Figure 1: A food web generated with a simple niche-model algorithm.
Neo Martinez and Alice Boit recently showed me Network3D — a note to myself to write up instructions and code that helps move between the data format used above and one Network3D can read. The R package cheddar already has a function for formatting data for Network3D.