Skip to content

Instantly share code, notes, and snippets.

@d125q d125q/fisherman-simulation.r Secret
Last active Aug 29, 2015

Embed
What would you like to do?
[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
You can’t perform that action at this time.