<- 100
n
<- .5; a.min <- 0.1; a.max <- 2;
alpha <- 2; l.max <- 10
lambda
# generate random data
<- rgamma(n, shape = alpha, rate = lambda)
x
<- x # save a copy of the original data x.orig
MLE Gamma
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}\)
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
<- (1/n)*sum( (x - mean(x))^2 )
sigma2.hat
<- mean(x)^2/sigma2.hat
alpha.hat.mme alpha.hat.mme
[1] 0.3356098
<- mean(x)/sigma2.hat
lambda.hat.mme lambda.hat.mme
[1] 1.215954
library(fitdistrplus)
Loading required package: MASS
Loading required package: survival
<- fitdist(x.orig, "gamma", method = "mme")
fit.gam 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
<- fitdist(x.orig, "gamma", method = "mle")
fit.gam 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"))