## Slide 6, 10
fit <- binom.bayes(31, 39, plot=TRUE, xlab=expression(theta), conf=.9)
fit

## Slide 13
fit <- binom.bayes(0, 29, plot=TRUE, xlab=expression(theta))
fit

## Frequentist approach (slide 11)
p <- 31/39
se <- sqrt(p*(1-p)/39)
p + c(-1,1)*qnorm(.95)*se
sqrt(fit$sample*(1-fit$sample)/39)

## Frequentist approach(slide 14)
prop.test(0, 29)$conf.int
binom.test(0, 29)$conf.int

## Log odds (slide 19)
xx <- seq(-10, 10, len=99)
plot(xx, exp(xx)/(1+exp(xx))^2, type="l", col="blue", lwd=3, xlab="Log odds", ylab="Prior density", las=1)

## Jeffreys (slide 22)
xx <- seq(0, 1, len=99)
plot(xx, dbeta(xx, 0.5, 0.5), type="l", col="blue", lwd=3, xlab=expression(theta), ylab="Prior density", las=1, ylim=c(0, 3.5))
binom.bayes(31, 39, a=0.5,  b=0.5, conf=.9)

## Informative (slide 25)
xx <- seq(0, 1, len=99)
col <- pal(4)
fit <- binom.bayes(31, 39, a=7, b=5, plot=TRUE, xlab=expression(theta), ylab="Density", col=pal(3)[3], conf=.9)
binom.bayes(6, 10, add=TRUE, col=pal(3, alpha=0.5)[2])
binom.bayes(30, 38, add=TRUE, col=pal(3, alpha=0.5)[1])
text(0.5, 3, "Prior")
text(0.95, 3, "Likelihood")
text(0.6, 5, "Posterior")
fit
