Jim — Nov 14, 2013, 10:46 AM
# data/prior conflict
# illustrating Box (1980)
# beta/binomial model
# observe y distributed binomial(n, p)
# p is beta(a, b)
# is there a data/prior conflict?
# two plots
# triplot -- shows prior, likelihood, and posterior
# plot of prior predictive distribution -- show observed value
two.plots <- function(prior, data){
require(LearnBayes)
n <- data[1]; y <- data[2]
a <- prior[1]; b <- prior[2]
par(mfrow=c(2, 1))
triplot(prior, c(y, n - y))
predplot(prior, n, y)
}
# Suppose your prior is beta(5, 10)
# Take a sample of n = 20 and observe y = 15
# (Here we have data/prior conflict)
two.plots(c(5, 10), c(20, 15))
Loading required package: LearnBayes
# Suppose your prior is beta(2, 10)
# Take a sample of n = 20 and observe y = 5
# (Here the data is reasonably consistent with the prior)
two.plots(c(2, 10), c(20, 5))