How to plot probability density curve?

3 次查看(过去 30 天)
I have modify the strip as per my data but its the resulst are not expected. Why the movemedian=25 is fixed here.
X = readmatrix('R_0.01.csv');
r_a=[X(1,:)];
r_b=[X(2,:)];
r_c=[X(3,:)];
r_d=[X(4:8,:)];
r_e=[X(9:12,:)];
r_f=[X(13:16,:)];
r_g=[X(17:26,:)];
r_h=[X(27:48,:)];
r_i=[X(49:120,:)];
r_j=[X(121:186,:)];
r_aam = (r_a(~isnan(r_a)));
r_abm = r_b(~isnan(r_b));
r_acm = r_c(~isnan(r_c));
r_adm = r_d(~isnan(r_d));
r_aem = r_e(~isnan(r_e));
r_afm = r_f(~isnan(r_f));
r_agm = r_g(~isnan(r_g));
r_ahm = r_h(~isnan(r_h));
r_aim = r_i(~isnan(r_i));
r_ajm= r_j(~isnan(r_j));
pd = makedist('Normal')
[f1,x1,flo1,fup1] = ecdf(r_aam);
[f2,x2,flo2,fup2] = ecdf(r_abm);
[f3,x3,flo3,fup3] = ecdf(r_acm);
[f4,x4,flo4,fup4] = ecdf(r_adm);
[f5,x5,flo5,fup5] = ecdf(r_aem);
[f6,x6,flo6,fup6] = ecdf(r_afm);
[f7,x7,flo7,fup7] = ecdf(r_agm);
[f8,x8,flo8,fup8] = ecdf(r_ahm);
[f9,x9,flo9,fup9] = ecdf(r_aim);
[f10,x10,flo10,fup10] = ecdf(r_ajm);
figure
plot(x, f)
grid
title('Empirical CDF')
dfdxs1 = smoothdata(gradient(f1)./gradient(x1), 'movmedian',25);
dfdxs2 = smoothdata(gradient(f2)./gradient(x2), 'movmedian',20);
dfdxs3 = smoothdata(gradient(f3)./gradient(x3), 'movmedian',25);
dfdxs4 = smoothdata(gradient(f4)./gradient(x4), 'movmedian',25);
dfdxs5 = smoothdata(gradient(f5)./gradient(x5), 'movmedian',25);
dfdxs6 = smoothdata(gradient(f6)./gradient(x6), 'movmedian',25);
dfdxs7 = smoothdata(gradient(f7)./gradient(x7), 'movmedian',25);
dfdxs8 = smoothdata(gradient(f8)./gradient(x8), 'movmedian',25);
dfdxs9 = smoothdata(gradient(f9)./gradient(x9), 'movmedian',25);
dfdxs10 = smoothdata(gradient(f10)./gradient(x10), 'movmedian',1000);
aaa1=smooth(dfdxs1)
aaa2=smooth(dfdxs2)
aaa3=smooth(dfdxs3)
aaa4=smooth(dfdxs4)
aaa5=smooth(dfdxs5)
aaa6=smooth(dfdxs6)
aaa7=smooth(dfdxs7)
aaa8=smooth(dfdxs8)
aaa9=smooth(dfdxs9)
aaa10=smooth(dfdxs10)
figure
plot(x1, aaa1)
plot(x2, aaa2)
plot(x3, aaa3)
plot(x4, aaa4)
plot(x5, aaa5)
plot(x6, aaa6)
plot(x7, aaa7)
plot(x8, aaa8)
plot(x9, aaa9)
plot(x10, aaa10)

采纳的回答

Star Strider
Star Strider 2021-12-8
For data with an unknown distribution, I generally use the empirical cumulative distribution (ecdf) function to get the CDF, and the use the gradient function to derive the PDF. This is generally more robust than estimating the PDF directly, at least in my experience.
.
  10 个评论
Andi
Andi 2022-3-30
I try with the ksdensity but results are not expected.

请先登录,再进行评论。

更多回答(0 个)

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by