[R] MLE with optim

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Wed Jun 29 17:36:09 CEST 2005


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


----- Original Message ----- 
From: "Carsten Steinhoff" <carsten.steinhoff at stud.uni-goettingen.de>
To: <r-help at stat.math.ethz.ch>
Sent: Wednesday, June 29, 2005 5:19 PM
Subject: [R] MLE with optim


> 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 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
>




More information about the R-help mailing list