bernoulli.likelihood <- function( theta, n, s ) { return( exp( s * log( theta ) + ( n - s ) * log( 1 - theta ) ) ) } theta.grid <- seq( 0, 1, length = 500 ) n <- 400 s <- 72 plot( theta.grid, bernoulli.likelihood( theta.grid, n, s ), type = 'l', xlab = 'theta', ylab = 'Likelihood Function' ) plot( theta.grid, bernoulli.likelihood( theta.grid, 4000, 720 ), type = 'l', xlab = 'theta', ylab = 'Likelihood Function' ) # figure on page 18, part 3 of the lecture notes pdf( "chapter-2-page-18-figure.pdf" ) par( mfrow = c( 1, 2 ) ) plot( theta.grid, bernoulli.likelihood( theta.grid, n, s ), type = 'l', xlab = 'theta', ylab = 'Likelihood Function' ) narrow.theta.grid <- seq( 0.12, 0.24, length = 500 ) plot( narrow.theta.grid, bernoulli.likelihood( narrow.theta.grid, n, s ), type = 'l', xlab = 'theta', ylab = 'Likelihood Function' ) dev.off( ) # figure on page 19, part 3 of the lecture notes bernoulli.log.likelihood <- function( theta, n, s ) { return( s * log( theta ) + ( n - s ) * log( 1 - theta ) ) } pdf( "part2-page-19-figure.pdf" ) par( mfrow = c( 1, 1 ) ) plot( narrow.theta.grid, bernoulli.log.likelihood( narrow.theta.grid, n, s ), type = 'l', xlab = 'theta', ylab = 'Log Likelihood Function' ) dev.off( )