Created
June 28, 2015 04:31
-
-
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/
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
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