5.12 Adding a population size variable
Using the freq
variable also gives us more flexibility than hard-coding an allele frequency into the rbinom
command.
Add to your code so that we also provide Ne
(effective population size) as a variable (without updating it in the for loop).
# set effective population size outside of for loop
Ne <- 100
# start an initial AF of 0.5
freq <- 0.5
for (i in 1:3) {
# run rbinom to generate the AF for the next generation
new_freq <- rbinom(n = 1, size = Ne, prob = freq) / Ne
# print new AF
print(new_freq)
# update `freq` in each iteration of the loop
freq <- new_freq
}
## [1] 0.53
## [1] 0.47
## [1] 0.43