Created
March 22, 2011 18:06
-
-
Save indapa/881702 to your computer and use it in GitHub Desktop.
simulate Wright-Fisher model in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#simulate Wright Fisher model | |
#see this for more info: http://www.genetics.wustl.edu/bio5488/lecture_notes_2004/popgen_1.pdf | |
wright_fisher <- function(N,m,j) { | |
#Preliminaries | |
#number of chromosomes | |
N=N | |
#number of generations | |
m = m | |
x = numeric(m) | |
#number of minor alleles in the first generation | |
x[1] = j | |
#Simulation | |
#binomial sampling at each generation - determines allele count in next generations | |
for (i in 2:m) | |
{ | |
k=(x[i-1])/N | |
n=seq(0,N,1) | |
prob=dbinom(n,N,k) | |
x[i]=sample(0:N, 1, prob=prob) | |
} | |
plot(x[1:m], type="o", pch=19) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@indapa Thanks. Could you please simulate the Wright-Fisher model in MATLAB as well?