psi.MLE = function() { negLL = function(psi) (-1)*dbinom(z, size=n, prob=psi, log=TRUE) z = 1 n = 5 fit = optim(0.5, negLL, method='BFGS') list(logLikelihood=-fit$value, mle=fit$par) }