I am modeling a process where events happen every X
days with X
following a gamma distribution. I already have a model for that which works relatively well.
The issue now, is that the day of the week also has an effect on X, and so, in order to improve the model, I would like to use a probability distribution like p(x) = k * gamma(x, alpha, theta) * w[weekday(x)]
where w
is a vector of 7 coefficients to be determined (one for every day of the week) and k
is a constant so that p(x)
integrates to 1. In other words, I want to modulate the gamma
distribution but I have no idea how to do that and have not been able to find in the Stan documentation anything related either.
So, any idea about how to proceed here?
Update: well, I am currently playing with the idea of using a gamma
modulated by a Fourier series (somehow).
I have come to the following density distribution with is the result of using a 4th order Fourier serie (sorry for the ugly format, I have generated it in Maple and don't know how to convert it into MathJax):
p(x, alpha, beta, lambda, k__0, k__1, k__2, k__3, d__1, d__2, d__3) =
k__0*beta^alpha*x^(alpha - 1)*exp(-beta*x)/GAMMA(alpha) +
k__1*x^(alpha - 1)*exp(-beta*x)*(1 + sin(lambda*x + d__1))*beta^alpha/(GAMMA(alpha)*((beta^2 + lambda^2)^(-alpha/2)*sin(d__1 + arccot(beta/lambda)*alpha)*beta^alpha + 1)) +
k__2*x^(alpha - 1)*exp(-beta*x)*(1 + sin(2*lambda*x + d__2))*beta^alpha/(GAMMA(alpha)*((beta^2 + 4*lambda^2)^(-alpha/2)*sin(d__2 + arccot(beta/(2*lambda))*alpha)*beta^alpha + 1)) +
k__3*x^(alpha - 1)*exp(-beta*x)*(1 + sin(3*lambda*x + d__3))*beta^alpha/(GAMMA(alpha)*((beta^2 + 9*lambda^2)^(-alpha/2)*sin(d__3 + arccot(beta/(3*lambda))*alpha)*beta^alpha + 1))
The components are parametrized by an amplitude ($k_0$, $k_1$, $k_2$ and $k_4$) and a phase ($d_1$, $d_2$ and $d_3$) with $\Sigma k_i = 1$ (I have found I can set that restriction in Stan using the Unit Simplex)
Now, let's see if I am able to build that distribution on Stan as explained here and to make everything work together!
The following graph shows the fourth components of the density function: