######################## Main program ########################
set.seed(100) # Initialize random number generator
N <- 100 # Set population size
Prop.LW <- 0.85 # Set initial proportion LW
Z.LW <- -qnorm(Prop.LW) # Threshold. Values greater are LW
MaxGen <- 10 # Number of generations
Output <- matrix(0,MaxGen,4) # Create file for output
h2 <- 0.5 # Set heritability of liability
Vp <- 1 # Set Phenotypic variance
Va <- Vp*h2 # Calculate Additive genetic variance
Ve <- Vp-Va # Calculate Environmental variance
mu <- 0 # Initial mean genetic liability
SDa <- sqrt(Va) # SD of Va
SDe <- sqrt(Ve) # SD of Ve
for (Igen in 1:MaxGen) # Iterate over generations
{
# Generate Genetic and environmental values using normal distribu-
tion
GM <- rnorm(N, mean¼mu, sd¼SDa) # Genetic values of males
GF <- rnorm(N, mean¼mu, sd¼SDa) # Genetic values of females
EM <- rnorm(N, mean¼0, sd¼SDe) # Environmental values of
males
EF <- rnorm(N, mean¼0, sd¼SDe) # Environmental value of females
PM <-GMþ EM # Phenotypic value of males
PF <-GFþ EF # Phenotypic value of females
# Calculate wing morphs by comparing liability to threshold
Male.Morph <- matrix(1,N) # Set all initially to SW (¼1)
Male.Morph[PM > Z.LW] <- 0 # Set LW to 0
Female.Morph <- matrix(1,N) # Set all initially to SW (¼1)
Female.Morph[PF > Z.LW] <
- 0 # Set LW to 0
#
Combine phenotypic and genetic values
Male <- cbind(PM, GM, Male.Morph )
Female <- cbind(PF, GF, Female.Morph)
# Store data
Output[Igen,1] <- Igen # Generation
Output[Igen,2] <- mean(PMþPF)/2 # Mean liability
Output[Igen,3] <- sum(Male.Morph)/N # Proportion of SW males
Output[Igen,4] <- sum(Female.Morph)/N # Proportion of SW females
# Calculate new mean genetic value by applying fitness criterion
mu <- SELECTION(Male,Female)
} # End of Igen loop
par(mfrow¼c(2,2)) # Divide graphics page into quadrats
# Plot proportion of SW males, and SW females over generation on same
graph
250 MODELING EVOLUTION