Fitting Bimodal Data to Histogram

3 次查看(过去 30 天)
Sophie Lis
Sophie Lis 2018-6-5
I am having trouble fitting the below bimodal data, which I plotted on a histogram. I am using the suggested MathWorks code to fit bivariate distributions (below), but for some reason, when I plot probability density on the yaxis, it appear to the 10^4 power, while the maximum value of the original histogram is 14, so I cannot overlay the two.
min_pts =
1.0e-04 *
0.0341 -0.1578 -0.1203
0.0198 -0.1459 -0.1284
0.0014 -0.1314 -0.1343
-0.0106 -0.1208 -0.1378
-0.0157 -0.1243 -0.1385
-0.0146 -0.1235 -0.1360
-0.0085 -0.1184 -0.1302
0.0015 -0.1092 -0.1216
0.0140 -0.0964 -0.1355
0.0278 -0.0807 -0.1465
0.0417 -0.0698 -0.1551
0.0554 -0.0655 -0.1618
0.0687 -0.0601 -0.1673
0.0816 -0.0550 -0.1721
0.0937 -0.0535 -0.1764
0.0860 -0.0726 -0.1803
0.0746 -0.1059 -0.1838
0.0443 -0.1343 -0.2418
0.0175 -0.1572 -0.2958
-0.0059 -0.1753 -0.3404
-0.0267 -0.1894 -0.3754
-0.0455 -0.2006 -0.4009
-0.0646 -0.2097 -0.4175
-0.0860 -0.2176 -0.4259
-0.1122 -0.2252 -0.4271
-0.1635 -0.2325 -0.4222
-0.2402 -0.2406 -0.4124
-0.3529 -0.2804 -0.3989
-0.4898 -0.3394 -0.3829
-0.6217 -0.4144 -0.4013
-0.7379 -0.4785 -0.4637
-0.8333 -0.5280 -0.5109
-0.9040 -0.5600 -0.5454
-0.9467 -0.5744 -0.5877
-0.9629 -0.5723 -0.6217
-0.9552 -0.5548 -0.6455
-0.9265 -0.5251 -0.6580
-0.9125 -0.4869 -0.6580
-0.8938 -0.4436 -0.6452
-0.8624 -0.3977 -0.6207
-0.8205 -0.3534 -0.5859
-0.7651 -0.3244 -0.5425
-0.7324 -0.2901 -0.4927
-0.7186 -0.2511 -0.4389
-0.6929 -0.2083 -0.3833
-0.6558 -0.1624 -0.3274
-0.6081 -0.1434 -0.3061
-0.5509 -0.1350 -0.3289
-0.4862 -0.1283 -0.3494
-0.4163 -0.1228 -0.3659
-0.4981 -0.1175 -0.3768
-0.6118 -0.1146 -0.3808
-0.7117 -0.1273 -0.3766
-0.7933 -0.1395 -0.3633
-0.8527 -0.1499 -0.3409
-0.8893 -0.1573 -0.3095
-0.9035 -0.1608 -0.2699
-0.8962 -0.1593 -0.2241
-0.8706 -0.1520 -0.1857
-0.8303 -0.1394 -0.2045
-0.7791 -0.1221 -0.2232
-0.7207 -0.1010 -0.2405
-0.6610 -0.0774 -0.2552
-0.6147 -0.0663 -0.2662
-0.5666 -0.0562 -0.2724
-0.5184 -0.0455 -0.2727
-0.4712 -0.0417 -0.2670
-0.4261 -0.0796 -0.2551
-0.3832 -0.1217 -0.2371
-0.3425 -0.1664 -0.2138
-0.3041 -0.2118 -0.1923
-0.2677 -0.2561 -0.2120
-0.2332 -0.2973 -0.2276
-0.2003 -0.3335 -0.2378
-0.1686 -0.3632 -0.2417
-0.1377 -0.3855 -0.2384
-0.1071 -0.3998 -0.2282
-0.0769 -0.4057 -0.2114
-0.0469 -0.4033 -0.1889
-0.0175 -0.3931 -0.1620
0.0106 -0.3755 -0.1446
0.0364 -0.3510 -0.1289
0.0252 -0.3204 -0.1119
-0.0195 -0.2842 -0.1305
-0.0644 -0.2435 -0.1471
-0.1089 -0.1992 -0.1612
-0.1521 -0.1523 -0.1726
-0.1932 -0.1620 -0.1811
-0.2311 -0.1738 -0.1865
-0.2646 -0.1840 -0.1892
-0.2927 -0.1924 -0.1897
-0.3141 -0.1986 -0.1885
-0.3280 -0.2023 -0.1864
-0.3335 -0.2031 -0.1900
-0.3300 -0.2010 -0.2451
-0.3174 -0.2063 -0.2989
-0.2960 -0.2274 -0.3493
x = min_pts(:);
figure;
hist(x,100);
pdf_normmixture = @(x,p,mu1,mu2,sigma1,sigma2) ...
p*normpdf(x,mu1,sigma1) + (1-p)*normpdf(x,mu2,sigma2);
pStart = .5;
muStart = quantile(x,[.25 .75]);
sigmaStart = sqrt(var(x) - .25*diff(muStart).^2);
start = [pStart muStart sigmaStart sigmaStart];
lb = [0 -Inf -Inf 0 0];
ub = [1 Inf Inf Inf Inf];
paramEsts = mle(x, 'pdf',pdf_normmixture, 'start',start, ...
'lower',lb, 'upper',ub);
bins = 100;
%h = bar(bins,histc(x,bins)/(length(x)*.5),'histc');
%h.FaceColor = [.9 .9 .9];
xgrid = linspace(1.1*min(x),1.1*max(x),300);
pdfgrid = pdf_normmixture(xgrid,paramEsts(1),paramEsts(2),paramEsts(3),paramEsts(4),paramEsts(5));
hold on
plot(xgrid,pdfgrid,'-')
hold off
xlabel('x')
ylabel('Probability Density')

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by