Learn R Programming

Renext (version 3.1-4)

fgamma: ML estimation of the Gamma distribution

Description

Fast Maximum Likelihood estimation of the Gamma distribution.

Usage

fgamma(x, check.loglik = FALSE)

Value

A list with the following elements

estimate

Parameter ML estimates.

sd

Vector of (asymptotic) standard deviations for the estimates.

loglik

The maximised log-likelihood.

check.loglik

The checked log-likelihood.

cov

The (asymptotic) covariance matrix computed from theoretical or observed information matrix.

info

The information matrix.

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.

Author

Yves Deville

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