Created
January 22, 2012 23:13
-
-
Save py/1659268 to your computer and use it in GitHub Desktop.
vos Savant binomial calcs
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
# Libraries | |
require("ggplot2") | |
# Define variables | |
n = 4 | |
p = .25 | |
k = c(1:4) | |
# Calculate binomial probabilities for X=[1:4] | |
probs <- dbinom(x=k, size=n, prob=p) | |
# Probability of being selected at least once, P(X >= 1) | |
sum(probs) | |
# Plot P(X=k) vs. K | |
qplot(k, probs, geom="point") + | |
xlab("k, # of times picked per year") + | |
ylab("P(X=k)") | |
# Probability of not being selected, P(X = 0) | |
## Binomial calculation | |
dbinom(x=0, size=n, prob=p) | |
## Probability approximation | |
(1-p)^n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment