fitdist should be pdf^-1 but is seems not to return correctly

1 view (last 30 days)
Niv Yonat
Niv Yonat on 13 Oct 2021
Answered: John D'Errico on 13 Oct 2021
y1 = lognpdf(x1,mu,sigma)
pd = fitdist(y1.','Lognormal')
% pd<> y1

Accepted Answer

John D'Errico
John D'Errico on 13 Oct 2021
The problem is, you do not understand that evaluating the PDF is NOT the same thing as sampling random numbers from that distribution. This is frequently misunderstod. And yes, the PDF tends to look a lot like the samples you would generate.
fitdist applies to a sample from that ditribution. It is NOT used to fit to values generated from the PDF itself though. (A course in probability and statistics would help, or do some reading.)
But here is an example. I'll use a large sample, so the plot will look good.
X = lognrnd(0,1,10000,1);
And that sampling of numbers does look like the PDF itself. Now use fitdist.
D = fitdist(X,'lognormal')
D =
LognormalDistribution Lognormal distribution mu = 0.00222268 [-0.017614, 0.0220593] sigma = 1.01197 [0.998137, 1.02619]
And we see a lognormal distribution has been estimated. The parameters are pretty close to what we used to create the sample, but with a sample size of 10000 points, that is to be expected.
Again, some reading would be of use to you. Spend some time understanding what a PDF is, what is the CDF, and how do you generate a random sampling from them, using tools like lognrnd, as well as how you can use tools like fitdist.

More Answers (0)





Community Treasure Hunt

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

Start Hunting!