Skip to content

Instantly share code, notes, and snippets.

@py
Created January 22, 2012 23:13
Show Gist options
  • Save py/1659268 to your computer and use it in GitHub Desktop.
Save py/1659268 to your computer and use it in GitHub Desktop.
vos Savant binomial calcs
# 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