fitdist should be pdf^-1 but is seems not to return correctly
1 view (last 30 days)
Show older comments
x1=[.1:.1:100];
y1 = lognpdf(x1,mu,sigma)
median(y1)
mean(y1)
std(y1)
pd = fitdist(y1.','Lognormal')
% pd<> y1
0 Comments
Accepted Answer
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);
histogram(X)
And that sampling of numbers does look like the PDF itself. Now use fitdist.
D = fitdist(X,'lognormal')
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.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!