# tw()


Create a Tweedie family with estimated variance power.


Usage

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


Convenience constructor mirroring the [tw()](tw.md#whittaker.tw) function familiar from `mgcv`. The variance power [p](Tweedie.md#whittaker.Tweedie.p) of the Tweedie distribution (see [Tweedie](Tweedie.md#whittaker.Tweedie)) is selected automatically by profile likelihood during model fitting rather than fixed by the user. The model is fitted at [n_grid](PartialDependenceResult.md#whittaker.PartialDependenceResult.n_grid) candidate values of [p](Tweedie.md#whittaker.Tweedie.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](Tweedie.md#whittaker.Tweedie.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](Tweedie.md#whittaker.Tweedie.p) will be estimated by profile likelihood the next time the returned family is passed to [GAM.fit()](GAM.md#whittaker.GAM.fit).


## Examples


``` python
import whittaker as wk

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