######################################################################################################## ## P is the vector that contains the frequencies of allele o over k generations ## Q is the vector that contains the frequencies of allele d over k generations ## c is the conversion rate (proportion) in heterozygotes of wild-type allele (o) to driver allele (d) ## s is the fitness cost of driver allele ## h is the dominance of fitness cost of driver allele in heterozygotes (do) ######################################################################################################## k=26 ## k is the number of generations P=Q=rep(0,k) ## define the vectors ## set the initial values for the frequency of alleles o and d in males and females Q[1]=0.001 P[1]=1-Q[1] ## set the values for the parameters c=0.9 s=0 h=0.5 for (t in 1:(k-1)){ ## take the frequency values in generation t q=Q[t] p=P[t] ## calculate the frequencies in generation t+1 wt=p^2+2*p*q*(1-h*s)+q^2*(1-s) P[t+1]=(p^2+(1-c)*p*q*(1-h*s))/wt ## the frequency of allele o in generation t+1 Q[t+1]=(q^2*(1-s)+(1+c)*p*q*(1-h*s))/wt ## the frequency of allele d in generation t+1 } gen=seq(0,k-1) res=cbind(gen,Q) res