Natural Selection Charles Darwin

Description

This module simulates the impact of natural selection on the frequencies of alleles, depending on their relative fitnesses and assuming selection is the only acting evolutionary force.

Parameters









Genotypes


	

Alleles


	

Differences


	

Fitness


	

R code

selection_coefficient = 0.001
number_of_generations = 10000

fitness_aa = 1
fitness_ab = 1
fitness_bb = 1 - selection_coefficient
freq_a = 0.5

freq_b = 1 - freq_a
freq_aa = freq_a^2
freq_ab = 2 * freq_a * freq_b
freq_bb = freq_b^2

genotypes = data.frame(t = 0, cbind(freq_aa, freq_ab, freq_bb))
alleles = data.frame(t = 0, cbind(freq_a, freq_b))

for (t in 1 : number_of_generations) {

	x_freq_a = freq_aa + 0.5 * freq_ab
	x_freq_b = freq_bb + 0.5 * freq_ab

	x_freq_aa = freq_aa * fitness_aa
	x_freq_ab = freq_ab * fitness_ab
	x_freq_bb = freq_bb * fitness_bb
	
	sum = x_freq_aa + x_freq_ab + x_freq_bb
	
	freq_aa = x_freq_aa / sum
	freq_ab = x_freq_ab / sum
	freq_bb = x_freq_bb / sum
	
	genotypes = rbind(genotypes, data.frame(t, cbind(freq_aa, freq_ab, freq_bb)))
	
	freq_a = freq_aa + 0.5 * freq_ab
	freq_b = freq_bb + 0.5 * freq_ab

	alleles = rbind(alleles, data.frame(t, cbind(freq_a, freq_b)))
}

head(genotypes)
tail(genotypes)

head(alleles)
tail(alleles)

See also Genetic Drift