run.popgensim | R Documentation |
performs a time-forward, agent-based and spatiallly explicit genetic population simulation
run.popgensim(
simpops,
steps,
cost.mat,
n.offspring,
n.ind,
mig.rate,
disp.max,
disp.rate,
n.allels,
mut.rate,
n.cov = 3,
rec = "none",
emi.table = NULL
)
simpops |
pops object (a list of pop) |
steps |
the number of steps (generations) |
cost.mat |
a cost matrix (e.g. calculated via costDistance) |
n.offspring |
number of offsprings per female |
n.ind |
number of individuals |
mig.rate |
migration rate |
disp.max |
dispersal distance of disp.rate individuals |
disp.rate |
percentage of individuals achieving disp.max |
n.allels |
number of maximal alleles at a loci |
mut.rate |
mutation rate |
n.cov |
number of covariates (defaults to 3) |
rec |
switch if emigration matrix should be recorded, either "none" or "emi" |
emi.table |
a emigration matrix, if provide a fixed number of migration events will take place otherwise based on disp.max, mig.rate and disp.rate, |
A pops object created via init.popgensim
is used as input. The function simulates time forward individual-based spatially explicit population dynamics. Subpopulations are linked by dispersal that can be specified via a pairwise distance matrix between subpopulations [cost.mat]. Distances are converted to a probability. Currenlty the function used is the p2p function, where dispersal is modeled using an exponential function, that can be specified via disp.max and disp.rate. disp.max specifies the maximal distance that are achieved by the proportion of disp.rate individuals in a subpopulation. The number of dispersers per generation is set to round(mig.rate * n.ind). A simple mutation rate can be specified (the probability of a mutation per loci) using mut.rate. The maximal allowed number of alleles per loci need to be specified. Currently the mutation model is a simple Kmax-allele model [n.alleles]. As before n.cov is the number if covariates in the data.frame (currenlty fixed to n.cov=3). To track emigration events between subpopulations (be aware output is then a list instead of a simple pops object) rec can be set to "emi", which provides a matrix that shows the actual emigrations between subpopulations during the simulation. Emigration can also be determistic (instead of using disp.max and disp.rate) to a specified number of dispersal events per subpopulations. Over each generation events are occuring in that order: 1. dispersal, 2. reproduction, 3. mutation. For convinience the simulation can be run a specified number of generations [steps]. In case extra dynamics need to be modelled (e.g. one population is increased in number be a managment action or population are affected by environmental factors) simulations can also run only in single time steps [steps=1]. See example.
an updated pops object after steps time steps or a list that includes the pops object and the emigration matrix [rec="emi"].
init.popgensim
library(raster)
set.seed(1)
locs <- cbind(x=round(runif(5,5,45)), y=round(runif(5,5,45)) )
cm <- as.matrix(dist(locs))
pops <- init.popgensim(n.pops = 5, n.ind=20, sex.ratio = 0.25, n.loci = 5, n.allels = 10, n.cov = 3)
#run pops
pops <- run.popgensim(pops, steps = 200, cost.mat= cm, n.offspring = 2, n.ind = 20,
mig.rate = 0.125, disp.max = 30, disp.rate =0.1, n.allels = 10, mut.rate = 0)
#convert to genind object
pops.gi <-pops2genind(pops)
#calculate pairwise fsts using pairwise.fstb
fsts <- pairwise.fstb(pops.gi)
#plot
plot(locs, xlim=c(0,50), ylim=c(0,50), pch=16,cex=4, col="darkgrey")
for (i in 1:4)
for (ii in (i+1):5)
lines(c(locs[i,1], locs[ii,1]), c(locs[i,2], locs[ii,2]), lwd=fsts[i,ii]*30, col="darkgreen")
text(locs+0.5, labels=1:5, col="white", font=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.