-
-
Save d125q/c19450dc316fc7c79c4d to your computer and use it in GitHub Desktop.
[R] Fisherman simulation (Poisson process)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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