Learn R Programming

Renext (version 3.0-0)

fgamma: ML estimation of the Gamma distribution

Description

Fast Maximum Likelihood estimation of the Gamma distribution.

Usage

fgamma(x, check.loglik = FALSE)

Arguments

x
Sample vector to be fitted. Should contain only positive non-NA values.
check.loglik
If TRUE, the log-likelihood is recomputed using dgamma function with log = TRUE. The result is returned as a list element.

Value

  • A list with the following elements
  • estimateParameter ML estimates.
  • sdVector of (asymptotic) standard deviations for the estimates.
  • loglikThe maximised log-likelihood.
  • check.loglikThe checked log-likelihood.
  • covThe (asymptotic) covariance matrix computed from theoretical or observed information matrix.
  • infoThe information matrix.

Details

The likelihood is concentrated with respect to the scale parameter. The concentrated log-likelihood is a strictly concave function of the shape parameter which can easily maximised numerically.

See Also

GammaDist in the stats package.

Examples

Run this code
set.seed(9876)
alpha <- 0.06
beta <- rexp(1)
n <- 30
x <- rgamma(n, shape = alpha, scale = beta)
fit <- fgamma(x, check.loglik = TRUE)

## compare with MASS results
if (require(MASS)) {
   fit.MASS <- fitdistr(x, densfun = "gamma")
   rate <- 1 / fit$estimate["scale"]
   est <- c(fit$estimate, rate = rate)
   der <- rate * rate ## derivative of rate w.r.t scale
   sdest <- c(fit$sd, rate = der * fit$sd["scale"])
   tab <- rbind(sprintf("%10.8f ", est),
                sprintf("(%10.8f)", sdest))
   colnames(tab) <- c("shape", "scale", "rate")
   rownames(tab) <- c("est", "sd")
   noquote(tab)
}

Run the code above in your browser using DataLab