Plotting Gamma Distribution, log-normal and histogram

15 vues (au cours des 30 derniers jours)
Carlos_conde
Carlos_conde le 18 Déc 2018
Hello all,
I have witten a piece of code to plot
Gamma Distribution
Log-normal distribution
Histogram (pdf)
from my raw data (droplet diameter).
I am not sure if I have done it correctly because the height of the bins do not match with the fittings (see image). Have I done something wrong? I have also attached the code and data.
Thanks in advance
clear all
close all
%%
load droplet_diameter
%%gamma plot
x= 0:0.01:8;
Y= gamfit(droplet_diameter)
G= gampdf(x,Y(1,1),Y(1,2))
figure
plot(x,G)
%%log
mean=mean(droplet_diameter);
variance= var(droplet_diameter);
sigma= (variance)^0.5
y_lognormal=lognpdf(x,log(mean),sigma)
figure
plot(x,y_lognormal)
hold on
plot(x,G)
hold on
histogram(droplet_diameter,'Normalization','pdf')

Réponses (1)

John D'Errico
John D'Errico le 18 Déc 2018
Hmm. I recall answering exactly this same question recently. For a second or so, I wondered if I should expect a spate of such questions. (Did something change when histogramwas introduced?) But you did properly use the histogram method of 'pdf', so the scaling is correct.
That suggests the problem is lack of fit. When I look at the histogram, I'd bet that your actual distribution has a bit heavier upper tail than either a lognormal or a gamma distribution can offer. So the mismatch is in terms of a poorly fitting distribution.
Does that mean your distribution is not in fact either lognormal or gamma in reality? Well, NO real world sampled data ever truly follows any fixed distribution. There is always some amount of crap in there as noise. As well, your distribution is based on far too little data to pin down anything very well. So the true distribution might have been either of those or maybe neither one. At best, you can use a statistcal test to decide which is most probable.
Basically, get better (more) data.

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by