n <- 220 s <- 100 print( theta.hat.mle <- s / n ) # [1] 0.4545455 # the Beta( alpha, beta ) density (for alpha > 0, beta > 0) is # c * theta^( alpha - 1 ) * ( 1 - theta )^( beta - 1 ) # the likelihood function is # c * theta^s * ( 1 - theta )^( n - s ), # which is the Beta( s + 1, n - s + 1 ) distribution; # here that's the Beta( 101, 121 ) distribution # the posterior density is Beta( alpha + s, beta + n - s ) # the neutral prior is Beta( 1, 1 ) = Uniform on the interval ( 0, 1 ) # the cut-the-DA-slack prior is Beta( 17.4, 4.6 ) # with the neutral prior, the posterior is Beta( 101, 121 ) # with the cut-the-DA-slack prior, the posterior is Beta( 117.4, 124.6 ) # make the prior-likelihood-posterior plot with the neutral prior theta.grid.1 <- seq( 0, 1, length = 500 ) plot( theta.grid.1, dbeta( theta.grid.1, 101, 121 ), type = 'l', xlab = 'theta', ylab = 'Density', lwd = 2, main = 'Neutral Prior', ylim = c( 0, 12.5 ) ) lines( theta.grid.1, dbeta( theta.grid.1, 1, 1 ), lty = 3, lwd = 2, col = 'blue' ) lines( theta.grid.1, dbeta( theta.grid.1, 101, 121 ), lty = 2, lwd = 2, col = 'red' ) text( 0.1, 2, 'prior', col = 'blue' ) text( 0.3, 11, 'likelihood' ) text( 0.6, 10, 'posterior', col = 'red' ) segments( 0.791, 0, 0.791, 1.5, lwd = 2 ) text( 0.791, 2.25, 'no discrimination' ) # make the prior-likelihood-posterior plot with the # cut-the-DA-slack prior plot( theta.grid.1, dbeta( theta.grid.1, 101, 121 ), type = 'l', xlab = 'theta', ylab = 'Density', lwd = 2, main = 'Cut-the-DA-Slack Prior', ylim = c( 0, 12.5 ) ) lines( theta.grid.1, dbeta( theta.grid.1, 17.4, 4.6 ), lty = 3, lwd = 2, col = 'blue' ) lines( theta.grid.1, dbeta( theta.grid.1, 117.4, 124.6 ), lty = 2, lwd = 2, col = 'red' ) text( 0.8, 5.5, 'prior', col = 'blue' ) text( 0.3, 11, 'likelihood' ) text( 0.6, 10, 'posterior', col = 'red' ) segments( 0.791, 0, 0.791, 1.5, lwd = 2 ) text( 0.791, 2.25, 'no discrimination' ) # superimpose the two posterior distributions on the same graph # to see how sensitive the posterior is to the prior plot( theta.grid.1, dbeta( theta.grid.1, 101, 121 ), type = 'l', xlab = 'theta', ylab = 'Density', lwd = 2, ylim = c( 0, 12.5 ), col = 'red', main = 'Sensitivity Analysis' ) lines( theta.grid.1, dbeta( theta.grid.1, 117.4, 124.6 ), lty = 2, lwd = 2, col = 'red' ) text( 0.3, 11, 'neutral', col = 'red' ) text( 0.7, 10, 'cut-the-DA-slack', col = 'red' ) segments( 0.791, 0, 0.791, 1.5, lwd = 2 ) text( 0.791, 2.25, 'no discrimination' )