How to plot empirical cdf and fitted distributions cdfs?

조회 수: 9 (최근 30일)
Macy
Macy 2023년 2월 13일
댓글: Macy 2023년 2월 15일
Hi, want to make one plot with the empirical CDF and three additional distributions CDFs (normal, lognormal, and weibull) to visually compare goodness of fit. (This is a smaller subset of data).
But, the x-axis of the fitted distributions goes to 1, whereas the empirical CDF goes to 2310. How can I make the x-axis to represent the table values, and the how do I overlay the plots so they are all in one plot?
Table = readtable("practice3.xlsx");
a = Table.values;
cdfplot(a); % Make a plot of the empirical CDF
% fit the normal, lognormal, and weibull distributions to the data
pd_normal = fitdist(a,'Normal');
pd_lognormal = fitdist (a, 'Lognormal');
pd_weibull = fitdist(a,"Weibull");
% generate CDF values for each of the fitted distributions
cdf_n = cdf(pd_normal,a);
cdf_l = cdf(pd_lognormal,a);
cdf_w = cdf(pd_weibull,a);
% plot the three distributions cdfs
figure;
hold on;
cdfplot(cdf_n)
cdfplot(cdf_l)
cdfplot(cdf_w)
grid on;
hold off;
%The x-axis of the fitted distributions goes to 1. How do I overlay the
%fitted distributions over the empirical distribution? The x-axis should go
%to 2500.

채택된 답변

Torsten
Torsten 2023년 2월 13일
Table = readtable("practice3.xlsx");
a = Table.values;
a = sort(a);
hold on
cdfplot(a); % Make a plot of the empirical CDF
% fit the normal, lognormal, and weibull distributions to the data
pd_normal = fitdist(a,'Normal');
pd_lognormal = fitdist (a, 'Lognormal');
pd_weibull = fitdist(a,'Weibull');
% generate CDF values for each of the fitted distributions
cdf_n = cdf('Normal',a,pd_normal.mu,pd_normal.sigma);
cdf_l = cdf('LogNormal',a,pd_lognormal.mu,pd_lognormal.sigma);
cdf_w = cdf('Weibull',a,pd_weibull.A,pd_weibull.B);
% plot the three distributions cdfs
plot(a,cdf_n)
plot(a,cdf_l)
plot(a,cdf_w)
hold off
grid on

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Exploration and Visualization에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by