Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@d125q
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d125q/c19450dc316fc7c79c4d to your computer and use it in GitHub Desktop.
Save d125q/c19450dc316fc7c79c4d to your computer and use it in GitHub Desktop.
[R] Fisherman simulation (Poisson process)
number.of.fish <- function() {
k <- rpois(1, 1.2) # Use lambda = 1.2 because we care about the first 2 hours.
ifelse(k > 0, k, 1)
}
simulate <- function(simulation.count) {
if (simulation.count > 0)
mean(sapply(1:simulation.count, function(i) number.of.fish()))
}
set.seed(13)
simulate(100000) # Outputs 1.50563
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment