生成服从Tweedie分布的随机数

• Tweedie分布介绍：随机变量是N个服从Gamma分布的数值的和。其中N服从泊松分布。

Tweedie分布会以一定的概率生成数值为0的样本。因此Tweedie分布也适合理赔的建模。

R base package "stat"不包含Tweedie这个分布。但是有一个R包可以帮助我们 -- tweedie

安装好后用下面的函数就可以了：

library(tweedie)
set.seed(987654)
y <- rtweedie( 20, xi = 1.5, mu = 1, phi = 1)


语法是

rtweedie(n, xi=NULL, mu, phi, power=NULL)


其中xi和power必须要有一个。

• 参数定义：

• y, q
vector of quantiles

• p
vector of probabilities

• n
the number of observations

• xi
the value of xi such that the variance is var(Y) = phi * mu^xi

• power
a synonym for xi

• mu
the mean

• phi
the dispersion

• exact
logical flag; if TRUE (the default), exact zeros are used with the W-algorithm of Sidi (1982); if FALSE, approximate (asymptotic) zeros are used in place of exact zeros. Using asymptotic zeros requires less computation but is often less accurate; using exact zeros can be slower but generally improves accuracy.

• method
either 1, 2 or 3, determining which of three methods to use to compute the density using the inversion method. If method is NULL (the default), the optimal method (in terms of relative accuracy) is used, element-by-element of y. See the Note in the Details section below