inst/resources/scripts/binom.sim.r

# program spuRs/resources/scripts/binom.sim.r

binom.sim <- function(n, p) {
  X <- 0
  px <- (1-p)^n
  Fx <- px
  U <- runif(1)
  while (Fx < U) {
    X <- X + 1
    px <- px*p/(1-p)*(n-X+1)/X
    Fx <- Fx + px
  }
  return(X)
}

Try the spuRs package in your browser

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

spuRs documentation built on May 30, 2017, 4:58 a.m.