# lib5c.algorithms.variance.nbinom_dispersion module¶

Module for estimating negative binomial dispersion parameters for 5C interaction data.

lib5c.algorithms.variance.nbinom_dispersion.dispersion_to_variance(disp, exp)[source]

Converts a dispersion estimate to a variance by applying it to the expected value via the relationship var = exp + disp * exp**2.

Parameters
• disp (float or np.ndarray) – The dispersion.

• exp (float or np.ndarray) – The expected value.

Returns

The variance.

Return type

float or np.ndarray

lib5c.algorithms.variance.nbinom_dispersion.nb_nll(disp, obs, exp)[source]

The negative log likelihood of observed data obs given mean/expected value exp and dispersion parameter disp.

Parameters
• disp (float or np.ndarray) – The dispersion parameter.

• obs (int or np.ndarray) – The observed data.

• exp (float or np.ndarray) – The mean/expected value.

Returns

The negative log likelihood.

Return type

float

lib5c.algorithms.variance.nbinom_dispersion.nb_nll_derivative(disp, obs)[source]

Derivative of the negative binomial log-likelihood function with respect to the dispersion parameter, given observed data.

This function is vectorized. Pass one dispersion and a vector of observed values to evaluate the derivative with just that one dispersion on the collection of all the observed values passed. Pass a vector of dispersions and a matrix of observed values to compute a vector of derivative evaluations, using the i th element of the dispersion vector and the i th row of the observed matrix to compute the i th derivative evaluation.

Parameters
• disp (float or np.ndarray) – The negative binomial dispersion parameter.

• obs (np.ndarray) – The observed values. If disp is a vector, this should be a matrix whose number of rows equals the length of disp.

Returns

The derviative evaluation(s).

Return type

float or np.ndarray

lib5c.algorithms.variance.nbinom_dispersion.nb_pmf(k, m, alpha)[source]

The negative binomial PMF, parametrized in terms of a mean m and a dispersion alpha.

Parameters
• k (int or np.ndarray) – The observed value.

• m (float or np.ndarray) – The expected or mean value.

• alpha (float or np.ndarray) – The dispersion parameter.

Returns

The value of the PMF.

Return type

float or np.ndarray

lib5c.algorithms.variance.nbinom_dispersion.variance_to_dispersion(var, exp, min_disp=None)[source]

Converts a variance estimate to a dispersion estimate by reversing the relationship in dispersion_to_variance(). Only defined for points where var > exp. If var is the sample variance and exp is the sample mean, this is the equivalent to the method-of-moments estimate of the dispersion parameter.

Parameters
• var (float or np.ndarray) – The variance.

• exp (float or np.ndarray) – The expected value.

• min_disp (float, optional) – Pass a value to enter a lenient mode where underdispersed points will be allowed, but will not be assigned a dispersion value from the statistical relationship. Underdispersed points will instead be assigned the min_disp value.

Returns

The dispersion.

Return type

float or np.ndarray