I am trying to generate a set of random positive steps that will result in a final location that is close to what I would have gotten from taking a similar number of fixed steps$^1$. I would like the step size to be sampled from gamma distribution$^2$ that has a peak at the fixed step size. If I understand correctly, this means that I want a gamma distribution whose mode is equal to the median.
$$mode = (k − 1) \theta$$ $$median = \theta \gamma^{-1}(k, \frac{\Gamma(k)}{2})$$
Setting these equal to each other and taking $\gamma$ of both sides yields
$$2 \gamma(k, k - 1) = \Gamma(k)$$
Which can be reworked to
$$\gamma(k, k - 1) = \Gamma(k, k - 1)$$
Where $\gamma$ is the lower incomplete gamma, and $\Gamma$ is the upper incomplete gamma function.
There is no closed form solution for $k$ that I am aware of to this problem. Having played with the integrals for a bit, I am unsure how to proceed to find the shape parameter of my distribution that will ensure that the mode and median coincide (getting the scale $\theta$ from the shape is trivial of course).
I am perfectly OK with a numerical solution, but I am not sure how to obtain even that, using commonly defined functions$^3$.
In short, how do I find the shape parameter of a gamma function whose median is equal to its mode?
Related questions, that helped me visualize up to here:
- Determine the mode of the gamma distribution with parameters $\alpha$ and $\beta$
- How to find the mode and median of a Gamma distribution?
$^1$ I am doing this in Python + numpy, so I want a vector of random values x of size n such that np.cumsum(x) represents a sequence of motonically increasing x-values randomly disturbed from approximately np.linspace(x[0], x[-1], n).
$^2$ Implemented in np.random.gamma.
$^3$ In particular, scipy defines the regularized and non-regularized, complete and incomplete gammas and their inverses.
