[R] maximum likelihood estimation of 5 parameters

francogrex francogrex at mail.com
Fri Jan 5 23:00:51 CET 2007


No I have not forgotten to use a negative fnscale to optimize, so as you
suggest I will post some parts of the code I am running to show you the
errors:

> n
 [1]   3   1   4  54   6  58  20  14   3  14   4  65   1   7   9  10   2   4 
66
[20]   5   9   7  12   7  55 105   2   5  10  55   5  28   1   1   6   2   1 
30
[39]   6  49   7  21   8   7
> e
 [1] 21.763201  1.209070  4.836270 32.644798 19.546600 24.584400 30.226700
 [8]  6.045340 14.010100  3.113350 21.015100 12.583100 15.826200 19.458401
[15]  3.891690  1.329970  0.241814  3.143580 13.057900  0.725441 18.136000
[22]  2.187660  6.319900  1.701510 29.654900 36.460999  7.292190  1.215370
[29]  3.209070 19.995001 11.972300  3.455920  0.138539  0.113350  1.360200
[36]  1.889170  1.518890 18.226700  4.050380 27.340099  1.181360 16.370300
[43] 20.589399 25.314899

> fr<-function(a1,b1,a2,b2,p){
+ 
+ w<-((gamma(a1+n)))/((gamma(a1)*factorial(n))*(1+(e/b1)^a1)*(1+(b1/e)^n))
+ z<-((gamma(a2+n)))/((gamma(a2)*factorial(n))*(1+(e/b2)^a2)*(1+(b2/e)^n))
+ 
+ sum (log( (p*w)+ ((1-p)*z) ))
+ 
+ }
> 
> mle((fr),
> start=list(a1=0.2,b1=0.1,a2=2,b2=4,p=0.33),method="BFGS",control=list(fnscale=-1))
Error in optim(start, f, method = method, hessian = TRUE, ...) : 
        non-finite finite-difference value [2]

And with the L-BFGS-B:

Error in optim(start, f, method = method, hessian = TRUE, ...) : 
        L-BFGS-B needs finite values of 'fn'

AND WITH NELDER-MEAD it doesn't work either (same error), but when I change
intial parameters (though I shouldn't, it gives something very weird
(negatives or sometimes huge values).

Call:
mle(minuslogl = (fr), start = list(a1 = 1, b1 = 1, a2 = 10, b2 = 10, 
    p = 0.9), method = "Nelder-Mead", control = list(fnscale = -1))

Coefficients:
        a1         b1         a2         b2          p 
-2.5035823  0.6236359 26.5562988 12.9604112 -0.1383767 

Thanks



Ravi Varadhan wrote:
> 
> Franco,
> Is it possible that you have failed to provide the negative of
> loglikelihood
> to "optim", since optim, by default, minimizes a function?  If you want to
> do this withput redefining the log-likelihood, you should set fnscale= -1
> (as hinted by Prof. Ripley).  This would turn the problem into a
> maximization problem.  
> 
> If this doesn't work, you should provide more details (a reproducible code
> with actual error message).
> 
> Ravi.
> 
> ----------------------------------------------------------------------------
> -------
> 
> Ravi Varadhan, Ph.D.
> 
> Assistant Professor, The Center on Aging and Health
> 
> Division of Geriatric Medicine and Gerontology 
> 
> Johns Hopkins University
> 
> Ph: (410) 502-2619
> 
> Fax: (410) 614-9625
> 
> Email: rvaradhan at jhmi.edu
> 
> Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html
> 
>  
> 
> ----------------------------------------------------------------------------
> --------
> 
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of francogrex
> Sent: Friday, January 05, 2007 10:42 AM
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] maximum likelihood estimation of 5 parameters
> 
> 
> 
> Franco,
> You can provide lower and upper bounds on the parameters if you use optim
> with method="L-BFGS-B".
> Hth, Ingmar
> 
> Thanks, but when I use L-BFGS-B it tells me that there is an  error in
> optim(start, f, method = method, hessian = TRUE, ...) : L-BFGS-B needs
> finite values of 'fn'
> 
> -- 
> View this message in context:
> http://www.nabble.com/maximum-likelihood-estimation-of-5-parameters-tf292536
> 4.html#a8180120
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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 at stat.math.ethz.ch 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/maximum-likelihood-estimation-of-5-parameters-tf2925364.html#a8186869
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list