# ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ....
# MAIN PROGRAM
# Initialize parameters
Xmax <- 40 # Maximum value of X ¼ eggs
Xcritical <- 0 # Lowest value of X ¼ 0 eggs
Xinc <- 1 # Increment in state variable
Max.Index <-1þ (Xmax-Xcritical)/Xinc # Max Index value
Psurvival <- 0.99 # Survival probty per time increment
Npatch <- 4 # Number of patches ¼ hosts
# Create host coefficient matrix from which to get Benefits
Host.coeff <- matrix(0,4,4)
Host.coeff[1,] <- c(-0.2302, 2.7021, -0.2044, 0.0039)
Host.coeff[2,] <- c(-0.1444, 2.2997, -0.1170, 0.0013)
Host.coeff[3,] <- c(-0.1048, 2.2097, -0.0878, 0.0004222)
Host.coeff[4,] <- c(-0.0524, 2.0394, -0.0339, -0.0003111)
# Calculate benefit as a function of
# clutch size (rows) and Host type (columns)
Clutch <- seq(from ¼ 0, to ¼ Xmax)
Benefit <- matrix(0, Xmaxþ1, 4) # Zero to Xmax
for (I.Host in 1:4) # Iterate over host types
{
Benefit[,I.Host] <- Host.coeff[I.Host,1] þ Host.coeff[I.
Host,2]*Clutch þ Host.coeff[I.Host,3]*Clutch^2 þ Host.coeff[I.
Host,4]*Clutch^3
}
Benefit[1,] <- 0 # Reset first row to zero
SHM <- c(9,12,14,23) # Set single host maximum. See text for deri-
vation
# Make all values > than SHM¼0. Note that we use 2 because of zero
class
for (i in 1:4){Benefit[(SHM[i]þ2):Max.Index,i] <-0}
# Probability of encountering host type
Pbenefit <- c(0.05, 0.05, 0.1, 0.8)
Horizon <-
21 # Number of time steps
# Set up matrix for fitnesses
# Column 1 is F(x, t). Column 2 is F(x, tþ1) Both are zero
F.vectors <- matrix(0, Max.Index,2)
# Create matrices for output
FxtT <- matrix(0,Horizon,Max.Index) # F(x,t,T)
# Best clutch size for host 2
Best.Patch <- matrix(0,Horizon,Max.Index)
382 MODELING EVOLUTION