0
$\begingroup$

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:

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ You don't provide any quantitative basis for "modulating" the distribution of waiting times. One instructive approach is to think of the waiting times as corresponding to a time-inhomogeneous process, because that immediately inspires the idea that a dilation or shrinking of the time scale could accomplish what you want in a way that naturally generalizes the basic model. One way to implement this is to generate the original homogeneous process and then replace time $t$ by the cumulative "effective" time $s=\int^tf(t)\,\mathrm dt$ where $f(t)$ is the relative rate of time flow at $t.$ $\endgroup$
    – whuber
    Commented Dec 14, 2022 at 19:38
  • 1
    $\begingroup$ @whuber ah, that seems much easier to implement, thank you for the idea! $\endgroup$
    – salva
    Commented Dec 15, 2022 at 8:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.