# Distribution of conditional waiting time untill next event in a renewal process [duplicate]

Let $$J_n = \sum_{i=1}^n S_i$$ be a renewal process with gamma distributed interval times $$S_i \sim Gamma(\alpha,\beta)$$.

Consider the value $$J_k$$ of the first event when the process passes a certain point $$t_{boundary}$$.

What is the distribution of $$t = J_k - t_{boundary}$$? More specifically what is the distribution in the limit $$t_{boundary} \to \infty$$?

Example computation/simulation of the process and the distribution for $$S_i \sim Gamma(\alpha = 5,\beta = 20)$$ and $$t_{boundary} = 10$$

alpha = 5
beta = 20

sim = function(x = 10) {
t = 0
### untill t is above some boundary point
while(t<x) {
dt = rgamma(1,alpha,beta)
t = t+dt
}
return(t-x) ### return the difference with the boundary point
}

set.seed(1)
time = replicate(10^4,sim())
hist(time, freq = 0, breaks = seq(0,max(time)+0.2,0.05))


We can argue that the interval length of the last interval $$S_k$$ is distributed as $$f(t) \sim Gamma(\alpha+1,\beta)$$. That is, the $$\alpha$$ parameter is one more than for the unconditional distribution of interval times $$S$$. See for a motivation: Intuitive explanation of paradoxical interval times distribution

If the interval had size $$S_k$$, we can imagine the point $$t_{boundary}$$ to be uniform distributed within that interval. Then the distribution of $$t$$ is like a compound distribution

$$t \sim U(0,S_k) \\ S_k \sim Gamma(\alpha+1,\beta)$$

This is related to the integral

$$g(t) = \int_t^\infty \frac{1}{s} f(s,\alpha+1,\beta) ds$$ and we can express this in terms of the cumulative distribution of a Gamma distribution

$$g(t) = \frac{\beta}{\alpha} (1-F(t,\alpha,\beta))$$

Here is a code that adds this distribution to the histogram plot

ts = seq(0,max(time),0.01)
lines(ts,beta/alpha*(1-pgamma(ts,alpha,beta)))


More generally the solution is

$$g(t) = \frac{(1-F(t,\alpha,\beta))}{E[S]}$$