NegativeBinomial#

class superglm.NegativeBinomial(theta: float | str)#

Bases: object

Negative binomial (NB2) family with overdispersion controlled by theta.

Parameters:
thetafloat or “auto”

Overdispersion parameter (>0). Larger theta = less overdispersion. As theta -> inf, approaches Poisson. Pass "auto" to estimate theta via profile likelihood during fit().

variance(
mu: NDArray,
) → NDArray#

V(μ) = μ + μ²/θ.

variance_derivative(
mu: NDArray,
) → NDArray#

V’(μ) = 1 + 2μ/θ.

variance_second_derivative(
mu: NDArray,
) → NDArray#

V’’(μ) = 2/θ. Wood (2011) Appendix D.

deviance_unit(
y: NDArray,
mu: NDArray,
) → NDArray#

NB2 unit deviance.

log_likelihood(
y: NDArray,
mu: NDArray,
weights: NDArray,
phi: float = 1.0,
) → float#

NB2 log-likelihood: Σ w[log Γ(y+θ) - log Γ(θ) - log Γ(y+1) + θ log(θ/(μ+θ)) + y log(μ/(μ+θ))].