Skip to content

Instantly share code, notes, and snippets.

@TonyLadson
Created June 28, 2015 04:31
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 TonyLadson/f7bc098a71c770bb2919 to your computer and use it in GitHub Desktop.
Save TonyLadson/f7bc098a71c770bb2919 to your computer and use it in GitHub Desktop.
Examples: Binomial distribution as applied to the 100-year flood https://tonyladson.wordpress.com/2015/06/22/100-year-flood-binomial-distribution/
dbinom(0,100,0.01) # zero 1% floods in 100 years
dbinom(1,100,0.01) # one 1% floods in 100 years
dbinom(2,100,0.01) # two 1% floods in 100 years
dbinom(3,100,0.01) # three 1% floods in 100 years
dbinom(4,100,0.01) # four 1% floods in 100 years
dbinom(5,100,0.01) # five 1% floods in 100 years
# at least 1 1% flood in 100 years
1 - pbinom(0,100, 0.01)
# Sample calculation
# Exactly 2 1% floods in 100 years
choose(100,2) * 0.01^2 * (1 - 0.01)^98
#[1] 0.1848648
par(oma = c(1, 2, 0, 0))
barplot(dbinom(0:5,100,0.01),
ylim = c(0, 0.4),
las = 1,
names.arg = 0:5,
ylab = 'Probability',
xlab = 'Number of 100-year floods in 100 years')
set.seed(2000)
rbinom(10, 100, 0.01)
#[1] 0 1 0 1 2 1 3 1 2 1
# number of 100-year floods in each of 10 100-year sequences
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment