You're minimizing the log likelihood, but you want to minimize the *negative* log likelihood. Also, optimize() is better than optim() if you have a function of only one argument.
Replace Jon Moroney wrote: > > #Create the log likelihood function > LL<-function(x) {(trials*log(x))-(x*sumvect)} > > optim(1,LL,method="BFGS") > with LL<-function(x) {-trials*log(x)+x*sumvect} optimize(LL,c(0,1e5)) or better yet, to avoid errors and make generalizeable, do this LL<-function(x) {-sum(dexp(vector,x,log=TRUE))} optimize(LL,c(0,1e5)) -- View this message in context: http://n4.nabble.com/Trouble-with-optim-function-tp1559382p1560118.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.