Click or drag to resize
Accord.NET (logo) GammaDistribution Class
Gamma distribution.
Inheritance Hierarchy
SystemObject
  Accord.Statistics.DistributionsDistributionBase
    Accord.Statistics.Distributions.UnivariateUnivariateContinuousDistribution
      Accord.Statistics.Distributions.UnivariateGammaDistribution

Namespace:  Accord.Statistics.Distributions.Univariate
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.4.0
Syntax
[SerializableAttribute]
public class GammaDistribution : UnivariateContinuousDistribution, 
	IFittableDistribution<double, GammaOptions>, IFittable<double, GammaOptions>, 
	IFittable<double>, IFittableDistribution<double>, IDistribution<double>, 
	IDistribution, ICloneable, ISampleableDistribution<double>, IRandomNumberGenerator<double>
Request Example View Source

The GammaDistribution type exposes the following members.

Constructors
  NameDescription
Public methodGammaDistribution
Constructs a Gamma distribution.
Public methodGammaDistribution(Double, Double)
Constructs a Gamma distribution.
Top
Properties
  NameDescription
Public propertyEntropy
Gets the entropy for this distribution.
(Overrides UnivariateContinuousDistributionEntropy.)
Public propertyMean
Gets the mean for this distribution.
(Overrides UnivariateContinuousDistributionMean.)
Public propertyMedian
Gets the median for this distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertyMode
Gets the mode for this distribution.
(Overrides UnivariateContinuousDistributionMode.)
Public propertyQuartiles
Gets the Quartiles for this distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertyRate
Gets the inverse scale parameter β = 1/θ.
Public propertyScale
Gets the distribution's scale parameter θ (theta).
Public propertyShape
Gets the distribution's shape parameter k.
Public propertyStatic memberStandard
Gets the standard Gamma distribution, with scale θ = 1 and location k = 1.
Public propertyStandardDeviation
Gets the Standard Deviation (the square root of the variance) for the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertySupport
Gets the support interval for this distribution.
(Overrides UnivariateContinuousDistributionSupport.)
Public propertyVariance
Gets the variance for this distribution.
(Overrides UnivariateContinuousDistributionVariance.)
Top
Methods
  NameDescription
Public methodClone
Creates a new object that is a copy of the current instance.
(Overrides DistributionBaseClone.)
Public methodComplementaryDistributionFunction
Gets the complementary cumulative distribution function (ccdf) for this distribution evaluated at point x. This function is also known as the Survival function.
(Inherited from UnivariateContinuousDistribution.)
Public methodCumulativeHazardFunction
Gets the cumulative hazard function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleDistributionFunction(Double)
Gets the cumulative distribution function (cdf) for this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionDistributionFunction(Double).)
Public methodDistributionFunction(Double, Double)
Gets the cumulative distribution function (cdf) for this distribution in the semi-closed interval (a; b] given as P(a < X ≤ b).
(Inherited from UnivariateContinuousDistribution.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodStatic memberEstimate
Estimates a new Gamma distribution from a given set of observations.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodFit(Double)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodFit(Double, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodFit(Double, Double)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodFit(Double, Int32)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodFit(Double, Double, GammaOptions)
Fits the underlying distribution to a given set of observations.
Public methodFit(Double, Double, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Overrides UnivariateContinuousDistributionFit(Double, Double, IFittingOptions).)
Public methodFit(Double, Int32, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodStatic memberFromBayesian
Constructs a Gamma distribution using α and β parameterization.
Public methodStatic memberFromMean
Constructs a Gamma distribution using k and μ parameterization.
Public methodGenerate
Generates a random observation from the current distribution.
(Overrides UnivariateContinuousDistributionGenerate.)
Public methodGenerate(Int32)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Int32, Double)
Generates a random vector of observations from the current distribution.
(Overrides UnivariateContinuousDistributionGenerate(Int32, Double).)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetRange
Gets the distribution range within a given percentile.
(Inherited from UnivariateContinuousDistribution.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodHazardFunction
Gets the hazard function, also known as the failure rate or the conditional failure density function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodInverseDistributionFunction
Gets the inverse of the cumulative distribution function (icdf) for this distribution evaluated at probability p. This function is also known as the Quantile function.
(Overrides UnivariateContinuousDistributionInverseDistributionFunction(Double).)
Public methodLogCumulativeHazardFunction
Gets the log of the cumulative hazard function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleLogProbabilityDensityFunction
Gets the log-probability density function (pdf) for this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionLogProbabilityDensityFunction(Double).)
Public methodStatic memberMarsaglia
Random Gamma-distribution number generation based on Marsaglia's Simple Method (2000).
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodCode exampleProbabilityDensityFunction
Gets the probability density function (pdf) for this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionProbabilityDensityFunction(Double).)
Public methodQuantileDensityFunction
Gets the first derivative of the inverse distribution function (icdf) for this distribution evaluated at probability p.
(Inherited from UnivariateContinuousDistribution.)
Public methodStatic memberRandom(Double, Double)
Generates a random observation from the Gamma distribution with the given parameters.
Public methodStatic memberRandom(Double, Double, Int32)
Generates a random vector of observations from the Gamma distribution with the given parameters.
Public methodStatic memberRandom(Double, Double, Int32, Double)
Generates a random vector of observations from the Gamma distribution with the given parameters.
Public methodToString
Returns a String that represents this instance.
(Inherited from DistributionBase.)
Public methodToString(IFormatProvider)
Returns a String that represents this instance.
(Inherited from DistributionBase.)
Public methodToString(String)
Returns a String that represents this instance.
(Inherited from DistributionBase.)
Public methodToString(String, IFormatProvider)
Returns a String that represents this instance.
(Overrides DistributionBaseToString(String, IFormatProvider).)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by Matrix.)
Top
Remarks

