EZ Statistics

Gamma Distribution Calculator

Calculator

Parameters

Distribution Chart

Click Calculate to view the distribution chart

Learn More

Gamma Distribution: Definition, Formula, and Applications

Gamma Distribution

Definition: The gamma distribution is a continuous probability distribution that arises naturally in processes for which the waiting times between events are relevant.

Formula:The probability density function (PDF) is given by:f(x;α,θ)=xα1ex/θθαΓ(α),x>0f(x; \alpha, \theta) = \frac{x^{\alpha-1} e^{-x/\theta}}{\theta^\alpha \Gamma(\alpha)}, \quad x > 0Where:Γ(α)=0tα1etdt\Gamma(\alpha) = \int_0^\infty t^{\alpha-1} e^{-t} dt

Where:

  • α\alpha is the shape parameter (determines the basic shape)
  • θ\theta is the scale parameter (stretches/compresses the distribution)
  • Γ(α)\Gamma(\alpha) is the gamma function

Properties

  • Mean: E(X)=αθE(X) = \alpha\theta
  • Variance: Var(X)=αθ2\text{Var}(X) = \alpha\theta^2
  • Mode: (α1)θ(\alpha-1)\theta for α1\alpha \geq 1
  • Support: (0,)(0, \infty)
  • Special cases:
    • When α=1\alpha = 1, reduces to exponential distribution
    • When α=n/2,θ=2\alpha = n/2, \theta = 2, becomes chi-square distribution with n degrees of freedom
    • For large α\alpha, approaches normal distribution

Applications

1. Waiting Time Analysis

The gamma distribution is often used to model waiting times, particularly when the waiting time represents the sum of several independent exponential waiting times. This makes it useful in queuing theory and service time modeling. For example, it can model the time needed to complete a complex task that consists of several sequential steps.

2. Reliability Engineering

In reliability engineering, the gamma distribution can model the time until failure for systems where failure occurs after accumulated wear and tear rather than sudden events. It's particularly useful when modeling systems that fail only after multiple minor degradations have accumulated.

3. Climate and Weather Analysis

The gamma distribution is commonly used in meteorology to model rainfall amounts and other precipitation patterns. It's particularly suitable because it's defined only for positive values and can represent both heavily skewed and more symmetric distributions, depending on its parameters.

4. Financial Analysis

In finance, the gamma distribution can model insurance claims, asset returns, and other financial metrics. It's particularly useful in risk analysis and portfolio management where asymmetric distributions are common and negative values are impossible.

R Code Example

library(tidyverse)

# Parameters
shape <- 2
scale <- 2

# Calculate probability between two values
x1 <- 2
x2 <- 4
prob <- pgamma(x2, shape = shape, scale = scale) - pgamma(x1, shape = shape, scale = scale)
print(str_glue("P({x1} < X < {x2}) = {round(prob, 4)}"))

# Create plot
x <- seq(0, 12, length.out = 1000)
y <- dgamma(x, shape = shape, scale = scale)
df <- tibble(x = x, y = y)

ggplot(df, aes(x = x, y = y)) +
  geom_line(color = "blue") +
  geom_area(data = subset(df, x >= x1 & x <= x2), 
            aes(x = x, y = y), 
            fill = "blue", 
            alpha = 0.2) +
  labs(title = str_glue("Gamma Distribution (α = {shape}, θ = {scale})"),
       x = "x",
       y = "Probability Density",
       caption = str_glue("P({x1} < X < {x2}) = {round(prob, 4)}")) +
  theme_minimal()

Python Code Example

import numpy as np
import pandas as pd
from scipy import stats
import matplotlib.pyplot as plt
import seaborn as sns

# Set parameters
shape = 2  # alpha
scale = 2  # theta

# Calculate probability between two values
x1, x2 = 2, 4
prob = stats.gamma.cdf(x2, a=shape, scale=scale) - stats.gamma.cdf(x1, a=shape, scale=scale)
print(f"P({x1} < X < {x2}) = {prob:.4f}")

# Create plot
x = np.linspace(0, 12, 1000)
pdf = stats.gamma.pdf(x, a=shape, scale=scale)

plt.figure(figsize=(10, 6))
plt.plot(x, pdf, 'blue', label='PDF')

# Add shaded area
x_shade = x[(x >= x1) & (x <= x2)]
pdf_shade = stats.gamma.pdf(x_shade, a=shape, scale=scale)
plt.fill_between(x_shade, pdf_shade, alpha=0.2, color='blue')

# Customize plot
plt.title(f'Gamma Distribution (α = {shape}, θ = {scale})')
plt.xlabel('x')
plt.ylabel('Probability Density')
plt.annotate(f'P({x1} < X < {x2}) = {prob:.4f}',
            xy=(6, max(pdf)/2),
            xytext=(6, max(pdf)/2))

plt.grid(True, alpha=0.3)
plt.show()

Related Links

Normal Distribution Calculator

Exponential Distribution Calculator

Chi-Square Distribution Calculator

Beta Distribution Calculator