Monday, March 5, 2012

Function to model selection at a biallelic locus

This is not for phytools, but I am teaching evolutionary biology to undergrads this semester. We are presently studying population genetics and for class tomorrow I decided to write an R function to illustrate selection at one locus. The function takes a starting allele frequency and fitnesses for each of the three genotypes as input, and then it can plot various things: the frequency of A or a over time; the mean fitness through time; and the population mean fitness as a function of p. The function is as follows:

  p<-wbar<-vector(); p[1]<-p0
  for(i in 2:time){
      xlab="time",main="frequency of A")
    else if(show=="q")
      ylab="q",main="frequency of a")
    else if(show=="fitness")
      xlab="time",main="mean fitness")
    else if(show=="surface")
    else {
      message("not a recognized option")
    plot(p,wbar,type="l",ylim=c(0,1),main="mean fitness")

Here is an example of a run to illustrate selection on A in which the fitness advantage of the A allele is recessive.

No comments:

Post a Comment