Rebuild PDFs from original data
Show older comments
Hello,
I have two histograms for two classes data (class1 and class2) and I want to create for each class a Chi2 distribution that represents the original data.
So how and what I should extract from the original data (mean, std, variance, ......) to build my two Chi2 distributions ?
Thanks.
load('data.mat')
histogram(class1)
hold on
histogram(class2)
Answers (1)
Star Strider
on 1 May 2021
The
is not an option for histfit or the others, however calculating the parameters is straightforward —
LD = load('data.mat');
class1 = LD.class1;
class2 = LD.class2;
figure
subplot(2,1,1)
histogram(class1,1000, 'DisplayStyle','stairs')
xlabel('Bin')
ylabel('Count')
xlim([0 1])
title('Class 1')
[muest1,sdest1] = normfit(class1);
text(0.5,max(ylim), sprintf('\\mu = %.3f\n\\sigma = %.3f',muest1,sdest1), 'Horiz','left', 'Vert','top')
grid
subplot(2,1,2)
histogram(class2,1000, 'DisplayStyle','stairs')
xlabel('Bin')
ylabel('Count')
xlim([0 1])
title('Class 2')
[muest2,sdest2] = normfit(class2);
text(0.5,max(ylim), sprintf('\\mu = %.3f\n\\sigma = %.3f',muest2,sdest2), 'Horiz','left', 'Vert','top')
grid
.
4 Comments
Khoder Makkawi
on 1 May 2021
Star Strider
on 1 May 2021
This is the best I can do with your data —
figure
subplot(2,1,1)
[h1,stats1] = cdfplot(class1);
xv1 = h1.XData(isfinite(h1.XData));
yv1 = h1.YData(isfinite(h1.XData));
nu1 = fminsearch(@(nu) norm(yv1 - chi2cdf(xv1,nu)), 1);
hold on
[muest1,sdest1] = normfit(class1);
class1cdf = cdf('Chisquare',xv1,nu1);
plot(xv1,class1cdf,'-r', 'LineWidth',1)
hold off
xlabel('x')
ylabel('cdf')
xlim([0 1])
title('Class 1')
text(0.01,max(ylim), sprintf('\\nu = %.3f',nu1), 'Horiz','left', 'Vert','top')
legend('Empirical CDF',' \chi^2 Fit', 'Location','best')
grid
subplot(2,1,2)
[h2,stats2] = cdfplot(class2);
xv2 = h2.XData(isfinite(h2.XData));
yv2 = h2.YData(isfinite(h2.XData));
nu2 = fminsearch(@(nu) norm(yv2 - chi2cdf(xv2,nu)), 1);
hold on
class1cdf = cdf('Chisquare',xv2,nu2);
plot(xv2,class1cdf,'-r', 'LineWidth',1)
hold off
xlabel('x')
ylabel('cdf')
xlim([0 1])
title('Class 2')
text(0.01,max(ylim), sprintf('\\nu = %.3f',nu2), 'Horiz','left', 'Vert','top')
legend('Empirical CDF',' \chi^2 Fit', 'Location','best')
grid
.
Jeff Miller
on 2 May 2021
These data don't seem to come from any chi^2 distribution. The mean of a chi^2 equals its degrees of freedom, which is at least 1. These data sets have means far less than 1, so that is simply incompatible with any chi^2.
Star Strider
on 2 May 2021
@Jeff Miller — I agree. I was also not aware that data were ever
-distributed, only that parameters were.
Categories
Find more on Hypothesis Tests 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!