Usage of chi2gof: how to derive the "expected" values from the fitting distribution to then use them as argument of chi2gof?
6 ビュー (過去 30 日間)
古いコメントを表示
How to derive the "expected" values from the fitting distribution to then use them as argument of chi2gof?
observed_data = exprnd(2, 100, 1);
xgrid = linspace(0,100,1000)';
pd = fitdist(observed_data,'Exponential'); % <-- fitting distribution
hold on
line(xgrid,pdf(pd,xgrid),'Linewidth',2,'color','b')
histogram(observed_data,100,'Normalization','pdf','facecolor','blue')
hold off
% Desired output
% [h, p] = chi2gof(observed_data, 'Expected', expected_counts)
0 件のコメント
採用された回答
Aman
2023 年 6 月 21 日
Hi Sim,
To generate the expected counts from a fitted distribution, you can use the probability density function (PDF) of the fitted distribution to generate the expected values for each bin.
Here's an example for the same,
observed_data = exprnd(2, 100, 1);
pd = fitdist(observed_data,'Exponential');
num_bins = 10;
bin_edges = linspace(min(observed_data), max(observed_data), num_bins+1);
expected_values = numel(observed_data) * diff(cdf(pd,bin_edges));
% since the area of the pdf must be 1, it is better to obtain the expected_counts by multiplying with the total number of observations accumulated on every single bin
expected_counts = expected_values * numel(observed_data);
[h, p] = chi2gof(observed_data, 'Expected', expected_counts);
Hope this helps!
3 件のコメント
Aman
2023 年 6 月 22 日
Hi Sim, Yes, sorry for confusion, that was for PDF, but we needed CDF, so I think expected_values should be used.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!