Learn R Programming

tweedie (version 3.2.2)

Tweedie: Tweedie distributions

Description

Density, distribution function, quantile function and random generation for the the Tweedie family of distributions, with mean mu, dispersion parameter phi and variance power power (or xi, a synonym for power).

Usage

dtweedie(y, xi = NULL, mu, phi, power = NULL, verbose = FALSE, log = FALSE)
ptweedie(q, xi = NULL, mu, phi, power = NULL, lower.tail = TRUE, 
  log.p = FALSE, verbose = FALSE)
qtweedie(p, xi = NULL, mu, phi, power = NULL)
rtweedie(n, xi = NULL, mu, phi, power = NULL)

Value

dtweedie() gives the density, ptweedie() gives the distribution function, qtweedie() gives the quantile function, and rtweedie generates random deviates.

As for R's own functions for distributions (such as dnorm), the result of dtweedie(), ptweedie() and qtweedie() has the same length and form as the first input (y, q or p): its attributes are kept, so (for example) a matrix gives a matrix, and a named vector gives a named vector. (mu and phi must be scalars, or the same length as the first input.) rtweedie() returns a vector of length n, without attributes.

Arguments

y

vector of quantiles.

xi

scalar; the value of \(\xi\) such that the variance is \(\mbox{var}[Y]=\phi\mu^{\xi}\). A synonym for power.

mu

vector of mean \(\mu\).

phi

vector of dispersion parameters \(\phi\).

power

scalar; a synonym for \(\xi\), the Tweedie index parameter.

verbose

logical; if TRUE, some details of the algorithms used is shown. The default is FALSE.

log

logical; if TRUE, dtweedie() returns the log of the density, computed without underflow (so it stays finite far into the tails, where the density itself underflows to zero). The default is FALSE.

q

vector of quantiles.

p

vector of probabilities.

n

number of observations. If length(n) > 1, the length is taken to be the number required (as for rnorm).

lower.tail

logical; if TRUE (the default), computes the lower tail \(F(y)\); otherwise computes \(S(y) = 1 - F(y)\).

log.p

logical; if TRUE, probabilities are returned as \(\log(p)\). The default is FALSE.

Details

Tweedie edms belong to the class of exponential dispersion models (edms), known for their role in generalized linear models (glms). The Tweedie distributions are the edms with a variance of the form \(\mbox{var}[Y] = \phi\mu^p\) where \(p \ge 1\). This function only evaluates for \(p \ge 1\).

Special cases are the Poisson (\(p = 1\) with \(\phi = 1\)), gamma (\(p = 2\)), and inverse Gaussian (\(p = 3\)) distributions. Evaluation is difficult for \(p\) outside of \(p = 0, 1, 2, 3\). For the density, dtweedie() uses one of three methods for each value, depending on \(p\) and \(z = \phi y^{p - 2}\) (the dispersion after rescaling \(y\) to one):

  1. the saddlepoint approximation with its asymptotic correction, where \(z\) is small enough for its estimated relative error to be below \(10^{-13}\);

  2. otherwise, the series (dtweedie_series) for \(1 < p < 2\), and for \(p > 2\) where its estimated relative error is below \(10^{-12}\);

  3. otherwise, the Fourier inversion (dtweedie_inversion).

Against high-precision reference values, the relative error of the density is below about \(4 \times 10^{-13}\). (Before version 3.2.0, dtweedie() also interpolated from stored values of the Fourier inversion, which was less accurate.)

When \(1<p<2\), the density function include a positive probability for \(Y = 0\).

References

Dunn, Peter K and Smyth, Gordon K (Submitted). Evaluation of the Tweedie exponential dispersion model distribution function. Submitted.

Dunn, P. K. and Smyth, G. K. (2008). Evaluation of Tweedie exponential dispersion model densities by Fourier inversion. Statistics and Computing, 18, 73--86. tools:::Rd_expr_doi("10.1007/s11222-007-9039-6")

Dunn, Peter K and Smyth, Gordon K (2005). Series evaluation of Tweedie exponential dispersion model densities Statistics and Computing, 15(4). 267--280. tools:::Rd_expr_doi("10.1007/s11222-005-4070-y")

Jorgensen, B. (1997). Theory of Dispersion Models. Chapman and Hall, London.

See Also

dtweedie_series, dtweedie_inversion, ptweedie_series, ptweedie_inversion, dtweedie_saddle, tweedie_lambda

Examples

Run this code
# Compute a Tweedie density
power <- 1.1
mu <- 1
phi <- 1
y <- seq(0, 5, by = 0.5)
dtweedie(y, power = power, mu = mu, phi = phi)

# Compare to the saddlepoint density
dtweedie_saddle(y = y, power = power, mu = mu, phi = phi)

# The DF:
ptweedie(y, power = power, mu = mu, phi = phi)

Run the code above in your browser using DataLab