Trait.X <- 2*(Pxy*X.loci þ Pc*C.loci) # Mean value of X
Trait.Y <- 2*(Pxy*Y.loci þ S*Pc*C.loci) # Mean value of Y
# Genetic variance of iX/i and Y
VarGX <- 2*(X.loci*Pxy*(1-Pxy)þ C.loci*Pc*(1-Pc))
VarGY <- 2*(Y.loci*Pxy*(1-Pxy)þ C.loci*Pc*(1-Pc))
CovGXY <- 2*C.loci*Pc*(1-Pc) # Genetic covariance
Rg <- S*CovGXY/sqrt(VarGX*VarGY) # Genetic correlation
print(c(Rg, VarGX, VarGY, Trait.X, Trait.Y)) # Print out values
# Calculate the environmental correlation
Re <- (Rp - Rg*sqrt(h2.X*h2.Y))/sqrt((1-h2.X)*(1-h2.Y))
# Check that this Re is possible
if (abs(Re)>1) stop (c(“Re not possible”))
# Environmental Variances and Standard deviations
Ve.X <- (1-h2.X)*VarGX/h2.X # Environmental variance for X
SDe.X <- sqrt(Ve.X) # Environmental SD for X
Ve.Y < (1-h2.Y)*VarGY/h2.Y # Environmental variance for Y
SDe.Y <- sqrt(Ve.Y) # Environmental SD for Y
CovE <- Re*SDe.X*SDe.Y # Environmental covariance
Ematrix <- matrix(c (V e.X ,Cov E, Co vE,V e. Y) ,2,2) # Covariance
matrix
# Nos of loci in each category
Nx.Alleles <- ASSIGN.LOCI(X.loci,N.Pop, Pxy)# Alleles uniqueto X
Ny.Alleles<- ASSIGN.LOCI(Y.loci, N.Pop, Pxy) # Alleles uniqueto Y
Nc.Alleles <- ASSIGN.LOCI(C.loci, N.Pop, Pc) # Alleles commontoX&Y
# Now make three matrices for loci in individuals
G.Xmatrix <- matrix(Nx.Alleles, N.Pop, 2*X.loci) # X composition
G.Ymatrix <- matrix(Ny.Alleles, N.Pop, 2*Y.loci) # Y composition
G.Cmatrix <- matrix(Nc.Alleles, N.Pop, 2*C.loci) # C composition
The above coding generates the three matrices. A sample output for G.Xmatrix is
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]
1 1 0 1 1 1100 1
[2,] 1 1 1 1 1 0111 1
[3,] 1 1 1 1 1 1111 1
[4,] 1 1 1 1 1 1111 1
[5,] 0 1 0 1 1 1101 1
[6,] 1 1 1 1 1 1111 1
Note that there are 6 rows, corresponding to 6 individuals, and 10 columns,
corresponding
to 5 diploid loci. We can get the actual genetic variances using
the two R functions rowSums, which calculates the sum of the values in each row
(which is the genetic value of the individual), and var, which calculates the
variances among these sums:
238 MODELING EVOLUTION