Learn R Programming

tweedie (version 3.2.2)

ptweedie_inversion: Fourier Inversion Evaluation for the Tweedie Distribution Function

Description

Evaluates the distribution function (df) for Tweedie distributions using Fourier inversion, for given values of the dependent variable y, the mean mu, dispersion phi, and power parameter power. Not usually called by general users, but can be in the case of evaluation problems.

Usage

ptweedie_inversion(q, mu, phi, power, lower.tail = TRUE, log.p = FALSE, IGexact = TRUE, 
                          verbose = FALSE, details = FALSE)

ptweedie.inversion(q, power, mu, phi, verbose, details)

Value

If details = FALSE, a numeric vector of the distribution function values; if details = TRUE, a list containing cdf (a vector of the values of the distribution function), regions (a vector of the number of integration regions used), exitstatus (a vector, where a 1 for any value means a computational problem or target relative accuracy not reached, for the corresponding observation), and small_tail (a logical vector; TRUE where the inversion returned a tail probability below \(10^{-8}\), whose relative accuracy may be poor; see the Accuracy section).

For special cases of \(p\) (i.e., \(p = 0, 1, 2, 3\)), where no inversion is needed, regions is set to NA for all values of q. For special cases of q for other values of \(p\) (i.e., \(P(Y = 0)\)), regions is set to NA.

Arguments

q

vector of quantiles.

mu

the mean parameter.

phi

the dispersion parameter.

power

the power parameter \(p\).

lower.tail

logical; if TRUE (the default) computes the distribution function \(F(y)\); if FALSE, computes \(1 - F(y)\).

log.p

logical; if TRUE, probabilities are returned as \(\log(p)\), computed directly from the already-correctly-computed tail probability rather than as log(ptweedie_inversion(...)) after the fact. The default is FALSE.

IGexact

logical; if TRUE (the default), evaluate the inverse Gaussian distribution using the 'exact' values, otherwise uses inversion.

verbose

logical; if TRUE, displays some internal computation details. The default is FALSE.

details

logical; if TRUE, returns the value of the distribution and some information about the integration. The default is FALSE.

Accuracy

The inversion computes \(F(y) = 1/2 - I/\pi\) (and \(1 - F(y) = 1/2 + I/\pi\) for the upper tail), where \(I\) is the integral evaluated numerically (for \(1 < p < 2\), the constant \(1/2\) is replaced by \((1 \pm e^{-\lambda})/2\)). When the requested tail probability \(P\) is small, \(I/\pi\) is close to \(1/2\) and most of the digits cancel, so the error is absolute (a few times \(10^{-16}\)) rather than relative: the relative error is about \(10^{-16}/P\) or a few times larger. Tail probabilities below about \(10^{-8}\) may therefore have poor relative accuracy, and those far below \(10^{-16}\) may have no correct digits. These values are flagged by small_tail when details = TRUE; no warning is given.

ptweedie() does not have this limitation: it recomputes small tail probabilities from the inversion by integrating the density, which keeps its relative accuracy far into the tails. Use ptweedie() for small tail probabilities.

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")

Giner G., Smyth G. K. (2016). statmod: probability calculations for the inverse Gaussian distribution. The R Journal, 8(1), 339--351. tools:::Rd_expr_doi("doi:10.32614/RJ-2016-024")

Examples

Run this code
# Plot a Tweedie distribution function
y <- seq(0.01, 4, length = 50)
Fy <- ptweedie_inversion(y, mu = 1, phi = 1, power = 1.1)
plot(y, Fy, type = "l", lwd = 2, ylab = "Distribution function")

Run the code above in your browser using DataLab