Do you want to do a nonlinear least-squares estimation (which is MLE if the errors are Gaussian)?
If so, you have to define a function that takes the parameter (k) and data matrix (LR, T, LM), as arguments, and returns a scalar, which is the residual sum of squares. Then you can optimize (minimize) that function. Ravi. -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of mlar...@rsmas.miami.edu Sent: Friday, October 01, 2010 4:40 PM To: r-help@r-project.org Subject: [R] maximum likelihood problem 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. ______________________________________________ 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.