data(DT_envs)
# scale passport data for environments
S=scale(W)
# build a relationship matrix between environments
G=tcrossprod(S)/ncol(S)
G[1:4,1:4]
# build the dataset for the genetic algorithm
DT <- data.frame(cov=rnorm(nrow(G)), occ=1, id=rownames(G))
nLocs=10 # desired number of representative locations
# \donttest{
if(requireNamespace("evola")){
library(evola)
res<-evolafit(formula=cbind(cov, occ)~id, dt= DT,
# constraints: if sum is greater than this ignore
constraintsUB = c(Inf, Inf),
# constraints: if sum is smaller than this ignore
constraintsLB= c(-Inf, nLocs),
# weight the traits for the selection
b = c(1,0),
# population parameters
nCrosses = 100, nProgeny = 20,
recombGens=1, nChr=1, mutRateAllele=0,
# coancestry parameters
D=G, lambda= 0 , nQtlStart = nLocs,
# selection parameters
fitnessf = inbFun, selectTop = FALSE,
# fixNumQtlPerInd = TRUE,
# propSelBetween = 0.5, propSelWithin =0.5,
nGenerations = 50, verbose = TRUE)
Q <- pullQtlGeno(res$pop, simParam = res$simParam, trait=1); Q <- Q/2
best <- bestSol(res$pop, selectTop = FALSE)[,"fitness"]
solution <- Q[best,]
sum(solution) # total # of inds selected
names(solution[which(solution>0)])
evolmonitor(res)
pareto(res)
svdW <- svd(G, nu = 2, nv = 2)
PCW <- G %*% svdW$v
rownames(PCW) <- rownames(G)
plot(PCW[,1], PCW[,2], col = (solution*2)+2,
pch=(solution*14)+4, xlab = "pc1", ylab = "pc2")
labs <- rownames(PCW)
labs[which(solution==0)]=""
text(x=PCW[,1], y=PCW[,2], labels=labs, cex=0.5, pos=3)
}
# }
Run the code above in your browser using DataLab