Learn R Programming

tweedie (version 3.2.2)

tweedie_convert: Tweedie Distribution: Convert Between Parameter Formats

Description

For \(1 < p < 2\), a Tweedie random variable is a Poisson sum of gamma random variables: \(Y = \sum_{i=1}^N Z_i\), where \(N \sim \mbox{Pois}(\lambda)\) and the \(Z_i\) are independent gamma variables with shape \(\alpha\) and scale \(\gamma\).

tweedie_convert() converts from the Tweedie (glm) parameters \(p\), \(\mu\) and \(\phi\) to the underlying Poisson parameter \(\lambda\) and gamma parameters \(\alpha\) and \(\gamma\).

tweedie_convert_back() converts the other way: from \(\lambda\), \(\alpha\) and \(\gamma\) to \(p\), \(\mu\) and \(\phi\).

Usage

tweedie_convert(xi = NULL, mu, phi, power = NULL)

tweedie_convert_back(lambda, alpha, gamma)

tweedie.convert(xi = NULL, mu, phi, power = NULL)

Value

tweedie_convert() returns a list of the parameters of the corresponding underlying Poisson and gamma distributions: poisson.lambda (\(\lambda\) from the underlying Poisson distribution), gamma.shape, gamma.scale (the shape \(\alpha\) and scale \(\gamma\) parameters from the underlying gamma distribution),

p0 (the probability that \(Y = 0\)),

gamma.mean and gamma.phi (the gamma mean \(\alpha\gamma\)

and dispersion parameter \(1/\alpha\) values).

tweedie_convert_back() returns a list containing mu (the Tweedie mean \(\mu\)), phi (the Tweedie dispersion parameter \(\phi\)), power (the Tweedie index parameter \(p\)), and p0 (the probability that \(Y = 0\)).

Arguments

xi

a synonym for power.

mu

the mean parameter \(\mu\).

phi

the dispersion parameter \(\phi\).

power

the power parameter \(p\); a synonym for \(\xi\).

lambda

the mean \(\lambda\) of the underlying Poisson distribution.

alpha

the shape parameter \(\alpha\) of the underlying gamma distribution.

gamma

the scale parameter \(\gamma\) of the underlying gamma distribution (the reciprocal of the rate parameter).

Details

The relationships are $$\lambda = \frac{\mu^{2 - p}}{\phi (2 - p)}, \quad \alpha = \frac{2 - p}{p - 1}, \quad \gamma = \phi (p - 1) \mu^{p - 1}$$ and, in reverse, $$p = \frac{\alpha + 2}{\alpha + 1}, \quad \mu = \lambda \alpha \gamma, \quad \phi = \frac{\lambda \alpha (\alpha + 1) \gamma^2}{\mu^p}.$$

Here \(\gamma\) is the gamma scale parameter; the corresponding rate parameter (sometimes written \(\beta\)) is \(\beta = 1/\gamma\). In R's notation, the gamma variables are rgamma(n, shape = alpha, scale = gamma).

Examples

Run this code
### Fit a Tweedie density
pretend <- data.frame( y = rgamma(20, shape = 1, rate = 1) )
fit <- glm(y ~ 1, data = pretend,
           family = statmod::tweedie(link.power = 0, var.power = 1.4))

# Convert parameters
tweedie_convert(mu = fitted(fit, type="response"), phi = 1, power = 1.4)

### Convert, then convert back
pg <- tweedie_convert(mu = 2, phi = 0.5, power = 1.4)
tweedie_convert_back(lambda = pg$poisson.lambda,
                     alpha  = pg$gamma.shape,
                     gamma  = pg$gamma.scale)

Run the code above in your browser using DataLab