tweedie: Tweedie (compound Poisson Gamma) family

tweedieR Documentation

Tweedie (compound Poisson Gamma) family

Description

Returns a GLM family object for the Tweedie family of distributions (e.g., Dunn & Smyth, 2018). The variance of such distributions is related to the mean \mu: variance=\phi\mu^p, where \phi is a dispersion parameter (as in Gaussian and Gamma families), and p is the index parameter of the distribution, which can be specified as the index argument of the function, and is referred to in other contexts (such as initial values for optimization) as Tw_index. The index need or need not be specified when calling tweedie, depending on usage. The current implementation handles values 1<p<2, for which the distributions are a Poisson sum of Gamma distributions.

The family link is controlled by another argument, link, that may specify a log link, or the exponent q of the link relationship \eta=\mu^q.

glm can be used with this family object and given index.

Fitting Tweedie models by spaMM's fitting functions requires some functions from the tweedieDistr package, or else from the tweedie package, so either one of these suggested packages must be installed. Various problems are theoretically expected for p close to zero (see Details), so the default parameter range when p is estimated is 1.1 – 1.999.

A structured-dispersion model can be fitted for \phi but this is sensitive to numerical issues (see Details about “inner estimation” of \phi).

Usage

tweedie(index, link = "log", numderiv=TRUE, ...)

Arguments

index

Missing or numeric value for the index parameter p, subject to the constraint 1<p<2. The “outer-optimizing” functions, such as fitme (see inner-vs-outer) will estimate this parameter if called with family=tweedie() (no given index value). In other usages of this family, index must be specified.

link

Link function, specified either as the default "log" for a log link, or as the link exponent q. q=0 is interpreted as the log link. There is no definite constraint on q, but using values that imply that \eta should be positive (such as 1, or non-integer values) may run into troubles. Values closes to 0 and 1 also lead to numerical errors. See Details if you want to estimate this parameter.

numderiv

Boolean; whether to use numerical derivation in some computation. numderiv=FALSE (not recommended) will be ignored if the tweedie package is not installed.

...

Additional arguments passed to some member functions of the returned family object. Currently used only for the method and method.args of grad if numerical derivatives are used (see numderiv argument).

Details

One can force spaMM's “outer-optimization” fitting functions to estimate the link exponent by using tweedie(link="fit"), and specyfing init, lower and upper values for the link exponent (using the name Tw_link for their values: see Examples). However this will fail if negative values of \eta are generated during the fitting process.

Estimates of the residual dispersion parameter \phi are by default constrained to be > 1e-05 because evaluations of the Tweedie density function are increasingly slow as \phi approaches 0. Other minimal \phi value can be set through the lower argument, as usual (or through control.HLfit$min_phi for inner estimation).

When p is close to 1, the Tweedie density is multimodal; further, when responses are recorded to a limited number of decimal places, the profile likelihood for p may be bimodal with a spurious maximum at p = 1 (Dunn & Smyth 2005). From limited numerical experiments, for low p such as 1.05, computed likelihood profiles with respect to \phi also often exhibited several maxima. Overall, estimation for low p will be sensitive to many things.

If the fitting function uses inner-estimation methods to fit \phi (see inner-vs-outer), it then requires evaluation of a derivative of the Tweedie density, which may be slow or not very accurate, depending on the method used (which can be controlled by the numderiv and optional ... arguments). So the fitting function avoids inner estimation for \phi, when possible. When it is used,
\bullet examples were found where the inner-estimation iterative algorithm did not converge due to cyclic values of \phi estimates, for p<1.5. An experimental correction has been implemented to fix this convergence issue;
\bullet the results are sensitive to the algorithm used to compute the derivative of the conditional likelihood (with the default algorithm appearing better), and maybe more so when both p and \phi are small.

Value

A family object with structure similar to stats::family objects, but with additional member functions for usage with spaMM fitting functions.

References

Dunn, Peter K and Smyth, Gordon K (2005) Series evaluation of Tweedie exponential dispersion model densities. Stat Comput 15, 267–280. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/s11222-005-4070-y")}

Dunn, Peter K and Smyth, Gordon K (2018) Generalized Linear Models With Examples in R. Springer, NY. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/978-1-4419-0118-7")}

Dunn, P. K. (2026). Tweedie: Evaluation of Tweedie exponential family models. R package. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.32614/CRAN.package.tweedie")}

Examples

if (spaMM.getOption("example_maxtime")>1.4) {
### toy data 
  set.seed(123)
  y <- rgamma(20,shape=rpois(20,lambda=rgamma(20,5)))
  x <- 1:20
  toyTw <- data.frame(x=x,y=y, grp=x)
  
### Fits
fitme(y~x+(1|grp),family=spaMM::tweedie(), data=toyTw) 

# tentative estimation of the link exponent:      
fitme(y~x+(1|grp),family=spaMM::tweedie(link="fit"), data=toyTw, 
      init=list(lambda=NA, phi=NA, Tw_link=0.5),
      lower=list(Tw_link=0.4), upper=list(Tw_link=0.6)) 
# (this shows that this _can_ work).

### Interactions with other packages
  tweedie::logLiktweedie(toyglm <- 
    glm(y~x,family=spaMM::tweedie(index=1.5,link= -0.5), data=toyTw))
  toyglm$fitted.values
  predict(toyglm, type="response")
  tweedie::logLiktweedie(spaMM_glm(y~x,
    family=spaMM::tweedie(index=1.5,link= -0.5), data=toyTw))
}

spaMM documentation built on Sept. 10, 2026, 1:07 a.m.