The gamma distribution is a two-parameter family of continuous probability distributions. There are three different parameterizations in common use:

  • With a Shape parameter k and a Scale parameter θ.
  • With a shape parameter α = k and an inverse scale parameter β = 1/θ, called a Rate parameter.
  • With a shape parameter k and a Mean parameter μ = k/β.

In each of these three forms, both parameters are positive real numbers. The parameterization with k and θ appears to be more common in econometrics and certain other applied fields, where e.g. the gamma distribution is frequently used to model waiting times. For instance, in life testing, the waiting time until death is a random variable that is frequently modeled with a gamma distribution. This is the default construction method for this class.

The parameterization with α and β is more common in Bayesian statistics, where the gamma distribution is used as a conjugate prior distribution for various types of inverse scale (aka rate) parameters, such as the λ of an exponential distribution or a Poisson distribution – or for that matter, the β of the gamma distribution itself. (The closely related inverse gamma distribution is used as a conjugate prior for scale parameters, such as the variance of a normal distribution.) In order to create a Gamma distribution using the Bayesian parameterization, you can use FromBayesian(Double, Double).

If k is an integer, then the distribution represents an Erlang distribution; i.e., the sum of k independent exponentially distributed random variables, each of which has a mean of θ (which is equivalent to a rate parameter of 1/θ).

The gamma distribution is the maximum entropy probability distribution for a random variable X for which E[X] = kθ = α/β is fixed and greater than zero, and E[ln(X)] = ψ(k) + ln(θ) = ψ(α) − ln(β) is fixed (ψ is the digamma function).

References:

Examples

The following example shows how to create, test and compute the main functions of a Gamma distribution given parameters θ = 4 and k = 2:

// Create a Γ-distribution with k = 2 and θ = 4
var gamma = new GammaDistribution(theta: 4, k: 2);

// Common measures
double mean = gamma.Mean;     // 8.0
double median = gamma.Median; // 6.7133878418421506
double var = gamma.Variance;  // 32.0
double mode = gamma.Mode;     // 4.0

// Cumulative distribution functions
double cdf = gamma.DistributionFunction(x: 0.27); // 0.002178158242390601
double ccdf = gamma.ComplementaryDistributionFunction(x: 0.27); // 0.99782184175760935
double icdf = gamma.InverseDistributionFunction(p: cdf); // 0.26999998689819171

// Probability density functions
double pdf = gamma.ProbabilityDensityFunction(x: 0.27); // 0.015773530285395465
double lpdf = gamma.LogProbabilityDensityFunction(x: 0.27); // -4.1494220422235433

// Hazard (failure rate) functions
double hf = gamma.HazardFunction(x: 0.27); // 0.015807962529274005
double chf = gamma.CumulativeHazardFunction(x: 0.27); // 0.0021805338793574793

// String representation
string str = gamma.ToString(CultureInfo.InvariantCulture); // "Γ(x; k = 2, θ = 4)"
See Also