TweedieLSS#

class superglm.TweedieLSS(power_lower: float = 1.05, power_upper: float = 1.95)#

Bases: TweediePredictors

Nonnegative responses with mean, dispersion and variance-power predictors.

Declare all three predictors with family.mu(...), family.phi(...) and family.p(...). Their result and offset names are mean, dispersion and power. The mean and dispersion use log links; power uses a bounded link between the configured limits.

For power between one and two, the distribution has a point mass at zero and a continuous positive part. At unit prior weight, variance is dispersion * mean**power.

Parameters:
power_lowerfloat, default=1.05

Lower bound on fitted power. Must be greater than one.

power_upperfloat, default=1.95

Upper bound on fitted power. Must exceed power_lower and be less than two. The fitted power stays strictly between the two bounds.

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 (log link) or the dispersion to infinity.

With every response at zero the row log-likelihood is -w mu^(2-p) / (phi (2-p)), which increases without bound as log mu -> -inf or log phi -> +inf; the power predictor is bounded on its interior walls.

predictor_rows(
y: NDArray,
plan: FamilyLikelihoodPlan,
links: Sequence[Link],
shared_last: bool,
)#

Compiled rows in predictor coordinates, or None where these links or rows need evaluate_natural. shared_last says one power serves every row.

The rows decline a power at the link’s walls and the family refuses one at its own, so a link whose walls lie outside the family’s keeps the natural route.

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.

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.

Kernel derivatives are in (mu, rho = log phi, p); the dispersion reaches rho through log of its inverse link, so no phi-scale round trip cancels. A refused row sends the caller to differences.

cdf(
y: NDArray,
theta: NDArray,
) → NDArray[float64]#

P(Y <= y) per row at unit prior weight.

log_window_probability(lower, upper, theta, weights=None)#

log P(lower < Y <= upper), including the atom iff lower < 0 <= upper.

Optional weights define the reproductive prior law, never replication. Numerical/work refusal is explicit; empty events return -inf.

quantile(
p: NDArray,
theta: NDArray,
) → NDArray[float64]#

The p-quantile per row at unit prior weight, p inside (0, 1).

cdf_left_limit(
y: NDArray,
theta: NDArray,
weights: NDArray | None = None,
) → NDArray[float64]#

P(Y < y) per row: zero on the atom at zero, P(Y <= y) above it.

The atom interval a randomised PIT samples on a zero row is therefore [0, P(Y = 0)]; the law is continuous everywhere else.

cdf_prior_weighted(
y: NDArray,
theta: NDArray,
weights: NDArray,
) → NDArray[float64]#

P(Y <= y) per row with a prior weight entering as the dispersion phi / w.

quantile_prior_weighted(
p: NDArray,
theta: NDArray,
weights: NDArray,
) → NDArray[float64]#

The prior-weighted p-quantile per row, p inside (0, 1).

Probabilities at or below the row’s zero mass return the atom itself.

variance(
theta: NDArray,
) → NDArray[float64]#

Var(Y) = phi mu^p per row at unit prior weight.

variance_prior_weighted(
theta: NDArray,
weights: NDArray,
) → NDArray[float64]#

Var(Y) = phi mu^p / w per row: the prior weight enters as phi / w.