[R] Trouble with optim function

Ian Fiske ianfiske at gmail.com
Thu Feb 18 14:20:25 CET 2010

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.


Jon Moroney wrote:
> #Create the log likelihood function
> LL<-function(x) {(trials*log(x))-(x*sumvect)}
> optim(1,LL,method="BFGS")


LL<-function(x) {-trials*log(x)+x*sumvect}

or better yet, to avoid errors and make generalizeable, do this

LL<-function(x) {-sum(dexp(vector,x,log=TRUE))}

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.

More information about the R-help mailing list