Tweedie | R Documentation |

Density, distribution function, quantile function and random generation for the Tweedie family of distributions

dtweedie(y, xi=NULL, mu, phi, power=NULL) dtweedie.series(y, power, mu, phi) dtweedie.inversion(y, power, mu, phi, exact=TRUE, method) dtweedie.stable(y, power, mu, phi) ptweedie(q, xi=NULL, mu, phi, power=NULL) ptweedie.series(q, power, mu, phi) qtweedie(p, xi=NULL, mu, phi, power=NULL) rtweedie(n, xi=NULL, mu, phi, power=NULL)

`y, q` |
vector of quantiles |

`p` |
vector of probabilities |

`n` |
the number of observations |

`xi` |
the value of |

`power` |
a synonym for |

`mu` |
the mean |

`phi` |
the dispersion |

`exact` |
logical flag;
if |

`method` |
either |

The Tweedie family of distributions belong to the class
of exponential dispersion models (EDMs),
famous for their role in generalized linear models.
The Tweedie distributions are the EDMs with a variance of the form
*var(Y) = phi * mu^power*
where *power* is greater than or equal to one, or less than or equal to zero.
**This function only evaluates for power
greater than or equal to one.**
Special cases include the
normal (

`power`

,
the distributions are still defined but cannot be written in closed form,
and hence evaluation is very difficult.
When *1 < power < 2*,
the distribution are continuous for *Y* greater than zero,
with a positive mass at *Y=0*.
For *power > 2*,
the distributions are continuous for *Y* greater than zero.

This function evaluates the density or cumulative probability using one of two methods, depending on the combination of parameters. One method is the evaluation of an infinite series. The second interpolates some stored values computed from a Fourier inversion technique.

The function `dtweedie.inversion`

evaluates the density using a Fourier series technique;
`ptweedie.inversion`

does likewise for the cumulative
probabilities.
The actual code is contained in an external FORTRAN program.
Different code is used for *power > 2*
and for *1 < power < 2*.

The function `dtweedie.series`

evaluates the density
using a series expansion;
a different series expansion
is used for *power > 2* and for *1 < power < 2*.
The function `ptweedie.series`

does likewise for the
cumulative probabilities but only for *1 < power < 2*.

The function `dtweedie.stable`

exploits the link between
the stable distribution (Nolan, 1997) and Tweedie distributions,
as discussed in Jorgensen, Chapter 4.
These are computed using Nolan's algorithm as implemented
in the `stabledist`

package (which is therefore required to use
the `dtweedie.stable`

function).

The function `dtweedie`

uses a two-dimensional interpolation procedure to
compute the density for some parts of the parameter space from
previously computed values found from the series or the
inversion. For other parts of the parameter space,
the series solution is found.

`ptweedie`

returns either the computed series
solution or inversion solution.

density (`dtweedie`

),
probability (`ptweedie`

),
quantile (`qtweedie`

)
or random sample (`rtweedie`

)
for the given Tweedie distribution with parameters
`mu`

,
`phi`

and
`power`

.

The `method`

s changed from version 1.4 to 1.5
(methods 1 and 2 swapped).
The methods are defined in Dunn and Smyth (2008).

Peter Dunn (pdunn2@usc.edu.au)

Dunn, P. K. and Smyth, G. K. (2008).
Evaluation of Tweedie exponential dispersion model densities by Fourier inversion.
*Statistics and Computing*,
**18**, 73–86.
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.
doi: 10.1007/s11222-005-4070-y

Dunn, Peter K and Smyth, Gordon K (2001).
Tweedie family densities: methods of evaluation.
*Proceedings of the 16th International Workshop on Statistical Modelling*,
Odense, Denmark, 2–6 July

Jorgensen, B. (1987).
Exponential dispersion models.
*Journal of the Royal Statistical Society*, B,
**49**, 127–162.

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

Nolan, John P (1997).
Numerical calculation of stable densities and distribution functions.
*Communication in Statistics—Stochastic models*,
**13**(4). 759–774.
doi: 10.1080/15326349708807450

Sidi, Avram (1982).
The numerical evaluation of very oscillatory infinite integrals by
extrapolation.
*Mathematics of Computation*
**38**(158), 517–529.
doi: 10.1090/S0025-5718-1982-0645667-5

Sidi, Avram (1988).
A user-friendly extrapolation method for
oscillatory infinite integrals.
*Mathematics of Computation*
**51**(183), 249–266.
doi: 10.1090/S0025-5718-1988-0942153-5

Tweedie, M. C. K. (1984).
An index which distinguishes between some important exponential families.
*Statistics: Applications and New Directions.
Proceedings of the Indian Statistical Institute Golden Jubilee International Conference*
(Eds. J. K. Ghosh and J. Roy), pp. 579-604. Calcutta: Indian Statistical Institute.

`dtweedie.saddle`

### Plot a Tweedie density power <- 2.5 mu <- 1 phi <- 1 y <- seq(0, 6, length=500) fy <- dtweedie( y=y, power=power, mu=mu, phi=phi) plot(y, fy, type="l", lwd=2, ylab="Density") # Compare to the saddlepoint density f.saddle <- dtweedie.saddle( y=y, power=power, mu=mu, phi=phi) lines( y, f.saddle, col=2 ) legend("topright", col=c(1,2), lwd=c(2,1), legend=c("Actual","Saddlepoint") ) ### A histogram of Tweedie random numbers hist( rtweedie( 1000, power=1.2, mu=1, phi=1) ) ### An example of the multimodal feature of the Tweedie ### family with power near 1 (from Dunn and Smyth, 2005). y <- seq(0.001,2,len=1000) mu <- 1 phi <- 0.1 p <- 1.02 f1 <- dtweedie(y,mu=mu,phi=phi,power=p) plot(y, f1, type="l", xlab="y", ylab="Density") p <- 1.05 f2<- dtweedie(y,mu=mu,phi=phi,power=p) lines(y,f2, col=2) ### Compare series and saddlepoint methods y <- seq(0.001,2,len=1000) mu <- 1 phi <- 0.1 p <- 1.02 f.series <- dtweedie.series( y,mu=mu,phi=phi,power=p ) f.saddle <- dtweedie.saddle( y,mu=mu,phi=phi,power=p ) f.all <- c( f.series, f.saddle ) plot( range(f.all) ~ range( y ), xlab="y", ylab="Density", type="n") lines( f.series ~ y, lty=1, col=1) lines( f.saddle ~ y, lty=3, col=3) legend("topright", lty=c(1,3), col=c(1,3), legend=c("Series","Saddlepoint") )

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.