plot - Distribution fitting and histogram overlay (scaling matter) - MATLAB -



plot - Distribution fitting and histogram overlay (scaling matter) - MATLAB -

while trying overlay pdf (probability density function) values on histogram face important scaling issues histogram barely visible on chart. might due scaling factors used in below code, otherwise density curves tiny. in predicament , wondering if there better way accomplish task without resorting adhoc scaling factor?

bmin=min(b); bmx=max(b); nrow=length(b); nbin=sqrt(nrow); pd = fitdist(b,'normal'); p = stblfit(b,'ecf'); x_pdf=[bmin:0.0025:bmax]; y=pdf(pd,x_pdf); hist(b,nrow); h = findobj(gca, 'type','patch'); h.facecolor=[0 0 0]; hold on; scale = 0.156*max(y); plot(x_pdf,y.*scale,'or'); hold on; scale2 = 0.24*max(y); plot(x_pdf,stblpdf(x_pdf,p(1),p(2),p(3),p(4)).*scale2,'k-'); legend('p&l distribution','normal fit', 'ecf fit')

thanks

as plotting histogram, y-axis represents number of counts specific interval. if have longer or shorter input vector, values of histogram different. histogram can used approximation probability density (pdf), need scale correctly. integral of pdf -infinity +infinity has result in 1, need scale histogram accordingly.

you can still utilize hist command, instead of using generate histogram plot, count values it. vector can scaled have integral of 1 calculating integral , dividing vector that.

% generate arbitrary gaussian distribution b = randi(10) + randi(10) .* randn(10000,1); bmin = min(b); bmax = max(b); % calculate histogram [counts,bins] = hist(b,100); % scale histogram pdf est_pdf = counts / sum(counts * mean(diff(bins))); % estimate pdf using fitdist pd = fitdist(b,'normal'); x_pdf = linspace(bmin,bmax,1000); y_pdf = pdf(pd,x_pdf); % plot figure; hold on; bar(bins,est_pdf); plot(x_pdf, y_pdf, '-r'); hold off;

note: calculate integral of counts multiplying counts mean interval width of histogram, not intervals as wide. approximation of integral, should exact enough.

matlab plot statistics distribution

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -