CovP[j,i] <- CovP[i,j] # Phenotypic covariance
CovA[i,j] <- H2[i,j]*sqrt(CovA[i,i]*CovA[j,j]) # Genetic co-
variance
CovA[j,i] <- CovA[i,j] # Genetic covariance
CovE[i,j] <- CovP[i,j]-CovA[i,j] # Environmental covariance
CovE[j,i] <- CovE[i,j] # Environmental covariance
} # End of j jj:NX loop
} # End of i 1:N.minus.1 loop
Epsilon <- 0.5 # Decrement in fitness for same morph interaction
# Set up fitness matrix. Note column-wise fill
PayoffMatrix <- matrix(c(-Epsilon,-1,1,1,-Epsilon,-1,-1,1,-Epsi-
lon),3,3)
Morph <- matrix(3,Npop,1) # Set up initial morphs as all Paper
for (Igen in 1:MaxGen) # Iterate over generations
{
Output[Igen,1] <- Igen # Store generation
# Generate additive and environmental values by calling mvrorm
Trait.E <- mvrnorm(Npop, mu=Mean.E, Sigma=CovE) # Envir. value
Trait.A <- mvrnorm(Npop, mu=Mean.A, Sigma=CovA) # Genetic value
Trait.P <- Trait.A þ Trait.E # Phenotype
# Determine morphs from trait with maximum value
Morph[Trait.P[,1]>Trait.P[,2]&Trait.P[,1]>Trait.P[,3]] <-1#Rock
Morph[Trait.P[,1]>Trait.P[,2]&Trait.P[,1]<Trait.P[,3]] <-3#Paper
Morph[Trait.P[,1]<Trait.P[,2]&Trait.P[,1]>Trait.P[,3]] <-2#Scis-
sors
Morph[Trait.P[,2]>Trait.P[,1]&Trait.P[,2]>Trait.P[,3]] <-2#Scis-
sors
Morph[Trait.P[,2]>Trait.P[,1]&Trait.P[,2]<Trait.P[,3]] <-3#Paper
Morph[Trait.P[,2]<Trait.P[,1]&Trait.P[,2]>Trait.P[,3]] <-1#Rock
Morph[Trait.P[,3]>Trait.P[,1]&Trait.P[,3]>Trait.P[,2]] <-3
# Paper
Morph[Trait.P[,3]>Trait.P[,1 ] & Trait.P[,3]
<T
rait.P[,2]] <-2
# Scissors
Morph[Trait.P[,3]<Trait.P[,1] & Trait.P[,3]>Trait.P[,2]] <-1#Rock
Nos.of.Rocks <- length(Morph[Morph==1]) # Number of Rocks
Nos.of.Scissors <- length(Morph[Morph==2]) # Number of Scissors
Nos.of.Papers <- length(Morph [Morph==3]) # Number of Papers
Output[Igen,2] <- Nos .of.Rocks/Npop # Proportion of Rocks
Output[Igen,3] <- Nos.of.Scissors/Npop # Proportion of Scissors
Output[Igen,4] <- Nos.of.Papers/N pop # Proportion of Papers
# Apply selection
Mean.A <- FITNESS(Morph, Trait.A, Npop, PayoffMatrix)
} # End of generation loop
par(mfrow=c(2,2)) # 4 plots per page
plot(Output[,1], Output[,2], type=’l’, xlab=’Generation’, ylab=’-
Propn þ
X’, ylim=c(0,2)) # Plot Rocks
lines( Output[,1], Output[,3]þ0.5) # Plot Scissors þ
0.5
320 MODELING EVOLUTION