Gamma Distribution Calculator
Calculator
Parameters
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.
Where:
- is the shape parameter (determines the basic shape)
- is the scale parameter (stretches/compresses the distribution)
- is the gamma function
Properties
- Mean:
- Variance:
- Mode: for
- Support:
- Special cases:
- When , reduces to exponential distribution
- When , becomes chi-square distribution with n degrees of freedom
- For large , 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()