# Col 1=Prop.H, col 2=Delta Prop.H, col3=P.Hawks, 3=Delta P.Hawks
PayoffMatrix <- matrix(c(-1,0,8,4),2,2) # Set up Payoff matrix
# Calculate theoretical frequency
a <- PayoffMatrix[1,1]
b <- PayoffMatrix[1,2]
c <- PayoffMatrix[2,1]
d <- PayoffMatrix[2,2]
P.Hawks <- (b-d)/(bþc-a-d) # Expected proportion of hawks
Data[,1] <- seq(from=0.01, to=0.95, length=MaxProp) # Propn of H
allele
for (Prop in 1:MaxProp) # Iterate over Proportions
{
# Calculate the number of each genotype as integers
Prop.H <- Data[Prop,1] # Get Proportion of H allele
HH <- round(Prop.H^2*Npop) # Number of HH genotypes
HD <- round(2*Prop.H*(1-Prop.H)*Npop)# Number of HD genotypes
Morph[1:Npop] <- 2 # Set initially to doves
Nos.of.Hawks <-HHþ HD # Assuming that HD is a Hawk
Morph[1:Nos.of.Hawks] <- 1 # Set rows 1 to Nos.of.Hawks to hawks
Nos.of.Hawks <- sum(Morph[Morph==1]) # The nos of Hawks
# Calculate new proportion of H allele by applying fitness criterion
New.Prop.H <- FITNESS(Morph, PayoffMatrix, HH, HD, Npop)
Data[Prop,2] <- New.Prop.H - Prop.H # Change in propn of H allele
Data[Prop,3]<- Prop.H^2þ 2*Prop.H*(1-Prop.H) # P.Hawks
New.Hawks <- New.Prop.H^2þ 2*New.Prop.H*(1-New.Prop.H)# New P.Hawks
Data[Prop,4] <- New.Hawks - Data[Prop,3] # Delta P.Hawks
} # End of Prop loop
# Plot Change in proportions as a function of P.Hawks
Ymax <- max(Data[,2],Data[,4]) # Maximum Y value
Ymin <- min(Data[,2],Data[,4]) # Minimum Y value
# Plot Change in Proportion of H allele
plot(Data[,1], Data[,2], type=’l’,lty=2, xlab=’Initial
Proportion (P or P.Hawks)’, ylab=’Change (in P or P.Hawks)’,
ylim=c(Ymin,Ymax))
lines(Data[,3], Data[,4], type=’l’) # Plot change in proportion
of Hawks
lines(Data[,1], rep(0,MaxProp)) # Plot theoretical ESS as
horizontal line
points(P.Hawks, 0, pch=“X”, cex=2) # Plot X at ESS. cex sets size
of X
# Apply smooth spline to smooth out curves
lines(smooth.spline(Data[,1],Data[,2]))
lines(smooth.spline(Data[,3],Data[,4]))
OUTPUT: (Figure 5.3)
290 MODELING EVOLUTION