n <- 112 s <- 4 theta.left <- 0.01 theta.right <- 0.99 theta.grid <- seq( theta.left, theta.right, length = 500 ) bernoulli.likelihood.1 <- function( theta, n, s ) { likelihood <- theta^s * ( 1 - theta )^( n - s ) return( likelihood ) } plot( theta.grid, bernoulli.likelihood.1( theta.grid, n, s ), type = 'l', xlab = 'theta', ylab = 'Likelihood', lwd = 2 ) theta.left <- 0.01 theta.right <- 0.1 theta.grid <- seq( theta.left, theta.right, length = 500 ) par( mfrow = c( 2, 1 ) ) plot( theta.grid, bernoulli.likelihood.1( theta.grid, n, s ), type = 'l', xlab = 'theta', ylab = 'Likelihood', lwd = 2 ) n <- 1120 s <- 40 plot( theta.grid, bernoulli.likelihood.1( theta.grid, n, s ), type = 'l', xlab = 'theta', ylab = 'Likelihood', lwd = 2 ) par( mfrow = c( 1, 1 ) ) n <- 11200 s <- 400 plot( theta.grid, bernoulli.likelihood.1( theta.grid, n, s ), type = 'l', xlab = 'theta', ylab = 'Likelihood', lwd = 2 ) bernoulli.likelihood.2 <- function( theta, n, s ) { log.likelihood <- s * log( theta ) + ( n - s ) * log( 1 - theta ) return( exp( log.likelihood ) ) } plot( theta.grid, bernoulli.likelihood.2( theta.grid, n, s ), type = 'l', xlab = 'theta', ylab = 'Likelihood', lwd = 2 ) bernoulli.log.likelihood.1 <- function( theta, n, s ) { log.likelihood <- s * log( theta ) + ( n - s ) * log( 1 - theta ) return( log.likelihood ) } n <- 112 s <- 4 plot( theta.grid, bernoulli.log.likelihood.1( theta.grid, n, s ), type = 'l', xlab = 'theta', ylab = 'Log( Likelihood )', lwd = 2 ) bernoulli.log.likelihood.2 <- function( theta, n, s ) { theta.hat <- s / n log.likelihood <- s * log( theta ) + ( n - s ) * log( 1 - theta ) max.log.likelihood <- s * log( theta.hat ) + ( n - s ) * log( 1 - theta.hat ) return( log.likelihood - max.log.likelihood ) } plot( theta.grid, bernoulli.log.likelihood.2( theta.grid, n, s ), type = 'l', xlab = 'theta', ylab = 'Log( Likelihood )', lwd = 2 ) abline( h = 0 ) abline( v = s / n, col = 'blue' ) text( 0.09, -1.0, '( n = 112, s = 4 )' ) n <- 1120 s <- 40 lines( theta.grid, bernoulli.log.likelihood.2( theta.grid, n, s ), lty = 2, lwd = 2, col = 'red' ) text( 0.07, -2.0, '( n = 1120, s = 40 )', col = 'red' ) ####################################################### f.1 <- function( x, y ) { s <- x + y return( s ) } f.2 <- function( x, y ) { s <- x + y return( s ) } f.3 <- function( x, y ) { s <- x + y return( s ) } f.4 <- function( x, y ) { s <- ( x + y ) return( s ) }