Fitting a double exponential cumulative distribution function

11 views (last 30 days)
Hello,
I have an empirical probability distribution function (PDF) that fits best to a double exponential, i.e. by specifying exp2 in the fit function:
a*exp(b*x) + c*exp(d*x)
However, I want to ensure that this is also true without binning, so I want to use an exponential cumulative distribution function (CDF).
So, I construct a CDF like this:
[p,x]=ecdf(x);
Now I want to fit a double CDF to this. For fitting to a double CDF, it seems like I could fit the double CDF with cftool, but I'd rather use the fit function as it needs to be automated. So does anyone know a) if I can specify a custom equation with the fit function and b) what the equation for a double exponential CDF would look like?
Thank you!

Accepted Answer

Tom Lane
Tom Lane on 22 Mar 2012
You can do most things like this by writing a pdf and calling mle:
>> x = [exprnd(1,1000,1); exprnd(5,2000,1)];
>> pdf = @(x,p,a,b) (p)*exppdf(x,a) + (1-p)*exppdf(x,b)
>> mle(x,'pdf',pdf,'start',[.5,2,3])
ans =
0.31645 0.96406 4.8809
I was lucky that I got an estimate satisfying 0<p<1. If I didn't, I'd have to choose a parametrization to prevent that.
  1 Comment
Grant
Grant on 22 Mar 2012
Thank you. Though I must say, I'm surprised at the lack of multimodal functions in dfittool...

Sign in to comment.

More Answers (1)

Peter Perkins
Peter Perkins on 22 Mar 2012
Grant, can I suggest that you take a look at
before going too much further? It may be that you want dfittool, not cftool.
  1 Comment
Grant
Grant on 22 Mar 2012
Peter, thank you for the informative article. I have indeed been misusing cftool/fit to fit PDFs!
The problem now is that I don't see an option in dfittool to add a custom equation, i.e. if I display as CDF I only see the option for a single exponential. In fact, I would have a similar problem trying to fit data with e.g. more than one gaussian.... so, how to do this? The "distribution reference" > "custom distributions" doc says only:
"User-defined custom distributions, created using files and function handles, are supported by the Statistics Toolbox functions pdf, cdf, icdf, and mle, and the Statistics Toolbox GUI dfittool."
... but does not tell me how. Advice appreciated!

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!