Re: [R] MLE with optim

From: Dimitris Rizopoulos <dimitris.rizopoulos_at_med.kuleuven.be>
Date: Thu 30 Jun 2005 - 01:36:09 EST

the following work for me:

x <- rlnorm(1000, 5, 3)

fn <- function(parms, dat) -sum(dlnorm(dat, parms[1], parms[2], log = TRUE))
optim(c(5, 3), fn, dat = x)

library(MASS)
fitdistr(x, "log-normal", list(meanlog = 5, sdlog = 3))

I hope it helps.

Best,
Dimitris



Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium

Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


> Hello,
>
> I tried to fit a lognormal distribution by using optim. But sadly
> the output
> seems to be incorrect.
> Who can tell me where the "bug" is?
>
> test = rlnorm(100,5,3)
> logL = function(parm, x,...) -sum(log(dlnorm(x,parm,...)))
> start = list(meanlog=5, sdlog=3)
> optim(start,logL,x=test)$par
>
> Carsten.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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
>



R-help@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 Received on Thu Jun 30 01:37:25 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:07 EST