I'm look at the following integral:
$$\int_{0}^p x^2 f(x,\alpha, \beta) dx $$
where $f(x, \alpha, \beta)$ is the pdf of the Gamma distribution is expressed as:
$$\frac{x^{\alpha-1}e^{-\beta x}\beta^\alpha}{\Gamma(\alpha)}$$
Now if I would multiply the integral with the fraction $\frac{\beta^2}{\alpha^2}$, wouldn't this be equal to the cdf of the Gamma distribution evaluated at $p$ with $\alpha+2$ ?:
$$\frac{\beta^2}{\alpha^2}\int_{0}^p x^2 f(x, \alpha, \beta) dx = F(p, \alpha+2, \beta)$$
, where $F(x)$ represents the cdf of the Gamma distribution evaluated at $x$.
I use the fact that $\Gamma(\alpha+1) = \alpha\Gamma(\alpha)$
But when I evaluate this in Python (with Scipy):
func = lambda x: x**2*gamma.pdf(x, a=alpha, scale=1/beta)
first_int = quad(func, 0, p)[0]*(beta**2/alpha**2)
cdf = gamma.cdf(p, a=alpha+2, scale=1/beta)
I can see this equation does not hold.
I'm obviously missing something, so if someone could point this out, that'd be great.
It appears that the pdf and cdf of the gamma distribution are defined as: \begin{align} \text{pdf} &= \frac{\beta^{\alpha}}{\Gamma(\alpha)} \, e^{- \beta \, x} \, x^{\alpha - 1} \\ \text{cdf} &= \frac{1}{\Gamma(\alpha)} \, \gamma(\alpha, \beta \, x). \end{align} The integral in question is $$ I = \frac{\beta^2}{\alpha^2} \, \int_{0}^{p} x^2 \, \frac{\beta^{\alpha}}{\Gamma(\alpha)} \, e^{- \beta \, x} \, x^{\alpha - 1} \, dx $$ which leads to \begin{align} I &= \frac{\beta^2}{\alpha^2} \, \int_{0}^{p} x^2 \, \frac{\beta^{\alpha}}{\Gamma(\alpha)} \, e^{- \beta \, x} \, x^{\alpha - 1} \, dx \\ &= \frac{\beta^{\alpha +2}}{\alpha^2 \, \Gamma(\alpha)} \, \int_{0}^{p} e^{- \beta \, x} \, x^{\alpha+1} \, dx \\ &= \frac{\beta^{\alpha +2}}{\alpha^2 \, \Gamma(\alpha)} \, \int_{0}^{p/\beta} e^{-u} \, \left(\frac{u}{\beta}\right)^{\alpha+1} \, \frac{du}{\beta} \\ &= \frac{1}{\alpha^2 \, \Gamma(\alpha)} \, \gamma\left(\alpha + 2, \frac{p}{\beta}\right) \\ &= \frac{1}{\alpha^2} \, \frac{1}{\Gamma(\alpha)} \, \gamma\left(\alpha+2, \beta \, \left(\frac{p}{\beta^2}\right) \right) \end{align}