Gamma distribution
Gamma distribution: the waiting time for several events, or any positive skewed quantity. With the default parameters (shape k = 3, scale θ = 1) its mean is 3 and its standard deviation 1.7321. Use the simulator below to draw samples and see it take shape.
Simulate it
Change the parameters, then draw random samples. The bars are the samples; the line is the exact density. With more samples the bars settle onto it.
Samples to draw
What is the gamma distribution?
The gamma distribution is defined by a shape k and a scale θ. When k is a whole number it is the total waiting time until the k-th event in a Poisson process, the sum of k exponential waiting times. For other values of k it is a flexible model for positive, right-skewed quantities.
It is the parent of several famous distributions: the exponential is gamma with k = 1 and the chi-square is gamma with shape k/2 and scale 2. In Bayesian statistics it is the usual prior for a rate.
Where it is used
- Time until the k-th customer arrives or the k-th failure occurs.
- Rainfall totals and river flows.
- Insurance claim sizes.
- Positive skewed measurements such as waiting times in queues.
- A prior distribution for a Poisson rate in Bayesian analysis.
Shape and parameters
With k < 1 the density is infinite at 0 and falls steeply; with k = 1 it is the exponential; with k > 1 it rises to a peak at (k − 1)θ and then falls. As k grows it looks more and more normal. The mean is kθ and the variance kθ².
What it assumes
- Positive values.
- For the waiting-time interpretation, independent events at a constant rate.
How it relates to other distributions
- Exponential distribution: Gamma with shape 1.
- Chi-square distribution: Gamma with shape k/2 and scale 2.
- Poisson distribution: The gamma is the waiting time for the k-th Poisson event.
- Beta distribution: A ratio of gammas gives a beta.
Common mistakes
- Mixing up the scale θ and the rate 1/θ: some software uses one and some the other.
- Using it for data that can be zero or negative.
How to work it out
- 1
The probability density function (the formula that gives the shape):
- 2
Its mean (the long-run average) and variance (the spread):
- 3
Worked example with the default parameters (shape k = 3, scale θ = 1): With shape 3 and scale 1, what is the probability of a value below 2?
LaTeX source of the formulas on this page
\[ f(x)=\frac{x^{k-1}e^{-x/\theta}}{\Gamma(k)\,\theta^{k}},\quad x>0 \]
\[ \mu = k\theta,\qquad \sigma^2 = k\theta^2 \]
\[ \text{answer} = 0.3233 \]At a glance
| Property | Value |
|---|---|
| Type | Continuous (measurements) |
| Parameters | shape k; scale θ |
| Possible values | 0 to ∞ |
| Mean | 3 |
| Variance | 3 |
| Standard deviation | 1.7321 |
| Example (shape k = 3, scale θ = 1) | With shape 3 and scale 1, what is the probability of a value below 2? Answer: 0.3233. |
How to compute it in Excel, Python and R
| Tool | Function |
|---|---|
| Excel / Google Sheets | =GAMMA.DIST(x, k, θ, TRUE) (Excel's beta argument is the scale θ) |
| Python (SciPy) | scipy.stats.gamma.cdf(x, a=k, scale=theta) |
| R | pgamma(x, shape = k, scale = theta) |
Questions
What is the gamma distribution used for?
The waiting time for several events, or any positive skewed quantity. Typical uses: Time until the k-th customer arrives or the k-th failure occurs. Rainfall totals and river flows. Insurance claim sizes.
What are the mean and variance of the gamma distribution?
Mean: μ = k\theta. Variance: σ² = k\theta².
What does the gamma distribution assume?
Positive values. For the waiting-time interpretation, independent events at a constant rate.
How do I calculate it in Excel?
=GAMMA.DIST(x, k, θ, TRUE) (Excel's beta argument is the scale θ)
How is the gamma distribution related to other distributions?
Exponential distribution: Gamma with shape 1. Chi-square distribution: Gamma with shape k/2 and scale 2. Poisson distribution: The gamma is the waiting time for the k-th Poisson event. Beta distribution: A ratio of gammas gives a beta.