[R] [help] simulation of a simple Marcov Stochastic process for population genetics

z3mao zhangyij at gmail.com
Thu Aug 21 12:00:51 CEST 2008


Hi, this is my first time using R. I want to simulate the following process:
"in a population of size N, there are i individuals bearing genotype A, the
number of those bearing A is j in the next generation, which following a
binominal distribution (choose j from 2*N, the p is i/2*N), to plot the
probability of the next generations, my script is as follows. It cannot run
successfully, declaring that the "ylim should be limited. " I wonder where
the bug is. Thanks very much!

generation<-function(i,N)
{
    m<-1;gen<-numeric(); 
    for(m in 1:50)
  {
   testp<-runif(1,0,1);
    j<-0; sump<-0;
    while(sump < testp)
      {  sump<-sump+dbinom(j,2*N,i/(2*N));
         j<-j+1;
       }
     i<-j; gen[m]<-j/(2*N); m<-m+1; 
   }
  plot(m, gen[m]); 
}
-- 
View this message in context: http://www.nabble.com/-help--simulation-of-a-simple-Marcov-Stochastic-process-for-population-genetics-tp19085705p19085705.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list