Skip to content

Instantly share code, notes, and snippets.

@richarddmorey
Created August 10, 2016 15:41
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 richarddmorey/eb1dc700941e3b6fa1b480c669fe3e35 to your computer and use it in GitHub Desktop.
Save richarddmorey/eb1dc700941e3b6fa1b480c669fe3e35 to your computer and use it in GitHub Desktop.
example, Essex, beta/binomial
y = 13
N = 35
a = 1
b = 1
theta = seq(0, 1, len = 100)
likelihood = theta ^ y * (1-theta)^(N-y) #dbinom(y, N, theta)
prior = theta ^ (a-1) * (1-theta)^(b-1) #dbeta(theta, a, b)
posterior1 = prior * likelihood
posterior2 = dbeta(theta, y + a, N - y + b)
plot(theta, likelihood, ty='l')
abline(v = y/N, col="red")
plot(theta, prior, ty='l')
plot(theta, posterior1, ty='l')
plot(theta, posterior2, ty='l', col="blue")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment