Last active
April 30, 2018 13:53
-
-
Save JonasMoss/aabd90cc45c0a6025986ba93c7edecb1 to your computer and use it in GitHub Desktop.
Illustration of negative binomial.
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
#' Graph of number of tries needed to obtain K successes. | |
#' @param K number of studies. | |
#' @return NULL. | |
plotter = function(K){ | |
kk = 0:(K*70) | |
plot(kk + K, dnbinom(kk, K, 0.05), bty = "l", type = "b", pch = 20, | |
xlab = "Number of studies", | |
ylab = "Probability", | |
main = paste0("Number of studies before ", K, " successes")) | |
abline(v = 0.95/0.05*K + K, lty = 2) | |
abline(v = floor(0.95/0.05*(K-1) + K), lty = 2, col = "red") | |
abline(v = qnbinom(0.5, K, 0.05) + K, lty = 2, col = "blue") | |
legend("topright", col = c("black", "blue", "red"), | |
lty = c(2, 2, 2), legend = c( | |
paste0("Mean: ", 0.95/0.05*K + K), | |
paste0("Mode: ", floor(0.95/0.05*(K-1) + K)), | |
paste0("Median: ", qnbinom(0.5, K, 0.05) + K) | |
), bty = "n") | |
} | |
plotter(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment