[R] Using nlm or optim

Joris Meys jorismeys at gmail.com
Thu Jul 8 15:49:09 CEST 2010


Without data I can't check, but try :
mle(nll,start=list(c=0.01,z=2.1,s=200),fixed=list(V=Var,M=Mean))

With a random dataset I get :
> Mean <- rnorm(136)

> Var <- 1 + rnorm(136)^2
> mle(nll,start=list(c=0.01,z=2.1,s=200),fixed=list(V=Var,M=Mean))
Error in optim(start, f, method = method, hessian = TRUE, ...) :
  initial value in 'vmmin' is not finite

This might be just a data problem, but again, I'm not sure.

Cheers
Joris

On Thu, Jul 8, 2010 at 3:11 AM, Anita Narwani <anitanarwani at gmail.com> wrote:
> Hello,
> I am trying to use nlm to estimate the parameters that minimize the
> following function:
>
> Predict<-function(M,c,z){
> + v = c*M^z
> + return(v)
> + }
>
> M is a variable and c and z are parameters to be estimated.
>
> I then write the negative loglikelihood function assuming normal errors:
>
> nll<-function(M,V,c,z,s){
> n<-length(Mean)
> logl<- -.5*n*log(2*pi) -.5*n*log(s) - (1/(2*s))*sum((V-Predict(Mean,c,z))^2)
> return(-logl)
> }
>
> When I put the Mean and Variance (variables with 136 observations) into this
> function, and estimates for c,z, and s, it outputs the estimate for the
> normal negative loglikelihood given the data, so I know that this works.
>
> However, I am unable to use mle to estimate the parameters c, z, and s. I do
> not know how or where the data i.e. Mean (M) and Variance (V) should enter
> into the mle function. I have tried variations on
>
> mle(nll,start=list(c=0.01,z=2.1,s=200)) including
> mle(nll,start=list(M=Mean,V=Var, c=0.01,z=2.1,s=200))
>
> I keep getting errors and am quite certain that I just have a syntax error
> in the script because I don't know how to enter the variables into MLE.
>
> Thanks for your help,
> Anita.
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



-- 
Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php



More information about the R-help mailing list