mlarkin at rsmas.miami.edu
2010-Oct-02 01:11 UTC
[R] [Fwd: RE: maximum likelihood problem]
I forgot to add that I first gave a starting value for K.
Nonlinear least squares won't work because my errors are not normally
distributed.
Any advide on my maximum likelihood function would be greatly appreciated.
---------------------------- Original Message ----------------------------
Subject: RE: [R] maximum likelihood problem
From: "Ravi Varadhan" <rvaradhan at jhmi.edu>
Date: Fri, October 1, 2010 5:10 pm
To: mlarkin at rsmas.miami.edu
r-help at r-project.org
--------------------------------------------------------------------------
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-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On
Behalf Of mlarkin at rsmas.miami.edu
Sent: Friday, October 01, 2010 4:40 PM
To: r-help at 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 at 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.
If your problem was as you described it, you'd simply find the 1st
derivative of your eq. w.r.t. k, equate to 0, and then solve for k (and check
that the solution is a maximum). But I guess what you really want to do is to
estimate k from data given your equation and _another model_ for the likelihood
of the data.
If that is the case then you haven't yet defined the model for the
likelihood of the data as a function of your single parameter k. You have to
define an R function that contains your process model (apparently your equation)
and your likelihood model, which will be made from some probability model for
the data. Try this to get help on how to write new functions:
?"function"
After defining this function with the two models then you can maximize the
likelihood of the data as a function of the process model parameter k. If there
is only one parameter then it is recommended to use optimise(), instead of
optim().
It is not necessary to maximize, just minimize the negative of the
log(likelihood) once you have defined what this likelihood is.
HTH
Rubén
-----Original Message-----
From: r-help-bounces@r-project.org on behalf of mlarkin@rsmas.miami.edu
Sent: Sat 10/2/2010 3:11 AM
To: r-help@r-project.org
Subject: [R] [Fwd: RE: maximum likelihood problem]
I forgot to add that I first gave a starting value for K.
Nonlinear least squares won't work because my errors are not normally
distributed.
Any advide on my maximum likelihood function would be greatly appreciated.
---------------------------- Original Message ----------------------------
Subject: RE: [R] maximum likelihood problem
From: "Ravi Varadhan" <rvaradhan@jhmi.edu>
Date: Fri, October 1, 2010 5:10 pm
To: mlarkin@rsmas.miami.edu
r-help@r-project.org
--------------------------------------------------------------------------
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-bounces@r-project.org [mailto:r-help-bounces@r-project.org] On
Behalf Of mlarkin@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.
[[alternative HTML version deleted]]