R/Poisson_Sim.R

Poisson_Sim <-
function(lambda,n)  {
  x = numeric(n)
  for(i in 1:n){
    j = 0; p = exp(-lambda); F = p
    temp = runif(1)
    while((F>temp)==FALSE){
      p = lambda*p/(j+1); F = F+p; j=j+1
    }
    x[i] = j
  }
  return(x)
}

Try the ACSWR package in your browser

Any scripts or data that you put into this service are public.

ACSWR documentation built on May 2, 2019, 6:53 a.m.