Thread Subject: fitting a Gamma cdf to my data

Subject: fitting a Gamma cdf to my data

From: Mohammad Monfared

Date: 7 Oct, 2008 19:46:01

Message: 1 of 4

I'm interested in fitting a Gamma cdf to my data which looks like:
particle_size=[2 50 ... 2000]
particle_fraction=[0.08 0.2 ... 1]

how can I do this jos?
thanks,
Reza

Subject: fitting a Gamma cdf to my data

From: Tom Lane

Date: 8 Oct, 2008 19:49:24

Message: 2 of 4

> I'm interested in fitting a Gamma cdf to my data which looks like:
> particle_size=[2 50 ... 2000]
> particle_fraction=[0.08 0.2 ... 1]

 Reza, the following demo contains a section showing one way to fit a gamma
distribution:

http://www.mathworks.com/products/statistics/demos.html?file=/products/demos/shipping/stats/cdffitdemo.html

The point of this demo is to offer an alternative to maximum likelihood
estimation, especially in cases where mle doesn't work.

If the variables you describe above are just a summary of some other data,
and if you can get at that other data, I recommend you do that instead.
Then you can use gamfit to get the maximum likelihood estimates.

Even if you can't get raw data, you could maximize the likelihood based on
this summary data. Here's an example, where I generate some gamma data but
retain only bin centers and cumulative frequencies. I can use fminsearch to
mimimize the negative log likelihood weighted by the frequencies. The blue
things are the raw data and a fit based on them, the red things are the
binned data and a fit based on the bin frequencies.

% Raw data with fit
x = gamrnd(2,100,100,1);
p1 = gamfit(x)

% Summary data with fit
[n,c] = hist(x); % c = rounded data
F = cumsum(n/sum(n)); % F = cumulative proportions
f = diff([0,F]); % f = proportions
p2 = fminsearch(@(ab) -sum(f.*log(gampdf(c,ab(1),ab(2)))),[1,mean(c)])

% How does it look?
ecdf(x); line(xx,gamcdf(xx,p1(1),p1(2)),'linestyle',':')
hold on; set(stairs(c,F),'color','r'); hold off
line(xx,gamcdf(xx,p2(1),p2(2)),'color','r','linestyle',':')

This doesn't give you any measures of uncertainty for the estimates. But
I'm not sure how I'd compute those anyway, given that you don't seem to have
a notion of a "sample size" in your example.

-- Tom

Subject: fitting a Gamma cdf to my data

From: aasim Azooz

Date: 9 Oct, 2008 13:53:14

Message: 3 of 4

"Mohammad Monfared" <gohardoust@gmail.com> wrote in message <gcge9p$sfv$1@fred.mathworks.com>...
> I'm interested in fitting a Gamma cdf to my data which looks like:
> particle_size=[2 50 ... 2000]
> particle_fraction=[0.08 0.2 ... 1]
>
> how can I do this jos?
> thanks,
> Reza

Dear Reza
Can you tell me what do you mean by cdf? is it a Gamma function of some type I may help you
Aasim Azooz

Subject: fitting a Gamma cdf to my data

From: Mohammad Monfared

Date: 9 Oct, 2008 21:33:01

Message: 4 of 4

"aasim Azooz" <aasimazooz@yahoo.com> wrote in message <gcl2c9$i8$1@fred.mathworks.com>...
>
> Dear Reza
> Can you tell me what do you mean by cdf? is it a Gamma function of some type I may help you
> Aasim Azooz

Hi,
cdf is for Cumulative Density Function.
my data are about soil particle size and their fraction in a sample. for a soil sample, I have:

p_size=[2 50 106 250 500 1000 2000]
p_fraction=[0.0300 0.1700 0.2790 0.7350 0.9210 0.9940 1.0020]

which says e.g. 27.90% of our soil particles size is less than 106. I don't know how to prepare them for 'gamfit' function (if possible).
as a graph:
stairs([0 p_size],[p_fraction 1.0020])

And thanks Tom, for your explanatory answer!
thanks again,
Reza,

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com