Hello,
I’d like to model insurance pure premium which is usually known to have a tweedie distribution. Has any of you pymc3-ers ever developed a custom tweedie distribution to sample from?
Update: I found a comparable function for a tweedie distribution (see below). How would I actually use this function as a sampling method like pm.Normal/pm.StudentT/etc.?
def
tweedie(n,p,mu,phi):
np.random.seed(seed
=
32
)
#checking the value of variance power between 1-2
if
(p
=
2
):
(
'p must be between (1,2)'
)
pass
else
:
rt
=
np.full(n,np.nan)
# calculating mean of poisson distribution
lambdaa
=
mu
*
*
(
2
-
p)
/
(phi
*
(
2
-
p))
# shape parameter of gamma distribution
alpha
=
(
2
-
p)
/
(
1
-
p)
# scale parameter of gamma distribution
gam
=
phi
*
(p
-
1
)
*
(mu
*
*
(p
-
1
))
# Generating Poisson random sample
N
=
np.random.poisson(lambdaa,n)
for
i
in
range
(n):
# Generate single data point of gamma distribution using poisson random variable
rt[i]
=
np.random.gamma(N[i]
*
np.
abs
(alpha),gam,
1
)
return
(rt)