NegativeBinomialLS#

class superglm.NegativeBinomialLS#

Bases: MeanPredictor, ThetaPredictor

Negative-binomial responses with mean and size predictors.

Declare family.mean(...) and family.theta(...). Both use log links. The unit count law has variance mean + mean**2 / theta, so larger theta means less overdispersion. theta is the size parameter in the NB2 parametrization.

Results use the column names mean and theta in that order. family.theta() estimates a constant size; a declaration with terms lets size vary between rows. The observation law for counts or weighted rates follows the model’s weight contract.

See also

SuperLSS

Construct and fit a model with these predictors.

response_boundaries(
links: Sequence[Link],
) → tuple[tuple[str, ...], ...]#

All-zero rows drive the mean to 0 or the size to 0 under log links.

P(Y = 0) = (theta / (theta + mu))^theta tends to one as log mu -> -inf and as log theta -> -inf.

limit_row_count(
theta: NDArray,
plan: FamilyLikelihoodPlan,
) → tuple[int, int]#

The size’s parameter index and how many rows the kernel treats as Poisson.

Rows with max(mean, count - 1) below 2**-52 times the size, in effective units. The count informs the disclosure only; the terminal rank decision is the test. A derived family reports no rows.

limit_row_disclosure(
n_limit: int,
n_rows: int,
constant_offered: bool,
offset_varies: bool = False,
) → str#

Say that the size is not identified, with n_limit rows at the Poisson limit.

constant_offered (see LimitRowDisclosingFamily) is true when a constant size can be offered and the size has terms to drop; otherwise only the Poisson family is suggested. A derived family gets no text.

expected_information_natural(
theta: NDArray,
plan: FamilyLikelihoodPlan,
) → NDArray[float64]#

Packed natural-scale Fisher information of each row’s mean and size.

predictor_curvature_directional_derivative(
y: NDArray,
eta: NDArray,
eta_direction: NDArray,
links: Sequence[Link],
plan: FamilyLikelihoodPlan,
) → NDArray[float64]#

Differentiate observed predictor curvature along one predictor path.

certified_predictor_curvature_directional_derivative(
y: NDArray,
eta: NDArray,
eta_direction: NDArray,
links: Sequence[Link],
plan: FamilyLikelihoodPlan,
) → tuple[NDArray[float64], NDArray[float64]]#

The curvature direction and the certified error of its l_bbb channel.

predictor_curvature_second_directional_derivative(
y: NDArray,
eta: NDArray,
direction_a: NDArray,
direction_b: NDArray,
links: Sequence[Link],
plan: FamilyLikelihoodPlan,
) → NDArray[float64]#

Differentiate observed predictor curvature twice, along a then b.

certified_predictor_curvature_second_directional_derivative(
y: NDArray,
eta: NDArray,
direction_a: NDArray,
direction_b: NDArray,
links: Sequence[Link],
plan: FamilyLikelihoodPlan,
*,
step: float = 0.001,
) → tuple[NDArray[float64], NDArray[float64]]#

The second curvature direction and the bounded error of its l_bbbb channel.

The series bound does not depend on the derivative step.

log_window_probability(
lower,
upper,
theta,
weights=None,
) → NDArray[float64]#

log P(lower < N/w <= upper); omitted weights mean unit exposure.