Clear Filters
Clear Filters

distributionFitter: What is the best fit for my data?

4 views (last 30 days)
Hi;
I used the distributionFitter tool to find the best fit to my data.
I am wondering how can I judge the goodness of the fit based on the distributionFitter outcomes?
Thank you in advance.

Accepted Answer

Drew
Drew on 16 Nov 2023
In the "Results" section of each "Edit Fit" window, the second line "Log likelihood" is one indication of the goodness of fit. In general, higher values of log likelihood (that is, closer to zero, since all log-likelihood values are negative) indicate a better fit to the data. However, it can be helpful to examine other metrics as well.
To visually examine the goodness of fit, compare the plots in the main Distribution Fitter window. For goodness-of-fit assessment, it can be helpful to examine the "Cumulative probability (CDF)" plot.
For additional quantitative goodness-of-fit metrics, one approach is to take these steps:
(1) Generate code from distribution fitter (find this option under "File --> Generate Code")
(2) Use the generated code to re-calculate all the distribution objects. (One could alternately export the fit objects from the "Fit Manager" window, but export happens one-fit-at-a-time, so that takes longer).
(3) Use tests such as the Kolmogorov-Smirnov test (kstest) and chi-squared goodness-of-fit (chi2gof) test to evaluate the goodness-of-fit.
One can use the MATLAB doc pages, or the MathWorks AI Chat Playground (https://www.mathworks.com/matlabcentral/playground/new) to help witih generating code to calculate the kstest and chi2gof. For example, here is some code generated to evaluate how well pd1 (normal distribution) and pd2 (Weibull distribution) fit the data in vector MPG, using the Kolmogorov-Smirnov test.
% Perform Kolmogorov-Smirnov test for normal distribution
[h1, p1, ksstat1] = kstest(MPG, 'CDF', pd1);
fprintf('Kolmogorov-Smirnov test for normal distribution:\n')
fprintf('h = %d, p = %f, ksstat = %f\n', h1, p1, ksstat1)
% Perform Kolmogorov-Smirnov test for Weibull distribution
[h2, p2, ksstat2] = kstest(MPG, 'CDF', pd2);
fprintf('Kolmogorov-Smirnov test for Weibull distribution:\n')
fprintf('h = %d, p = %f, ksstat = %f\n', h2, p2, ksstat2)
If this answer helps you, please remember to accept the answer.

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!