import math


def negbin_pdf(x, m, a):
    """
    We need to draw values from an overdispersed negative binomial distribution, with non-integer inputs. Had to
    generate the numbers myself in order to do this.
    This is the generalized negbin used in glm models I think.

    m = mean
    a = overdispertion
    """
    A = math.gamma(x + 1 / a) / (math.gamma(x + 1) * math.gamma(1 / a))
    B = (1 / (1 + a * m))**(1 / a)
    C = (a * m / (1 + a * m))**x
    return A * B * C