MATLAB: How can i estimate parameters of two independent gamma distributed variables with one same parameter in matlab

no tag

Suppose we have two independent random variables $X_1$ and $X_2$ where $X_1 \sim (\alpha_1, \beta)$ and $X_2 \sim (\alpha_2, \beta)$. how can i estimate three parameters $(\alpha_1, \alpha_2, \beta)$ from given data for $X_1$ and $X_2$?

Best Answer

I think one possible way to do this is to use maximum likelihood estimation method, like:
% Sample data
X1 = gamrnd(2,10,1000,1);
X2 = gamrnd(5,10,1000,1);
% Fit each data to Gamma distribution
pd1 = fitdist(X1,'Gamma');
pd2 = fitdist(X2,'Gamma');
% Assume beta = (beta1 + beta2)/2, and estimate alpha1 and alpha2
beta = (pd1.b + pd2.b)/2;
alpha1 = mle(X1,'pdf',@(X1,alpha1) gampdf(X1,alpha1,beta),'start',pd1.a);
alpha2 = mle(X2,'pdf',@(X2,alpha2) gampdf(X2,alpha2,beta),'start',pd2.a);