--- title: "MLE Gamma" author: "Prof. Eric A. Suess" format: html: self-contained: true --- ## 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}$ ```{r} 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 ```{r} hist(x.orig, probability=T) lines(density(x.orig)) ``` # MMEs p.249 ```{r} sigma2.hat <- (1/n)*sum( (x - mean(x))^2 ) alpha.hat.mme <- mean(x)^2/sigma2.hat alpha.hat.mme lambda.hat.mme <- mean(x)/sigma2.hat lambda.hat.mme ``` ```{r} library(fitdistrplus) fit.gam <- fitdist(x.orig, "gamma", method = "mme") summary(fit.gam) ``` plot the fitted model to the simulated data ```{r} denscomp(list(fit.gam), legendtext = c("Gamma")) ``` ```{r} cdfcomp(list(fit.gam), legendtext = c("Gamma")) ``` ```{r} qqcomp(list(fit.gam), legendtext = c("Gamma")) ``` ```{r} ppcomp(list(fit.gam), legendtext = c("Gamma")) ``` ### MLE fitted gamma ```{r} fit.gam <- fitdist(x.orig, "gamma", method = "mle") summary(fit.gam) ``` plot the fitted model to the simulated data ```{r} denscomp(list(fit.gam), legendtext = c("Gamma")) ``` ```{r} cdfcomp(list(fit.gam), legendtext = c("Gamma")) ``` ```{r} qqcomp(list(fit.gam), legendtext = c("Gamma")) ``` ```{r} ppcomp(list(fit.gam), legendtext = c("Gamma")) ```