Learn R Programming

EnvStats (version 2.1.0)

egamma: Estimate Parameters of Gamma Distribution

Description

Estimate the shape and scale parameters (or the mean and coefficient of variation) of a Gamma distribution.

Usage

egamma(x, method = "mle", ci = FALSE, 
    ci.type = "two-sided", ci.method = "normal.approx", 
    normal.approx.transform = "kulkarni.powar", conf.level = 0.95)

  egammaAlt(x, method = "mle", ci = FALSE, 
    ci.type = "two-sided", ci.method = "normal.approx", 
    normal.approx.transform = "kulkarni.powar", conf.level = 0.95)

Arguments

x
numeric vector of non-negative observations. Missing (NA), undefined (NaN), and infinite (Inf, -Inf) values are allowed but will be removed.
method
character string specifying the method of estimation. The possible values are: "mle" (maximum likelihood; the default), "bcmle" (bias-corrected mle), "mme" (method of moments), and "mmue" (method of
ci
logical scalar indicating whether to compute a confidence interval for the mean. The default value is ci=FALSE.
ci.type
character string indicating what kind of confidence interval to compute. The possible values are "two-sided" (the default), "lower", and "upper". This argument is ignored if ci=FALSE.
ci.method
character string indicating which method to use to construct the confidence interval. Possible values are "normal.approx" (the default), "profile.likelihood", and "chisq.approx". This argument is ignore
normal.approx.transform
character string indicating which power transformation to use when ci.method="normal.approx". Possible values are "kulkarni.powar" (the default), "cube.root", and "fourth.root". See the DETAILS s
conf.level
a scalar between 0 and 1 indicating the confidence level of the confidence interval. The default value is conf.level=0.95. This argument is ignored if ci=FALSE.

Value

  • a list of class "estimate" containing the estimated parameters and other information. See estimate.object for details.

Warning

When ci=TRUE and ci.method="normal.approx", it is possible for the lower confidence limit based on the transformed data to be less than 0. In this case, the lower confidence limit on the original scale is set to 0 and a warning is issued stating that the normal approximation is not accurate in this case.

Details

If x contains any missing (NA), undefined (NaN) or infinite (Inf, -Inf) values, they will be removed prior to performing the estimation. Let $\underline{x} = x_1, x_2, \ldots, x_n$ denote a random sample of $n$ observations from a gamma distribution with parameters shape=$\alpha$ and scale=$\beta$. The relationship between these parameters and the mean (mean=$\mu$) and coefficient of variation (cv=$\tau$) of this distribution is given by: $$\alpha = \tau^{-2} \;\;\;\;\;\; (1)$$ $$\beta = \mu/\alpha \;\;\;\;\;\; (2)$$ $$\mu = \alpha \; \beta \;\;\;\;\;\; (3)$$ $$\tau = \alpha^{-1/2} \;\;\;\;\;\; (4)$$ The function egamma returns estimates of the shape and scale parameters. The function egammaAlt returns estimates of the mean ($\mu$) and coefficient of variation ($cv$) based on the estimates of the shape and scale parameters. Estimation Maximum Likelihood Estimation (method="mle") The maximum likelihood estimators (mle's) of the shape and scale parameters $\alpha$ and $\beta$ are solutions of the simultaneous equations: $$\hat{\alpha}_{mle} = \frac{1}{n}\sum_{i=1}^n log(x_i) - log(\bar{x}) = \psi(\hat{\alpha}_{mle}) - log(\hat{\alpha}_{mle}) \ \;\;\;\;\;\; (5)$$ $$\hat{\beta}_{mle} = \bar{x} / \hat{\alpha} \;\;\;\;\;\; (6)$$ where $\psi$ denotes the digamma function, and $\bar{x}$ denotes the sample mean: $$\bar{x} = \frac{1}{n}\sum_{i=1}^n x_i \;\;\;\;\;\; (7)$$ (Forbes et al., 2011, chapter 22; Johnson et al., 1994, chapter 17). Bias-Corrected Maximum Likelihood Estimation (method="bcmle") The bias-corrected maximum likelihood estimator of the shape parameter is based on the suggestion of Anderson and Ray (1975; see also Johnon et al., 1994, p.366 and Singh et al., 2010b, p.48), who noted that the bias of the maximum likelihood estimator of the shape parameter can be considerable when the sample size is small. This estimator is given by: $$\hat{\alpha}_{bcmle} = \frac{n-3}{n}\hat{\alpha}_{mle} + \frac{2}{3n} \;\;\;\;\;\; (8)$$ The estimate of the scale paramter is not modified (i.e., the mle of $\beta$ is returned). Method of Moments Estimation (method="mme") The method of moments estimators (mme's) of the shape and scale parameters $\alpha$ and $\beta$ are: $$\hat{\alpha}_{mme} = (\bar{x}/s_m)^2 \;\;\;\;\;\; (9)$$ $$\hat{\beta}_{mme} = s_m^2 / \bar{x} \;\;\;\;\;\; (10)$$ where $s_m^2$ denotes the method of moments estimator of variance: $$s_m^2 = \frac{1}{n} \sum_{i=1}^n (x_i - \bar{x})^2 \;\;\;\;\;\; (11)$$ Method of Moments Estimation Based on the Unbiased Estimator of Variance (method="mmue") The method of moments estimators based on the unbiased estimator of variance are exactly the same as the method of moments estimators, except that the method of moments estimator of variance is replaced with the unbiased estimator of variance: $$\hat{\alpha}_{mmue} = (\bar{x}/s)^2 \;\;\;\;\;\; (12)$$ $$\hat{\beta}_{mmue} = s^2 / \bar{x} \;\;\;\;\;\; (13)$$ where $s^2$ denotes the unbiased estimator of variance: $$s^2 = \frac{1}{n-1} \sum_{i=1}^n (x_i - \bar{x})^2 \;\;\;\;\;\; (14)$$ Confidence Intervals This section discusses how confidence intervals for the mean $\mu$ are computed. Normal Approximation (ci.method="normal.approx") The normal approximation method is based on the method of Kulkarni and Powar (2010), who use a power transformation of the the original data to approximate a sample from a normal distribuiton, compute the confidence interval for the mean on the transformed scale using the usual formula for a confidence interval for the mean of a normal distribuiton, and then tranform the limits back to the original space using equations based on the expected value of a gamma random variable raised to a power. The particular power used for the normal approximation is defined by the argument normal.approx.transform. The value normal.approx.transform="cube.root" uses the cube root transformation suggested by Wilson and Hilferty (1931), and the value "fourth.root" uses the fourth root transformation suggested by Hawkins and Wixley (1986). The default value "kulkarni.powar" uses the Optimum Power Normal Approximation Method of Kulkarni and Powar (2010), who show this method performs the best in terms of maintining coverage and minimizing confidence interval width compared to eight other methods. The optimum power $p$ is determined by: lll{ $p = -0.0705 - 0.178\hat{\alpha} + 0.475 \sqrt{\hat{\alpha}}$ if $\hat{\alpha} \le 1.5$ $p = 0.246$ if $\hat{\alpha} > 1.5$ (15) } where $\hat{\alpha}$ denotes the estimate of the shape parameter. Kulkarni and Powar (2010) derived this equation by determining what power transformation yields a skew closest to 0 and a kurtosis closest to 3 for a gamma random variable with a given shape parameter. Although Kulkarni and Powar (2010) use the maximum likelihood estimate of shape to determine the power to use to induce approximate normality, for the functions egamma and egammaAlt the power is based on whatever estimate of shape is used (e.g., method="mle", method="bcmle", etc.). Likelihood Profile (ci.method="profile.likelihood") This method was proposed by Cox (1970, p.88), and Venzon and Moolgavkar (1988) introduced an efficient method of computation. This method is also discussed by Stryhn and Christensen (2003) and Royston (2007). The idea behind this method is to invert the likelihood-ratio test to obtain a confidence interval for the mean $\mu$ while treating the coefficient of variation $\tau$ as a nuisance parameter. The likelihood function is given by: $$L(\theta, \tau | \underline{x}) = \prod_{i=1}^n \frac{x_i^{\alpha-1} e^{-x_i/\beta}}{\beta^\alpha \Gamma(\alpha)} \;\;\;\;\;\; (16)$$ where $\alpha$ and $\beta$ are defined in Equations (1) and (2) above, and $\Gamma(t)$ denotes the Gamma function evaluated at $t$. Following Stryhn and Christensen (2003), denote the maximum likelihood estimates of the mean and coefficient of variation by $(\theta^*, \tau^*)$. The likelihood ratio test statistic ($G^2$) of the hypothesis $H_0: \theta = \theta_0$ (where $\theta_0$ is a fixed value) equals the drop in $2 log(L)$ between the full model and the reduced model with $\theta$ fixed at $\theta_0$, i.e., $$G^2 = 2 {log[L(\theta^*, \tau^*)] - log[L(\theta_0, \tau_0^*)]} \;\;\;\;\;\; (17)$$ where $\tau_0^*$ is the maximum likelihood estimate of $\tau$ for the reduced model (i.e., when $\theta = \theta_0$). Under the null hypothesis, the test statistic $G^2$ follows a chi-squared distribution with 1 degree of freedom. Alternatively, we may express the test statistic in terms of the profile likelihood function $L_1$ for the mean $\theta$, which is obtained from the usual likelihood function by maximizing over the parameter $\tau$, i.e., $$L_1(\theta) = max_{\tau} L(\theta, \tau) \;\;\;\;\;\; (18)$$ Then we have $$G^2 = 2 {log[L_1(\theta^*)] - log[L_1(\theta_0)]} \;\;\;\;\;\; (19)$$ A two-sided $(1-\alpha)100%$ confidence interval for the mean $\theta$ consists of all values of $\theta_0$ for which the test is not significant at level $alpha$: $$\theta_0: G^2 \le \chi^2_{1, {1-\alpha}} \;\;\;\;\;\; (20)$$ where $\chi^2_{\nu, p}$ denotes the $p$'th quantile of the chi-squared distribution with $\nu$ degrees of freedom. Chi-Square Approximation (ci.method="chisq.approx") This method is based on the relationship between the sample mean of the gamma distribution and the chi-squared distribution (Grice and Bain, 1980). Because this method is exact only when the shape parameter $\alpha$ is known, the method used here is called the chi-square approximation method because the estimate of the shape parameter is used. This method is not the method proposed by Grice and Bain (1980) in which the confidence interval is adjusted based on adjusting for the fact that the shape parameter is estimated. The chi-square approximation method used by egamma and egammaAlt is equivalent to the Approximate gamma method of Singh et al. (2010b, equation (2-34), p.51).

References

Anderson, C.W., and W.D. Ray. (1975). Improved Maximum Likelihood Estimators for the Gamma Distribution. Communications in Statistics, 4, 437--448. Forbes, C., M. Evans, N. Hastings, and B. Peacock. (2011). Statistical Distributions, Fourth Edition. John Wiley and Sons, Hoboken, NJ. Grice, J.V., and L.J. Bain. (1980). Inferences Concerning the Mean of the Gamma Distribution. Journal of the American Statistician, 75, 929-933. Hawkins, D. M., and R.A.J. Wixley. (1986). A Note on the Transformation of Chi-Squared Variables to Normality. The American Statistician, 40, 296--298. Johnson, N.L., S. Kotz, and N. Balakrishnan. (1994). Continuous Univariate Distributions, Volume 1. Second Edition. John Wiley and Sons, New York, Chapter 17. Kulkarni, H.V., and S.K. Powar. (2010). A New Method for Interval Estimation of the Mean of the Gamma Distribution. Lifetime Data Analysis, 16, 431--447. Singh, A., A.K. Singh, and R.J. Iaci. (2002). Estimation of the Exposure Point Concentration Term Using a Gamma Distribution. EPA/600/R-02/084. October 2002. Technology Support Center for Monitoring and Site Characterization, Office of Research and Development, Office of Solid Waste and Emergency Response, U.S. Environmental Protection Agency, Washington, D.C. Singh, A., R. Maichle, and N. Armbya. (2010a). ProUCL Version 4.1.00 User Guide (Draft). EPA/600/R-07/041, May 2010. Office of Research and Development, U.S. Environmental Protection Agency, Washington, D.C. Singh, A., N. Armbya, and A. Singh. (2010b). ProUCL Version 4.1.00 Technical Guide (Draft). EPA/600/R-07/041, May 2010. Office of Research and Development, U.S. Environmental Protection Agency, Washington, D.C. Wilson, E.B., and M.M. Hilferty. (1931). The Distribution of Chi-Squares. Proceedings of the National Academy of Sciences, 17, 684--688.

See Also

GammaDist, estimate.object, eqgamma, predIntGamma, tolIntGamma.

Examples

Run this code
# Generate 20 observations from a gamma distribution with parameters 
  # shape=3 and scale=2, then estimate the parameters. 
  # (Note: the call to set.seed simply allows you to reproduce this 
  # example.)

  set.seed(250) 
  dat <- rgamma(20, shape = 3, scale = 2) 
  egamma(dat, ci = TRUE)

  #Results of Distribution Parameter Estimation
  #--------------------------------------------
  #
  #Assumed Distribution:            Gamma
  #
  #Estimated Parameter(s):          shape = 2.203862
  #                                 scale = 2.174928
  #
  #Estimation Method:               mle
  #
  #Data:                            dat
  #
  #Sample Size:                     20
  #
  #Confidence Interval for:         mean
  #
  #Confidence Interval Method:      Optimum Power Normal Approximation
  #                                 of Kulkarni & Powar (2010)
  #                                 using mle of 'shape'
  #
  #Normal Transform Power:          0.246
  #
  #Confidence Interval Type:        two-sided
  #
  #Confidence Level:                95%
  #
  #Confidence Interval:             LCL = 3.361652
  #                                 UCL = 6.746794

  # Clean up
  rm(dat)

  #----------------------------------------------------------------

  # Using the reference area TcCB data in EPA.94b.tccb.df, assume a 
  # gamma distribution, estimate the parameters based on the 
  # bias-corrected mle of shape, and compute a one-sided upper 90% 
  # confidence interval for the mean.

  attach(EPA.94b.tccb.df)

  #----------
  # First test to see whether the data appear to follow a gamma 
  # distribution.

  gofTest(TcCB[Area == "Reference"], dist = "gamma", 
    est.arg.list = list(method = "bcmle"))

  #Results of Goodness-of-Fit Test
  #-------------------------------
  #
  #Test Method:                     Shapiro-Wilk GOF Based on 
  #                                 Chen & Balakrisnan (1995)
  #
  #Hypothesized Distribution:       Gamma
  #
  #Estimated Parameter(s):          shape = 4.5695247
  #                                 scale = 0.1309788
  #
  #Estimation Method:               bcmle
  #
  #Data:                            TcCB[Area == "Reference"]
  #
  #Sample Size:                     47
  #
  #Test Statistic:                  W = 0.9703827
  #
  #Test Statistic Parameter:        n = 47
  #
  #P-value:                         0.2739512
  #
  #Alternative Hypothesis:          True cdf does not equal the
  #                                 Gamma Distribution.

  #----------
  # Now estimate the paramters and compute the upper confidence 
  # limit.

  egamma(TcCB[Area == "Reference"], method = "bcmle", ci = TRUE, 
    ci.type = "upper", conf.level = 0.9) 

  #Results of Distribution Parameter Estimation
  #--------------------------------------------
  #
  #Assumed Distribution:            Gamma
  #
  #Estimated Parameter(s):          shape = 4.5695247
  #                                 scale = 0.1309788
  #
  #Estimation Method:               bcmle
  #
  #Data:                            TcCB[Area == "Reference"]
  #
  #Sample Size:                     47
  #
  #Confidence Interval for:         mean
  #
  #Confidence Interval Method:      Optimum Power Normal Approximation
  #                                 of Kulkarni & Powar (2010)
  #                                 using bcmle of 'shape'
  #
  #Normal Transform Power:          0.246
  #
  #Confidence Interval Type:        upper
  #
  #Confidence Level:                90%
  #
  #Confidence Interval:             LCL = 0.0000000
  #                                 UCL = 0.6561838

  #----------------------------------------------------------------

  # Repeat the above example but use the alternative 
  # parameterization.

  egammaAlt(TcCB[Area == "Reference"], method = "bcmle", ci = TRUE, 
    ci.type = "upper", conf.level = 0.9) 

  #Results of Distribution Parameter Estimation
  #--------------------------------------------
  #
  #Assumed Distribution:            Gamma
  #
  #Estimated Parameter(s):          mean = 0.5985106
  #                                 cv   = 0.4678046
  #
  #Estimation Method:               bcmle of 'shape'
  #
  #Data:                            TcCB[Area == "Reference"]
  #
  #Sample Size:                     47
  #
  #Confidence Interval for:         mean
  #
  #Confidence Interval Method:      Optimum Power Normal Approximation
  #                                 of Kulkarni & Powar (2010)
  #                                 using bcmle of 'shape'
  #
  #Normal Transform Power:          0.246
  #
  #Confidence Interval Type:        upper
  #
  #Confidence Level:                90%
  #
  #Confidence Interval:             LCL = 0.0000000
  #                                 UCL = 0.6561838

  #----------

  # Clean up
  #---------
  detach("EPA.94b.tccb.df")

Run the code above in your browser using DataLab