Search code examples
matlabdistributiongamma-distribution

How can we find percentile or quantile of gamma distribution in MATLAB?


Suppose that we have this gamma distribution in MATLAB:

enter image description here

I want this part of distribution with higher density (x-axis range). How can I extract this in MATLAB? I fit this distribution using histfit function.

enter image description here

PS. My codes:

figure;
histfit(Data,20,'gamma');
    [phat, pci] = gamfit(Data);

phat =

   11.3360    4.2276

pci =

    8.4434    3.1281
   15.2196    5.7136

Solution

  • When you fit a gamma distribution to your data with [phat, pci] = gamfit(Data);, phat contains the MLE parameters. You can plug this into gaminv:

    x = gaminv(p, phat(1), phat(2));
    

    where p is a vector of percentages, e.g. p = [.2, .8].