In this exercise, you will explore a stochastic implementation of the Levins metapopulation model, modified to assume a finite number of habitat patches. The aim is to understand how patch occupancy changes over time depending on colonisation and extinction probabilities, the number of patches, and initial conditions.
This model assumes that:
We simulate this process for a number of time steps and track the overall occupancy.
Cut and paste this code into R so you can use the function later.
simulate_metapop <- function(num_patches, c , e,
time_steps, initial_occupied) {
patches <- rep(FALSE, num_patches)
patches[sample(1:num_patches, initial_occupied)] <- TRUE
occupancy_record <- numeric(time_steps)
for (t in 1:time_steps) {
new_patches <- patches
for (i in 1:num_patches) {
if (patches[i]) {
new_patches[i] <- runif(1) > e
} else {
colonize_prob <- c * mean(patches)
new_patches[i] <- runif(1) < colonize_prob
}
}
patches <- new_patches
occupancy_record[t] <- mean(patches)
}
return(occupancy_record)
}
This is how you use the function - make sure it works for you.
Note that your graph will look different to this one, since the model is stochastic.
# Set the parameters
nPatch <- 150
cVal <- 0.5
eVal <- 0.3
# Run the model
result <- simulate_metapop(num_patches = nPatch, c = cVal, e = eVal,
time_steps = 100,
initial_occupied = ceiling(nPatch / 10))
# Plot the result, including labels
plot(result, type = 'l', col = 'darkgreen', lwd = 2,
ylab = "Proportion Occupied", xlab = "Time",
main = paste0("Stochastic Levins Model (",nPatch," patches)"), ylim = c(0,1))
# Add a line for Levins' deterministic equilibrium
abline(h = 1 - eVal / cVal, col = "red", lty = 2)
You should see that the proportion of occupied patches bounces around the deterministic equilibrium of \(1 - (e/c)\). This “bouncing around” is caused by the stochastic nature of the model - it is probabilistic. On average, in the long run, the equilibrium is predictable.
Let’s explore the model further.
[This recaps some ideas from the simple deterministic Levins model, you can skip it if you are comfortable with that.]
Try different values for c (e.g. 0.1, 0.3, 0.5, 0.7)
while keeping e = 0.3 constant.
c value.Try simulations with 10, 30, 100, and 300 patches, keeping
c = 0.5 and e = 0.3 constant.
num_patches.Try setting initial_occupied to 0, 10, 50, and 100 with
100 patches, and observe how the model behaves.