Does anyone know how to create a custom distribution?
Show older comments
the thing is, i want to define a custom distribution in statistic toolbox,the custom distribution is like this pdf = (1-p)*normalpdf +p*exppdf, it's a combination of two distribution.
there is an example from matlab,it's laplace distrbution, but i want a combination of two distributions.it's hard for me . Could someone give me an idea ?
Answers (2)
Image Analyst
on 27 Jan 2013
0 votes
Try this link: http://www.mathworks.com/matlabcentral/fileexchange/7309-randraw. It has numerous distributions, along with source code so you can see how it's done.
Tom Lane
on 27 Jan 2013
You have a four-parameter distribution with density
(1-p)*normpdf(x,mu,sigma) + p*exppdf(x,lambda)
and with a cdf that is similarly a linear combination of normcdf and expcdf. You can generate random numbers from it by take the normal value with probability (1-p) and the exponential value with probability p. The inversecdf is trickier but you might find fzero to be helpful:
>> p = .6; mu = 0; sigma = 1; lambda = 3;
>> mycdf = @(x) (1-p)*normcdf(x,mu,sigma) + p*expcdf(x,lambda);
>> mycdf(1.5)
ans =
0.6094
>> fzero(@(y) mycdf(y)-.6094,1)
ans =
1.5002
1 Comment
jeff himmel
on 28 Jan 2013
Categories
Find more on Exponential Distribution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!