I want to find the log likelihood of data given Gamma, Weibull and Log normal distributions in R. How do I proceed given that I have already estimated the parameters of the respective distributions?
Asked
Active
Viewed 2,240 times
1
-
2Consider posting example data and functional code that estimates the parameters. – Mark Miller Feb 18 '14 at 05:51
-
These links [here](http://stat.ethz.ch/R-manual/R-devel/library/stats4/html/mle.html), [here](http://en.wikibooks.org/wiki/R_Programming/Maximum_Likelihood) and [here](https://r-forge.r-project.org/scm/viewvc.php/*checkout*/paper/CompStat/maxLik.pdf?revision=1114&root=maxlik&pathrev=1114) would be good starting point. – MYaseen208 Feb 18 '14 at 06:28
-
This sound like a request to do your homework, but without the actual question. – IRTFM Feb 18 '14 at 07:49
-
i have done my parameters estimation as follows:fitdistr(x,'Gamma') shape rate 451.76954 202.13089 ( 31.96263) ( 14.30864) fitdistr(x,'Weibull') shape scale 20.618605163 2.285169506 ( 0.696335843) ( 0.005879705) fitdistr(x,'lognormal') meanlog sdlog 0.803152625 0.047006742 (0.002353281) (0.001664021) now i want to find the respective log likelihood @ Mark Miller – user3309969 Feb 18 '14 at 14:19
1 Answers
7
Here's an example for Gamma. Weibull and log-Normal follow exactly the same procedure.
set.seed(101)
x <- rgamma(20,shape=3,rate=2.5)
library(MASS)
(ff <- fitdistr(x,"gamma"))
## shape rate
## 4.452775 4.175653
## (1.358630) (1.348722)
fitdistr
has a log-likelihood accessor method:
logLik(ff)
## 'log Lik.' -13.14535 (df=2)
Or you can do it by hand:
sum(dgamma(x,shape=coef(ff)["shape"],rate=coef(ff)["rate"],log=TRUE))
## [1] -13.14535
or a little bit of sugar/R-magic:
with(as.list(coef(ff)),
sum(dgamma(x,shape=shape,rate=rate,log=TRUE)))
For the other distributions
densfun="weibull"
->dweibull()
densfun="lognormal"
->dlnorm()
In both cases the parameterizations/names of the parameters match between fitdistr
and the corresponding density functions.

Ben Bolker
- 211,554
- 25
- 370
- 453