MLE Gamma

Author

Prof. Eric A. Suess

MME fitted gamma

\(X_1, X_2, ...,X_n\) iid \(Gamma(\alpha,\lambda)\), find the MMEs.

p.50 \(f(x|\alpha,\lambda)= \frac{\lambda^\alpha}{\Gamma(\alpha)} x^{\alpha-1} e^{-\lambda x}\)

n <- 100

alpha <- .5; a.min <- 0.1; a.max <- 2;
lambda <- 2; l.max <- 10


# generate random data

x <- rgamma(n, shape = alpha, rate = lambda)

x.orig <- x # save a copy of the original data

make a histogram

use the density estimator since this is a continuous random variable

hist(x.orig, probability=T)
lines(density(x.orig))

MMEs p.249

sigma2.hat <- (1/n)*sum( (x - mean(x))^2 )

alpha.hat.mme <- mean(x)^2/sigma2.hat
alpha.hat.mme
[1] 0.3356098
lambda.hat.mme <- mean(x)/sigma2.hat
lambda.hat.mme
[1] 1.215954
library(fitdistrplus)
Loading required package: MASS
Loading required package: survival
fit.gam <- fitdist(x.orig, "gamma", method = "mme")
summary(fit.gam)
Fitting of the distribution ' gamma ' by matching moments 
Parameters : 
       estimate
shape 0.3356098
rate  1.2159545
Loglikelihood:  58.78397   AIC:  -113.5679   BIC:  -108.3576 

plot the fitted model to the simulated data

denscomp(list(fit.gam), legendtext = c("Gamma"))

cdfcomp(list(fit.gam), legendtext = c("Gamma"))

qqcomp(list(fit.gam), legendtext = c("Gamma"))

ppcomp(list(fit.gam), legendtext = c("Gamma"))

MLE fitted gamma

fit.gam <- fitdist(x.orig, "gamma", method = "mle")
summary(fit.gam)
Fitting of the distribution ' gamma ' by maximum likelihood 
Parameters : 
       estimate Std. Error
shape 0.4391033 0.05065569
rate  1.5907651 0.30216987
Loglikelihood:  61.31218   AIC:  -118.6244   BIC:  -113.414 
Correlation matrix:
         shape     rate
shape 1.000000 0.607318
rate  0.607318 1.000000

plot the fitted model to the simulated data

denscomp(list(fit.gam), legendtext = c("Gamma"))

cdfcomp(list(fit.gam), legendtext = c("Gamma"))

qqcomp(list(fit.gam), legendtext = c("Gamma"))

ppcomp(list(fit.gam), legendtext = c("Gamma"))