#####
# This is the neutral Wright-Fisher model.
# No migration, mutation or selection.
# Two alleles at one locus.
# See Neuhauser 2001: 156.
# Note that this model is based on the binomial distribution (a discrete and non-negative distribution).
N <- 25 # Haploid population size.
ploid <- 2 # Ploidy level, usually haploid or diploid.
p <- 0.5 # Frequency of Allele A1 at generation i.
j <- round(p * (ploid*N)) # Number of gametes of type A1 at generation i.
gens <- 500 # Number of generations.
sims <- 10 # number of simulations to perform.
label <- paste("Generation Number; ", "Simulations = ", sims, "; ", ploid,"N =", (2*N), sep = "")
plot(1:(gens+1), seq(0,1, length.out=(gens+1)), type="n", ylim=c(0, 1), main="Neutral Wright-Fisher Model", xlab = label, ylab="Allele Frequency")
for (h in 1:sims)
{
for (i in 1:gens)
{
j[i+1] <- rbinom(1, ploid*N, p[i])
p[i+1] <- j[i+1]/(ploid*N)
}
lines(1:(gens+1), p, col=h)
}
#####