3.5.5 Multiple invasibility analysis
The program follows the outline previously given and introduces a single random
mutant in each generation. The simulation is run for 5,000 generations.
R CODE:
rm(list¼ls()) # Clear memory
DD.FUNCTION<- function(X, N.total) # Density-dependence
function
{
# Set parameter values
ALPHA <- X[1] # Set alpha
N <- X[2] # Population size for this alpha
BETA <- ALPHA*0.001 # Set value of beta
N <- N*ALPHA*exp(-BETA*N.total) # New cohort size
return(N)
} # End of function
############## MAIN PROGRAM ##############
set.seed(10) # Initialize the random number seed
Maxgen <- 5000 # Number of generations run
Stats <- matrix(0,Maxgen,3) # Allocate space for statistics
MaxAlpha <- 4 # maximum value of alpha
Ninc <- 50 # Number of classes for alpha
# Allocate space to store data for each generation
Store <- matrix(0,Maxgen, Ninc)
# Allocate space for alpha class and population size
Data <- matrix(0,Ninc,2)
Data[24,2] <- 1 # Initial population size and alpha class
ALPHA <- matrix(seq(from¼2, to¼MaxAlpha, length¼Ninc),
Ninc,1) # Set Alpha
Data[,1] <- ALPHA # Place alpha in 1
st
column
for (Igen in 1:Maxgen) # Iterate over generations
{
N.total <- sum(Data[,2]) # Total population size
Data[,2] <- apply(Data,1,DD.FUNCTION, N.total) # New cohort
Store[Igen,] <- Data[,2] # Store values for this generation
# Keep track of population size, mean trait value and SD of trait
value
Stats[Igen ,2] <- sum(Data[,1]*Data[,2])/sum(Data[,2]) # Mean
S <- sum(Data[,2]) # Population size
Stats[Igen,1] <- S # Population size
SX1 <- sum(Data[,1]^2*Data[,2])
SX2 <- (sum(Data[,1]*Data[,2]))^2/S
Stats[Igen,3] <- sqrt((SX1-SX2)/(S-1)) # SD of trait
INVASIBILITY ANALYSIS 201