n <- 3 m <- 114 print( theta.hat <- n / m ) binomial.likelihood.1 <- function( n, m, theta ) { likelihood <- theta^n * ( 1 - theta )^( m - n ) return( likelihood ) } binomial.likelihood.1( 3, 114, 0.1 ) [1] 8.335248e-09 theta.grid.1 <- seq( 0, 1, length = 500 ) plot( theta.grid.1, binomial.likelihood.1( n, m, theta.grid.1 ), type = 'l', ylab = 'Likelihood', xlab = 'theta' ) theta.grid.2 <- seq( 0, 0.1, length = 500 ) plot( theta.grid.2, binomial.likelihood.1( n, m, theta.grid.2 ), type = 'l', ylab = 'Likelihood', xlab = 'theta' ) binomial.log.likelihood.1 <- function( n, m, theta ) { log.likelihood <- n * log( theta ) + ( m - n ) * log( 1 - theta ) return( log.likelihood ) } par( mfrow = c( 2, 1 ) ) plot( theta.grid.2, binomial.likelihood.1( n, m, theta.grid.2 ), type = 'l', ylab = 'Likelihood', xlab = 'theta' ) plot( theta.grid.2, binomial.log.likelihood.1( n, m, theta.grid.2 ), type = 'l', ylab = 'Log Likelihood', xlab = 'theta' ) par( mfrow = c( 1, 1 ) ) plot( theta.grid.1, dbeta( theta.grid.1, 1, 1 ), type = 'l', ylab = 'Density', xlab = 'theta', lwd = 2, ylim = c( 0, 3 ) ) lines( theta.grid.1, dbeta( theta.grid.1, 0.5, 1 ), lty = 2, lwd = 2, col = 'red' ) par( mfrow = c( 1, 1 ) ) plot( theta.grid.1, dbeta( theta.grid.1, 1, 1 ), type = 'l', ylab = 'Density', xlab = 'theta', lwd = 2, ylim = c( 0, 3 ) ) lines( theta.grid.1, dbeta( theta.grid.1, 0.5, 1 ), lty = 2, lwd = 2, col = 'blue' ) lines( theta.grid.1, dbeta( theta.grid.1, 0.1, 1 ), lty = 3, lwd = 2, col = 'blue' ) lines( theta.grid.1, dbeta( theta.grid.1, 0.01, 1 ), lty = 4, lwd = 2, col = 'green' )