# \donttest{
# A typical work flow would consist of:
# 1. Reduce the number of explanatory variables
data(Poptri.baseline.env)
data(Poptri.future.env)
VIF.select <- VIF.subset(Poptri.baseline.env,
keep=c("MAT", "CMI"),
cor.plot=TRUE)
VIF.select$VIF$vars.included
baseline.env <- Poptri.baseline.env[, VIF.select$VIF$vars.included]
summary(baseline.env)
future.env <- Poptri.future.env[, VIF.select$VIF$vars.included]
# 2. Create the genpop object
data(Poptri.genind)
Poptri.genpop <- adegenet::genind2genpop(Poptri.genind)
# Get to know the populations and the alleles
poppr::poppr(Poptri.genind)
adegenet::makefreq(Poptri.genpop)
# 3. Calibrate the models
# Note that the ordistep procedure is not needed
# CCA model only to compare results with those by Blumstein et al. 2020
Poptri.count.model <- count.model(Poptri.genpop,
permutations=9, # use 999 or more
env.data=baseline.env,
ordistep=FALSE,
cca.model=FALSE)
Poptri.pred.baseline <- count.pred(Poptri.count.model, env.data=baseline.env)
head(Poptri.pred.baseline)
Poptri.freq.model <- freq.model(Poptri.pred.baseline)
Poptri.freq.baseline <- freq.pred(Poptri.freq.model,
count.predicted=Poptri.pred.baseline)
head(Poptri.freq.baseline)
# 4. Check how well the models predict baseline allele frequencies
# Populations are split in those with R2 > 0.50 and those with R2 < 0.50
# Better populations
plotA1 <- freq.ggplot(Poptri.freq.baseline,
plot.best=TRUE,
ylim=c(0.0, 0.8))
# plotA1
# Populations with low R2
manual.colour.values1 <- ggsci::pal_npg()(5)
plotB1 <- freq.ggplot(Poptri.freq.baseline,
plot.best=FALSE,
manual.colour.values=manual.colour.values1,
xlim=c(0, 0.5),
ylim=c(0, 0.25))
# plotB1
# Colouring by alleles
plotA2 <- freq.ggplot(Poptri.freq.baseline,
colour.Pop=FALSE,
plot.best=TRUE,
ylim=c(0.0, 0.8),
manual.colour.values=manual.colour.values1)
# plotA2
plotB2 <- freq.ggplot(Poptri.freq.baseline,
colour.Pop=FALSE,
plot.best=FALSE,
manual.colour.values=manual.colour.values1,
xlim=c(0, 0.5),
ylim=c(0, 0.25))
# plotB2
# 5. Predict future allele frequencies
Poptri.pred.future <- count.pred(Poptri.count.model, env.data=future.env)
head(Poptri.pred.future)
Poptri.freq.future <- freq.pred(Poptri.freq.model,
count.predicted=Poptri.pred.future)
# The key results are variables 'Allele.freq' representing the baseline allele frequencies
# and variables 'Freq.e2', the predicted frequency for the future/ past climate.
# Variable 'Freq.e1' is the predicted allele frequency in step 1
head(Poptri.freq.future)
# 5. Visualize the changes
# See functions shift.dot.ggplot, shift.pie.ggplot, shift.moon.gpplot,
# shift.waffle.ggplot and shift.surf.ggplot
# }
Run the code above in your browser using DataLab