Contenuto principale

gamfit

Gamma parameter estimates

Description

pHat = gamfit(x) returns the maximum likelihood estimates (MLEs) of the gamma distribution parameters (shape and scale), given the sample data in x.

[pHat,pCI] = gamfit(x) also returns the 95% confidence intervals for the parameter estimates.

[pHat,pCI] = gamfit(x,alpha) specifies the confidence level for the confidence intervals to be 100(1 – alpha)%.

example

[___] = gamfit(x,alpha,censoring) accepts a Boolean vector, censoring, of the same size as x, containing the value 1 for observations that are right-censored and 0 for observations that are observed exactly.

[___] = gamfit(x,alpha,censoring,freq) specifies the frequency (or weights) of the observations.

[___] = gamfit(x,alpha,censoring,freq,options) specifies optimization options for the iterative algorithm gamfit uses to compute the MLEs. Create options by using the function statset.

You can specify [] for alpha, censoring, and freq to use their default values.

Examples

collapse all

Generate 100 random numbers from the gamma distribution with the shape parameter a=2 and scale parameter b=4.

rng(0,"twister") % For reproducibility
a = 2;
b = 4;
x = gamrnd(a,b,100,1);

Find the maximum likelihood estimates and the 99% confidence intervals.

[pHat,pCI] = gamfit(x,0.01)
pHat = 1×2

    1.9564    4.4696

pCI = 2×2

    1.3956    3.0421
    2.7427    6.5670

pHat(1) and pHat(2) are the MLEs of the a and b parameters, respectively. pCI contains the 99% confidence intervals of each parameter. The values in the first row are the lower bounds, and the values in the second row are the upper bounds.

Input Arguments

collapse all

Sample data, specified as a vector of nonnegative scalar values.

Data Types: single | double

Significance level for the confidence intervals, specified as a scalar in the range [0,1]. The confidence level is 100(1 – alpha)%, where alpha is the probability that the confidence intervals do not contain the true value. You can specify [] for alpha to use its default value of 0.05.

Data Types: single | double

Indicator for the censoring of each value in x, specified as a logical vector of the same size as x. Use 1 for observations that are right-censored and 0 for observations that are fully observed.

The default is an array of 0s, meaning that all observations are fully observed.

Data Types: logical

Frequency (or weights) of the observations, specified as a nonnegative vector that is the same size as x. The freq input argument typically contains nonnegative integer counts for the corresponding elements in x, but can contain any nonnegative values.

To obtain the weighted MLEs for a data set with censoring, specify weights of observations, normalized to the number of observations in x.

The default is an array of 1s, meaning one observation per element of x.

Data Types: single | double

Optimization options, specified as a structure. options determines the control parameters for the iterative algorithm used by gamfit to compute MLEs.

Create options by using the function statset or by creating a structure array containing the fields and values described in this table.

Field NameValueDefault Value
Display

Amount of information displayed by the algorithm

  • "off" — Displays no information

  • "final" — Displays the final output

  • "notify" — Displays output only if the function does not converge

  • "iter" — Displays iterative output. This setting is only available for uncensored data.

"off"
MaxFunEvals

Maximum number of objective function evaluations allowed, specified as a positive integer. This setting is only available for censored data.

200
MaxIter

Maximum number of iterations allowed, specified as a positive integer. This setting is only available for censored data.

100
TolBnd

Lower bound of the standard deviation parameter estimate, specified as a positive scalar.

The bounds for the mean and standard deviation parameter estimates are [–Inf,Inf] and [TolBnd,Inf], respectively. This setting is only available for censored data.

1e-6
TolFun

Termination tolerance for the objective function value, specified as a positive scalar. This setting is only available for censored data.

1e-8
TolX

Termination tolerance for the parameters, specified as a positive scalar

1e-8
OutputFcn

Specify one or more user-defined functions that an optimization function calls at each iteration, either as a function handle or as a cell array of function handles. This setting is only available for uncensored data. For more information, see Optimization Solver Output Functions.

[]

You can also enter statset("gamfit") in the Command Window to see the names and default values of the fields included in the options structure. The gamfit function ignores any field not listed in the above table.

Example: statset(Display="final",MaxIter=1000) specifies to display the final information of the iterative algorithm results, and change the maximum number of iterations allowed to 1000.

Data Types: struct

Output Arguments

collapse all

Estimates of the parameters a (scale) and b (shape) of the gamma distribution, returned as a 1-by-2 row numeric vector.

Confidence intervals for the parameters, returned as a 2-by-2 matrix containing the lower and upper bounds of the 100(1 – alpha)% confidence interval.

The first and second rows correspond to the lower and upper bounds of the confidence intervals, respectively.

Alternative Functionality

gamfit is a function specific to the gamma distribution. Statistics and Machine Learning Toolbox™ also offers the generic functions mle, fitdist, and paramci and the Distribution Fitter app, which support various probability distributions.

  • mle returns MLEs and the confidence intervals of MLEs for the parameters of various probability distributions. You can specify the probability distribution name or a custom probability density function.

  • Create a GammaDistribution probability distribution object by fitting the distribution to data using the fitdist function or the Distribution Fitter app. The object properties a and b store the parameter estimates. To obtain the confidence intervals for the parameter estimates, pass the object to paramci.

References

[1] Evans, M., N. Hastings, and B. Peacock. Statistical Distributions. Hoboken, NJ: Wiley-Interscience, 2000.

[2] Hahn, Gerald J., and S. S. Shapiro. Statistical Models in Engineering. Hoboken, NJ: John Wiley & Sons, Inc., 1994, p. 88.

[3] Lawless, J. F. Statistical Models and Methods for Lifetime Data. Hoboken, NJ: Wiley-Interscience, 2002.

[4] Meeker, W. Q., and L. A. Escobar. Statistical Methods for Reliability Data. Hoboken, NJ: John Wiley & Sons, Inc., 1998.

Extended Capabilities

expand all

Version History

Introduced before R2006a