tw()

Create a Tweedie family with estimated variance power.

Usage

Source

tw(
    p_range=(1.01, 1.99),
    n_grid=20,
)

Convenience constructor mirroring the tw() function familiar from mgcv. The variance power p of the Tweedie distribution (see Tweedie) is selected automatically by profile likelihood during model fitting rather than fixed by the user. The model is fitted at n_grid candidate values of p spaced across p_range, and the value minimizing AIC is chosen as the final family.

Parameters

p_range: tuple of float = (1.01, 1.99)

(p_min, p_max) range to search. Must satisfy 1 < p_min and p_max < 2 (or both > 2 for the positive-continuous case). Defaults to (1.01, 1.99), which covers the compound Poisson-Gamma case used for most zero-inflated positive data.

n_grid: int = 20
Number of candidate p values in the grid search. Defaults to 20.

Returns

TweedieEstimated
A Tweedie family, with variance function V(\mu) = \mu^{p} and log link g(\mu) = \log(\mu), whose power p will be estimated by profile likelihood the next time the returned family is passed to GAM.fit().

Examples

import whittaker as wk

model = wk.GAM("y ~ s(x)", family=wk.tw(p_range=(1.05, 1.95), n_grid=15))