Genetic Drift Genetic drift


This module simulates genetic drift under complete neutrality where is no selection for or against the different alleles (variants). The initial distribution of the variants in the population is random. Depending on the population size, number of variants, and number of generations, the random genetic drift of the alleles will reduce the number of alleles and eventually eliminate the of variations, leading to fixation of only one in the population.


Drifting of Variants

Number of Variants

R code

number_of_variants = 10 # Number of alleles
population_size = 100
number_of_generations = 1000 # Maximum number of generations
# Generate initial distribution of variants
variants = sample (LETTERS[1:number_of_variants], population_size, replace = TRUE)
# Display initial counts (t = 0)
generations = data.frame(t = 0, table(variants))
# Iterate over the number of generations
for (t in 1 : number_of_generations) {
	# Sample
	variants = sample(variants, population_size, replace = TRUE)
	counts = table(variants)
	generations = rbind(generations, data.frame(t, counts))
	if (length(counts) == 1)
		break # Stop if number of variants drops to 1
# Display final counts

See also Natural Selection