GammaLS#

class superglm.GammaLS#

Bases: MeanPredictor, ScalePredictor

Positive responses with mean and coefficient-of-variation predictors.

Declare family.mean(...) and family.scale(...). Both use log links. Here scale is the coefficient of variation, so the unit-law variance is mean**2 * scale**2. It is the square root of GLM Gamma dispersion, and differs from the scale argument of scipy.stats.gamma.

Results use the column names mean and scale in that order. Responses must be strictly positive. An empty helper call estimates a constant parameter through an intercept-only predictor.

See also

SuperLSS

Construct and fit a model with these predictors.

censored_recession(
bounds: ResponseBounds,
) → NDArray[bool]#

Every censored row escapes along the mean; none is flagged on the scale.

At a fixed coefficient of variation the mean is a scale parameter, and d^2 log f/(dy dm) = a/m^2 > 0 is a monotone likelihood ratio in m, so within any truncation window P(Y > c) rises and P(Y <= c) falls strictly with the mean. Along the coefficient of variation, at a fixed mean, P(Y <= c) nears one both as cv grows and, for c above the mean, as it shrinks, and P(Y > c) nears its supremum as cv shrinks only for c below the mean and peaks at an interior cv above it, so the direction depends on the fitted mean.

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.

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

log P(lower < Y <= upper) per row, shape w/cv^2 with prior weights w.

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

P(Y <= y) per row: shape 1/cv^2 and scale mean cv^2.

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

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

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

E[Y | Y > q_p] for shape 1 / cv^2 at unit prior weight.

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

Var(Y) = (mean cv)^2 per row at unit prior weight.

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

Var(Y) = (mean cv)^2 / w per row: shape w / cv^2, scale mean cv^2 / w.

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

P(Y <= y) per row: shape w / cv^2 and scale mean cv^2 / w.

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

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

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

E[Y | Y > q_p] for weighted shape w / cv^2.