The probability density of the sum of gamma and uniform variables is the convolution of their densities, as it was for the sum of Gaussian and uniform variables, which we considered in a previous post. As before I'll define a simplifying unit boxcar function and a general boxcar to represent the uniform density.

Let's let h be the density of a gamma variable, with parameters a and b.

⇒ | $h(x,a,b):=\left(\frac{{b}^{a}}{\Gamma \left(a\right)}{x}^{a-1}\mathrm{exp}\left(\left(-b\right)x\right)\right)$ |

Here's the convolution integral. I'll quote the density functions to make the structure more obvious and therefore make further manipulation easier.

⇒ | ${\int}_{-\infty}^{r}h(r-s,{a}_{1},{b}_{1})U(s,{a}_{2},{b}_{2})ds$ |

As in a previous blog post, I'll define some simplification rules in order to manipulate the integral to the point that Maxima's built-in integrate function can handle it. There's a slightly obscure strategem in the definition of the second rule. yy_minus_xx is assigned before turning off the simplification flag, since it is important that the rule match the simplified form of y - x, which is internally represented as y + (-1)*x.

Now let's allow Maxima to apply the rules we just defined. The effect of quote-quote is just as if we just typed in the value of I.

⇒ | $\frac{{\int}_{{a}_{2}}^{\mathrm{min}({b}_{2},r)}h(r-s,{a}_{1},{b}_{1})ds}{{b}_{2}-{a}_{2}}$ |

I originally defined the integral with h quoted in the integrand. Let's verbify it.

⇒ | $\frac{{b}_{1}^{{a}_{1}}{\int}_{{a}_{2}}^{\mathrm{min}({b}_{2},r)}{\left(r-s\right)}^{{a}_{1}-1}{e}^{-{b}_{1}\left(r-s\right)}ds}{\left({b}_{2}-{a}_{2}\right)\Gamma \left({a}_{1}\right)}$ |

I'll make a change of variables from r - s to u which simplifies the integrand somewhat.

⇒ | $-\frac{{b}_{1}^{{a}_{1}}{\int}_{r-{a}_{2}}^{r-\mathrm{min}({b}_{2},r)}{u}^{{a}_{1}-1}{e}^{-{b}_{1}u}du}{\left({b}_{2}-{a}_{2}\right)\Gamma \left({a}_{1}\right)}$ |

Now we're ready to evaluate the integral. I'll assert some inequalities to forestall questions from 'integrate'. These are all necessary conditions for the definition of the gamma and uniform density functions.

⇒ | $-\frac{{b}_{1}^{{a}_{1}}\left(\frac{\Gamma ({a}_{1},{b}_{1}r-{b}_{1}{a}_{2})}{{b}_{1}^{{a}_{1}}}-\frac{\Gamma ({a}_{1},{b}_{1}r-{b}_{1}\mathrm{min}({b}_{2},r))}{{b}_{1}^{{a}_{1}}}\right)}{\left({b}_{2}-{a}_{2}\right)\Gamma \left({a}_{1}\right)}$ |

Terrific, now we have computed the convolution symbolically. Note the gamma function, Γ(a), and the upper incomplete gamma function, Γ(a, z), in the result. We'll take a look at a specific example, as given by specific values for the parameters.

⇒ | $-\frac{{2}^{\frac{1}{4}}\Gamma (\frac{1}{4},\frac{r}{2}-\frac{5}{2})-{2}^{\frac{1}{4}}\Gamma (\frac{1}{4},\frac{r}{2}-\frac{\mathrm{min}(12,r)}{2})}{7{2}^{\frac{1}{4}}\Gamma \left(\frac{1}{4}\right)}$ |

Let's define a function which has those parameter values baked in, and plot it.

It's interesting that the convolution function is asymmetric. I guess that's not surprising, since the gamma density is asymmetric too. Well, that's all for now.