InverseGaussian

Inverse Gaussian family with log link.

Usage

Source

InverseGaussian()

The Inverse Gaussian family models strictly positive, continuous responses whose variance grows even faster than in the Gamma case, producing heavier right tails. It arises naturally as a first-passage-time distribution (e.g. the time for a diffusion process to reach a threshold) and is a common choice for lifetime, duration, and other highly skewed positive data. InverseGaussian is the Tweedie special case with variance power p = 3 (compare Tweedie and tw()), implemented directly here for exact deviance and log-likelihood computations rather than the saddlepoint approximation used by the general Tweedie family. The log link is used for the same reasons as in Gamma: it keeps fitted values positive and gives coefficients a multiplicative interpretation.

Notes

The link is the natural logarithm:

g(\mu) = \log(\mu)

The variance function grows with the cube of the mean:

V(\mu) = \mu^{3},

making this family appropriate when large means are associated with disproportionately large variability. The deviance is

D(y, \hat\mu) = \sum_i \frac{(y_i - \hat\mu_i)^2}{\hat\mu_i^2\, y_i} .

Examples

Fit a GAM to heavy-tailed positive data with a smooth trend:

import numpy as np
import whittaker as wk

rng = np.random.default_rng(0)
n = 200
x = np.linspace(0, 2 * np.pi, n)
mu = np.exp(1.0 + 0.4 * np.sin(x))
scale = 0.5
lam = mu / scale
y = rng.wald(mu, lam)

data = {"x": x, "y": y}

model = wk.GAM("y ~ s(x)", family=wk.InverseGaussian())
model.fit(data, method="REML")
print(model.summary())
GAM fit summary
============================================================
Formula:    y ~ s(x)
Family:     InverseGaussian(link='log')
Inference:  REML
Observations: 200
Coefficients: 10

Parametric coefficients:
  Term                       Estimate    Std.Err    t value    p-value
  ------------------------ ---------- ---------- ---------- ----------
  (Intercept)                  1.0954     0.0555     19.735    < 1e-16

Approximate significance of smooth terms:
  Term                        EDF Ref.df     Chi.sq    p-value
  ------------------------ ------ ------ ---------- ----------
  s(x)                       4.19      5     32.744  4.231e-06

Total EDF:  5.19
Scale est:  0.198556
Deviance:   38.6806
Null dev:   45.4465
Dev. expl:  14.9%
GCV score:  0.203847
AIC:        783.07
BIC:        800.19

Attributes

Name Description
scale_known Whether the dispersion parameter is fixed. Always False for InverseGaussian.

scale_known

Whether the dispersion parameter is fixed. Always False for InverseGaussian.

scale_known: bool

The dispersion phi is estimated from the data during fitting rather than fixed, analogous to how Gamma and Gaussian estimate their own dispersion parameters. This affects how GAM.fit() and GAM.summary() treat the scale.

Methods

Name Description
deviance() Total Inverse Gaussian deviance, the (weighted) sum of unit_deviance.
initialize() Starting values for mu: y nudged away from zero.
link() Apply the log link: \eta = \log(\mu).
link_derivative() Derivative of the log link: g'(\mu) = 1/\mu.
link_inverse() Apply the inverse log link: \mu = e^{\eta}.
log_likelihood() Inverse Gaussian log-likelihood evaluated at dispersion scale.
simulate() Simulate Inverse Gaussian (Wald) response values with mean mu and dispersion scale.
unit_deviance() Per-observation Inverse Gaussian deviance contributions.
variance() Inverse Gaussian variance function: V(\mu) = \mu^3.

deviance()

Total Inverse Gaussian deviance, the (weighted) sum of unit_deviance.

Usage

Source

deviance(
    y,
    mu,
    *,
    weights=None,
)

Parameters

y: NDArray

Observed response values (positive), shape (n,).

mu: NDArray

Fitted conditional mean values, shape (n,).

weights: NDArray | None = None
Optional prior weights, shape (n,).

Returns

float
The total (weighted) deviance.

initialize()

Starting values for mu: y nudged away from zero.

Usage

Source

initialize(y)

Since the log link requires strictly positive mu, values are pushed away from zero to avoid log(0) on the first P-IRLS iteration.

Parameters

y: NDArray
Observed response values (positive), shape (n,).

Returns

NDArray
Starting values for mu, shape (n,).




log_likelihood()

Inverse Gaussian log-likelihood evaluated at dispersion scale.

Usage

Source

log_likelihood(
    y,
    mu,
    scale,
    *,
    weights=None,
)

Parameters

y: NDArray

Observed response values (positive), shape (n,).

mu: NDArray

Fitted conditional mean values, shape (n,).

scale: float

Dispersion parameter \phi.

weights: NDArray | None = None
Optional prior weights, shape (n,).

Returns

float
The total log-likelihood.

simulate()

Simulate Inverse Gaussian (Wald) response values with mean mu and dispersion scale.

Usage

Source

simulate(
    mu,
    scale,
    rng,
)

Draws are generated via Michael, Schucany & Haas’s transformation of a chi-squared variate, then adjusted with a uniform random variable to select between the two candidate roots.

Parameters

mu: NDArray

Mean (fitted values), shape (n,).

scale: float

Dispersion parameter \phi.

rng: np.random.Generator
A numpy.random.Generator instance.

Returns

NDArray
Simulated response values, shape (n,).

unit_deviance()

Per-observation Inverse Gaussian deviance contributions.

Usage

Source

unit_deviance(
    y,
    mu,
)

Computes d_i = (y_i - \hat\mu_i)^2 / (\hat\mu_i^2\, y_i).

Parameters

y: NDArray

Observed response values (positive), shape (n,).

mu: NDArray
Fitted conditional mean values, shape (n,).

Returns

NDArray
Per-observation deviance contributions, shape (n,).

variance()

Inverse Gaussian variance function: V(\mu) = \mu^3.

Usage

Source

variance(mu)

The variance grows with the cube of the mean, giving this family the heaviest right tail among Whittaker’s built-in continuous positive families.

Parameters

mu: NDArray
Conditional mean values, shape (n,).

Returns

NDArray
Variance values \mu^3, shape (n,).