[R] messages from mle function

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Mar 11 23:13:54 CET 2008


This is not reproducible, so I am reduced to guessing.

Your loglike() is only defined for positive f, but you have not imposed 
that constraint on your optimization.  Further, if f=5.91e-05 is a typical 
value, your problem is badly conditioned and the finite difference code in 
optim() is likely to step outside the undeclared region of validity.

I suggest that you

- study the help page for optim()
- make use of the control parameters to scale the problem suitably
- either impose the positivity constraint via the L-BFGS-B method, or
   transform f to a suitable scale, e.g. by making log(f) the parameter.


On Tue, 11 Mar 2008, bernardo lagos alvarez wrote:

> Dears useRs,
> I am using the mle function but this gives me the follow erros that I
> don't understand. Perhaps there is someone that can help me.

You could look at the many warnings -- they may well tell you the 
underlying problem.

> thank you for you atention.
>
> Bernardo.
>
>
>> erizo <- read.csv("Datos_Stokes_1.csv", header = TRUE)
>> head(erizo)
>  EDAD TALLA
> 1    0   7.7
> 2    1  14.5
> 3    1  16.9
> 4    1  13.2
> 5    1  24.4
> 6    1  22.5
>> TAN <- function(edad,f,c,a,d) (1/sqrt(f))*log(abs(2*f*(edad-c)+ 2*sqrt((f^2)*((edad-c)^2)+f*a)))+d
>> loglike  = function(f,c,a,d)  {
> + edad  <- erizo$EDAD
> + LT    <- erizo$TALLA
> + N     <- length(edad)
> + sigma <- sum((LT - TAN(edad,f,c,a,d))^2) / N
> + logl  <- (N/2)*log(sigma) + (sum((LT - TAN(edad,f,c,a,d))^2) / (2*sigma))
> + }
>> ini.pars <- list(f=5.91e-05,c=-0.41732,a=0.009661,d=846.7179)
>> library(stats4)
>> erizo.mle  <- mle(start= ini.pars, minuslogl = loglike, method="Nelder-Mead", control = list(maxit=1500, trace=TRUE))
>  Nelder-Mead direct search function minimizer
> function value for initial parameters = 1159.477620
>  Scaled convergence tolerance is 1.72776e-05
> Stepsize computed as 84.671790
> BUILD              5 3165.307359 1159.477620
> .
> .
> .
> HI-REDUCTION     303 1158.377359 1158.377314
> LO-REDUCTION     305 1158.377339 1158.377303
> LO-REDUCTION     307 1158.377321 1158.377303
> Exiting from Nelder Mead minimizer
>    309 function evaluations used
> Error en optim(start, f, method = method, hessian = TRUE, ...) :
>        non-finite finite-difference value [1]
> Además: Hubo 50 o  más avisos (use warnings() para ver los primeros 50)
>
> ______________________________________________
> 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list