I saw this question https://stats.stackexchange.com/a/518651/403725 where the distribution of "gambler ruin times" is derived (Discrete Phase Type Distribution):
$$\mathbb{P}(T=t) = w_0 \cdot \frac{(t - 1)!}{(\tfrac{t+w_0}{2})! (\tfrac{t-w_0}{2})!} \cdot \frac{1}{2^t}.$$
I am interested in learning how random ruin times from this distribution can be simulated in R. As an example, suppose $w_0=6$
I first thought we can use the Probability Integral Transform method:
$$Y = F_X(X)$$ $$X = F_X^{-1}(Y)$$
where:
- $X$ is a continuous random variable,
- $F_X$ is the cumulative distribution function of $X$, and
- $Y$ is a random variable that follows a standard uniform distribution.
As an example of this for the Exponential Distribution (pdf, cdf, inverse cdf) - $X$ is a random number from the exponential distribution and $U$ is Uniform(0,1):
$$f(x;\lambda) = \lambda e^{-\lambda x} \quad \text{for } x \geq 0$$
$$F(x;\lambda) = 1 - e^{-\lambda x} \quad \text{for } x \geq 0$$
$$F^{-1}(y;\lambda) = -\frac{\log(1-y)}{\lambda} \quad \text{for } 0 \leq y < 1$$
$$X = F^{-1}(U;\lambda) = -\frac{\log(1-U)}{\lambda}$$
But in the case of Gamblers Ruin, I am not sure how to work with the CDF of this distribution as it involves summation terms with large factorials:
$$F_T(t) = P(T \leq t) = \sum_{k=0}^{t} P(T=k)$$ $$F_T(t) = \sum_{k=0}^{t} w_0 \cdot \frac{(k - 1)!}{(\tfrac{k+w_0}{2})! (\tfrac{k-w_0}{2})!} \cdot \frac{1}{2^k}$$
I thought maybe we could use some sampling algorithm like Acceptance-Rejection?
- Generate a sample $x$ from a proposal distribution that has a density proportional to a function $g(x)$, where $g(x) \geq f(x)$ for all $x$. Here, $f(x)$ is the density of the target distribution.
- Generate a uniform random number $u$ between 0 and 1.
- If $u > \frac{f(x)}{g(x)}$, reject the sample $x$ and return to step 1; otherwise, accept $x$ as a sample from the target distribution.
So in the case of Gamblers Ruin time, I thought I can do this (e.g. suppose times are between 0 and 100, I can use $g(t)=1/100$:
- Generate a proposal sample $t$ from the uniform distribution on the interval $[1, 100]$.
- Calculate acceptance probability $a = \frac{\mathbb{P}(T=t)}{g(t)}$.
- Generate a uniform random number $u$ between 0 and 1.
- If $u \leq a$, accept $t$ as a sample from the target distribution; otherwise, reject $t$ and return to step 1.
Is this approach correct? If so, I am currently working on R code for this and can post my results.
Rcode applied to a problem just like this one, see https://stats.stackexchange.com/a/608790/919. But doesn't the thread you reference already answer your question? I seeRcode there. – whuber Jan 12 '24 at 14:31