Ravi has already responded about the possibility of using nls(). He and I also have put up
the optimx package which allows a control 'maximize=TRUE' because of the awkwardness of
using fnscale in optim. (optimx still lets you use optim()'s tools too, but wrapped with
this facility.) There are a number of optimizers available through optimx. If you can
compute gradients analytically, you will find methods that can use these much more
efficient, and your subsequent Hessian estimates better too.
You should be aware that optimise() is for 1D problems i.e., 1 parameter to
optimize.
John Nash
Message: 81
Date: Fri, 1 Oct 2010 16:39:58 -0400 (EDT)
From: mlar...@rsmas.miami.edu
To: r-help@r-project.org
Subject: [R] maximum likelihood problem
Message-ID:
<3675.129.171.104.122.1285965598.squir...@webmail.rsmas.miami.edu>
Content-Type: text/plain;charset=iso-8859-1
I am trying to figure out how to run maximum likelihood in R. Here is my
situation:
I have the following equation:
equation<-(1/LR-(exp(-k*T)*LM)*(1-exp(-k)))
LR, T, and LM are vectors of data. I want to R to change the value of k
to maximize the value of equation.
My attempts at optim and optimize have been unsuccessful. Are these the
recommended functions that I should use to maximize my equation?
With optim I wanted the function to be maximized so I had to make the
fnscale negative. Here is what I put:
L<-optim(k,equation,control=(fnscale=-1))
My result: Error: could not find function "fn"
Here is what I put for optimize:
L<-optimise(equation,k,maximum=TRUE)
My result: Error: 'xmin' not less than 'xmax'
Any advise would be greatly appreciated.
Mike
------------------------------
______________________________________________
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.