pyfastnbfit/pyfastnbfit.py
def fastfit_negbin(observed, tol=1e-4, max_iterations=100):
    """Fit Negatove Binomial.

    Parameters
    ----------
    observed: array_like
              Observed values

    tol: float
         Tolerance criterion for stopping
         iterations when difference between sucessive estimates
         drops below this value.

    max_iterations: int
                    Maximum number of iterations.

    Returns
    -------
    param_dict: dict
                Dict with inferred parameters and number of iterations
    """

    xmean = np.mean(observed)

    xvar = np.var(observed)
    b = xmean / xvar - 1

    if b < 0:
        b = 1e-3

    a = xmean / b
    a_old = np.inf
    iteration = 0
    while (np.abs(a_old - a) > tol) and (iteration < max_iterations):
        a_old = a
        p = b / (b + 1)
        # sufficient stat
        obsa = observed + a
        xmean = np.mean((obsa) * p)
        s = np.log(xmean) - np.mean(digamma(obsa) + np.log(p))
        a, b, _ = fastfit_gamma(xmean, s, tol=tol)
        iteration += 1
    return {
        "theta": a,
        "dispersion": 1/a,
        "mu": a*b,
        "iterations": iteration
    }
Fit Negatove Binomial.

    Parameters
    ----------
    observed: array_like
              Observed values

    tol: float
         Tolerance criterion for stopping
         iterations when difference between sucessive estimates
         drops below this value.

    max_iterations: int
                    Maximum number of iterations.

    Returns
    -------
    param_dict: dict
                Dict with inferred parameters and number of iterations
    
Fit Negatove Binomial.
Parameters



float
Tolerance criterion for stopping
iterations when difference between sucessive estimates
drops below this value.

int
Maximum number of iterations.

Returns

dict
Dict with inferred parameters and number of iterations
Fit Negatove Binomial . Parameters float Tolerance criterion for stopping iterations when difference between sucessive estimates drops below this value . int Maximum number of iterations . Returns dict Dict with inferred parameters and number of iterations
def fastfit_negbin(observed, tol=1e-4, max_iterations=100):
    xmean = np.mean(observed)
    xvar = np.var(observed)
    b = xmean / xvar - 1
    if b < 0:
        b = 1e-3
    a = xmean / b
    a_old = np.inf
    iteration = 0
    while (np.abs(a_old - a) > tol) and (iteration < max_iterations):
        a_old = a
        p = b / (b + 1)
        obsa = observed + a
        xmean = np.mean((obsa) * p)
        s = np.log(xmean) - np.mean(digamma(obsa) + np.log(p))
        a, b, _ = fastfit_gamma(xmean, s, tol=tol)
        iteration += 1
    return {
        "theta": a,
        "dispersion": 1/a,
        "mu": a*b,
        "iterations": iteration
    }
def fastfit_negbin ( observed , tol = 1e-4 , max_iterations = 100 ) : xmean = np . mean ( observed ) xvar = np . var ( observed ) b = xmean / xvar - 1 if b < 0 : b = 1e-3 a = xmean / b a_old = np . inf iteration = 0 while ( np . abs ( a_old - a ) > tol ) and ( iteration < max_iterations ) : a_old = a p = b / ( b + 1 ) obsa = observed + a xmean = np . mean ( ( obsa ) * p ) s = np . log ( xmean ) - np . mean ( digamma ( obsa ) + np . log ( p ) ) a , b , _ = fastfit_gamma ( xmean , s , tol = tol ) iteration += 1 return { "theta" : a , "dispersion" : 1 / a , "mu" : a * b , "iterations" : iteration }
Fit Negatove Binomial.
Fit Negatove Binomial .
"""Fit Negatove Binomial.

    Parameters
    ----------
    observed: array_like
              Observed values

    tol: float
         Tolerance criterion for stopping
         iterations when difference between sucessive estimates
         drops below this value.

    max_iterations: int
                    Maximum number of iterations.

    Returns
    -------
    param_dict: dict
                Dict with inferred parameters and number of iterations
    """ # sufficient stat
observed
tol
max_iterations