Simulate a random variable having piecewise gamma failure rate I am having trouble in simulating values for a random variable $X$ having a piecewise gamma failure rate:
$$ \lambda_X(t) =\lambda_1(t)1\!\!1_{\lbrace t\leq t_0 \rbrace} + \lambda_2(t)1\!\!1_{\lbrace t > t_0 \rbrace}$$
where $\lambda_1$ and $\lambda_2$ are the failure rates of two Gamma distributions $\Gamma(\alpha_1,\beta_1)$ and $\Gamma(\alpha_2,\beta_2)$ respectively. The value of $t_0$ and the parameters of Gamma distributions are known in advance.
Apparently the change point $t_0$ doesnot allow simulating two independant gamma random variables. Does anyone have a solution?
Thanks in advance.
 A: As a general rule, when given the failure rate$$\eta(t)=\frac{f(t)}{\int_t^\infty f(x)\,\text{d}x}=-\frac{\text{d}}{\text{d}t}\,\log \int_t^\infty f(x)\,\text{d}x$$we can formally derive$$\int_0^t\eta(x)\,\text{d}x=-\log \int_t^\infty f(x)\,\text{d}x$$since the value at $t=0$ is zero on both sides, and$$\exp\left\{-\int_0^t\eta(x)\,\text{d}x\right\}=1-\int_0^t f(x)\,\text{d}x$$which leads to the cdf$$F(t)=\int_0^t f(x)\,\text{d}x=1-\exp\left\{-\int_0^t\eta(x)\,\text{d}x\right\}$$From a simulation perspective, if we generate $U\sim\mathcal{U}(0,1)$, we have to solve $F(X)=U$, which means
$$1-\exp\left\{-\int_0^X\eta(x)\,\text{d}x\right\}=U$$or$$\int_0^X\eta(x)\,\text{d}x=-\log(1-U)$$
Now, when $\eta(x)=\lambda_1(x)\mathbb{I}_{x\le t_0}+\lambda_2(x)\mathbb{I}_{x>t_0}$, this means that 
$$F(x)=\cases{F_1(x) &when $x<t_0$\\
1-\{1-F_1(t_0)\}\dfrac{1-F_2(x)}{1-F_2(t_0)} &else}$$ where $F_1$ is the Gamma $G(\alpha_1,\beta_1)$ cdf and $F_2$ the Gamma $G(\alpha_2,\beta_2)$ cdf. Equivalently,
$$F(x)=\cases{F_1(t_0)\mathbb{P}(X_1\le x|X_1\le t_0) &when $x<t_0$\\
F_1(t_0)+\{1-F_1(t_0)\}\mathbb{P}(X_2\le x|X_2\ge t_0) &else}$$where $X_1$ and $X_2$ denote Gamma $G(\alpha_1,\beta_1)$ and Gamma $G(\alpha_2,\beta_2)$ random variables.

Conclusion
  This representation of the cdf establishes that the distribution with failure rate$$\eta(x)=\lambda_1(x)\mathbb{I}_{x\le t_0}+\lambda_2(x)\mathbb{I}_{x>t_0}$$is a
  mixture of a Gamma $G(\alpha_1,\beta_1)$ truncated to $(0,t_0)$ and of
  a Gamma $G(\alpha_2,\beta_2)$ truncated to $(t_0,\infty)$ with weights
  $F_1(t_0)$ and $(1-F_1(t_0))$.

In terms of random simulation this means


*

*pick the generating distribution Gamma $G(\alpha_1,\beta_1)$ truncated to $(0,t_0)$ with probability $F_1(t_0)$ and the generating distribution Gamma $G(\alpha_2,\beta_2)$ truncated to $(t_0,\infty)$ with probability $1-F_1(t_0)$

*Generate X from the picked truncated Gamma distribution

