Regarding the PDF and CDF of two gamma distributed random varaibles!!

If X ~ gamma (m, p) with a shape parameter m and a scale parameter p and Y~ gamma (m, q) with a shape parameter m and a scale parameter q when X and Y are independent random variables then What will be the PDF and CDF of X+Y? How can I solve it in MatLab
Thanks in advance for help

 Accepted Answer

The density function for X+Y is given by
f_X+Y(z)=exp(-q*z)*p^(2*m)/(gamma(m))^2*integral_{x=0}^{x=z}(x*(z-x))^(m-1)*exp(-(p-q)*x) dx
Use MATLAB's "integral" to evaluate the integral for different values of z.
Best wishes
Torsten.

10 Comments

Thanks for the answer. Is this pdf or CDF (Specially I need CDF)? Is it the "int" or "integral" function in the matlab? Can you please tell me MatLab code for example, m=1, p=1, q=1, z=0.2, using symbolic variable.
Sorry for your inconvenience.
Thanks in advance again
Does this work ?
m=1;
p=1;
q=1;
z1=0.2;
z2=3;
% Compute PDF at z1
fun1=@(x)(x.*(z1-x)).^(m-1).*exp(-(p-q)*x);
PDF = exp(-q*z1)*p^(2*m)/gamma(m)^2*integral(fun1,0,z1);
% Compute CDF at z2
fun2=@(x,z)exp(-q*z).*(x.*(z-x)).^(m-1).*exp(-(p-q)*x);
CDF = p^(2*m)/gamma(m)^2*integral2(fun2,0,@(z)z,0,z2);
Best wishes
Torsten.
Thanks for your answer. For pdf, I am getting a numerical value. But for CDF there is an error like as
Try
fun2=@(z,x)exp(-q*z).*(x.*(z-x)).^(m-1).*exp(-(p-q)*x);
CDF = p^(2*m)/gamma(m)^2*integral2(fun2,0,z2,0,@(z)z);
Best wishes
Torsten.
Thanks a lot. I am really grateful to you
I am really grateful to you for my previous answers. Can you please help me one more time?
If Xi (i=0,1..) ~ gamma (m, p) with a shape parameter m and a scale parameter p and X are independent random variables then What will be the PDF and CDF of sum(X)? How can I solve it in MatLab? i.e, PDF and CDF of the sum of two gamma random variables with same shape and scale parameter. You can add this one with the previous answers.
Little correction to my code:
m=1;
p=1;
q=1;
z1=0.2;
z2=3;
% Compute PDF at z1
fun1=@(x)(x.*(z1-x)).^(m-1).*exp(-(p-q)*x);
PDF = exp(-q*z1)*(p*q)^m/(gamma(m))^2*integral(fun1,0,z1);
% Compute CDF at z2
fun2=@(z,x)exp(-q*z).*(x.*(z-x)).^(m-1).*exp(-(p-q)*x);
CDF = (p*q)^m/(gamma(m))^2*integral2(fun2,0,z2,0,@(z)z);
Best wishes
Torsten.
But for me X1=gamma(a,m) and X2=gamma(a,m), then what will be the pdf and cdf of
X0+X1 ~ gamma(2*a,m)
In general:
X0+X1+...+Xn ~ Gamma((n+1)*a,m)
To calculate pdf and cdf, use gampdf and gamcdf.
Best wishes
Torsten.

Sign in to comment.

More Answers (1)

This is a math or stats question, not a MATLAB question. But, you made me curious.
The answer is not trivial. This paper gives a solution. This post on another forum gives an explanation (and references the paper I just mentioned).

Tags

Asked:

on 14 Jan 2016

Commented:

on 18 Jan 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!