All formulas

Probability distributions

Gamma probability density

prob.gamma-pdfAlso called gamma pdf, gamma density, gamma distribution

f(x)=xk−1e−x/θΓ(k) θkf(x) = \frac{x^{k - 1} e^{-x/\theta}}{\Gamma(k)\,\theta^{k}}

Density of the gamma distribution with shape k and scale θ, for x > 0. The mean is kθ.

Notation

xx

the point, x > 0

x > 0

kk

shape

k > 0

θ\theta

scale

θ > 0

f(x)f(x)

Result: the density at x

scalar

Worked examples

Each result is solved exactly and confirmed by two independent computations.

  1. Given

    x=1,k=1,θ=1x = 1, k = 1, \theta = 1

    Result

    f(x)=e−1\displaystyle f(x) = e^{-1}

    ≈ 0.367879441171

  2. Given

    x=2,k=2,θ=1x = 2, k = 2, \theta = 1

    Result

    f(x)=2e2\displaystyle f(x) = \frac{2}{e^{2}}

    ≈ 0.270670566473

  3. Given

    x=1,k=3,θ=0.5x = 1, k = 3, \theta = 0.5

    Result

    f(x)=4e2\displaystyle f(x) = \frac{4}{e^{2}}

    ≈ 0.541341132946

  4. Given

    x=0.5,k=0.5,θ=1x = 0.5, k = 0.5, \theta = 1

    Result

    f(x)=2πe12\displaystyle f(x) = \frac{\sqrt{2}}{\sqrt{\pi} e^{\frac{1}{2}}}

    ≈ 0.483941449038

Common mistakes

  • Uses the rate parameterization

    The code treats θ as a rate β = 1/θ. NumPy's gamma and SciPy's gamma take the scale; many texts write the rate.

    Fix: Use xk−1 e−x/θ / (Γ(k) θk) with θ the scale, or pass scale=1/β.

Sources

  • NIST/SEMATECH e-Handbook, §1.3.6.6.11

    NIST/SEMATECH e-Handbook of Statistical Methods. https://www.itl.nist.gov/div898/handbook/ Last updated 2022-04-27. doi:10.18434/M32189

    doi.org
  • DLMF, eq. 5.2.1

    NIST Digital Library of Mathematical Functions. https://dlmf.nist.gov/ Release 1.2.8 of 2026-09-15. F. W. J. Olver, A. B. Olde Daalhuis, D. W. Lozier, B. I. Schneider, R. F. Boisvert, C. W. Clark, B. R. Miller, B. V. Saunders, H. S. Cohl, and M. A. McClain, eds.

    dlmf.nist.gov