# Finding the correct probability distribution function

Here is a sample of data which corresponds to the following histogram

data = Flatten[Import["hist.dat", "Table"], 1];

P00 = Histogram[data, Automatic, "Probability", ChartStyle -> Gray,
ChartBaseStyle -> EdgeForm[None], Frame -> True,
FrameLabel -> {"N", "P"}, RotateLabel -> False,
LabelStyle -> Directive[FontFamily -> "Helvetica", 20],
Epilog -> {Red, Thick, Dashed,
Line[{{#, 0}, {#, 1}} &@Last@Commonest[data]]}, PlotRange -> All,
PlotRangePadding -> 0.001, AspectRatio -> 1, ImageSize -> 550] Now I want to find the best possible probability distribution function (PDF). So let's try some of the most well-known PDFs:

1. Laplace distribution:

fit1 = FindDistributionParameters[Flatten@data, LaplaceDistribution[m, b]]
m0 = m /. fit1[];
b0 = b /. fit1[];
t1 = Plot[PDF[LaplaceDistribution[m0, b0], x], {x, 0, 30},
PlotStyle -> {Magenta, Thick}, PlotRange -> All];
Show[{P00, t1}, Axes -> False] As we can see, the right-hand side of the distribution is acceptable but the left-hand side is not.

2. Maxwell distribution:

fit2 = FindDistributionParameters[Flatten@data, MaxwellDistribution[m]]
m1 = m /. fit2[];
t2 = Plot[PDF[MaxwellDistribution[m1], x], {x, 0, 30}, PlotStyle -> {Magenta, Thick}];
Show[{P00, t2}, Axes -> False] 3. Reyleigh distribution:

fit3 = FindDistributionParameters[Flatten@data, RayleighDistribution[m]]
m2 = m /. fit3[];
t3 = Plot[PDF[RayleighDistribution[m2], x], {x, 0, 30}, PlotStyle -> {Magenta, Thick}];
Show[{P00, t3}, Axes -> False] We observe that the last two types of distribution do not fit well the data. In particular, they do not go high enough.

My question: Is there a way to fix/modify/improve these types of PDFs in order to achieve the best possible fit in my data? Moreover, is there any other type of PDF which might work better in this case?

• "Why?" Because that would be an even worse fit, the distributions tie height with width. You can't just guess at the distributions, surely you have an idea which one would fit before you run the experiment? Oct 28 '16 at 8:39
• Have you tried FindDistribution? Oct 28 '16 at 9:39
• If your integer data consists of counts, then attempting to fit continuous distributions will never get you the "correct" distribution (which is taken directly from your question). If your integer data is simply rounded, then treating your data as if it were continuous is not the best way to estimate the parameters in an underlying continuous distribution. So...what is the generating process of your data? As has been suggested by others in your previous question, are there not candidate distributions suggested or implied by your experiment?
– JimB
Oct 28 '16 at 15:19
• Your data is clearly discrete (iintegers going from 4 to 29) and so fitting a continuous distribution is not likely a great approach. If you could mention something about the data generation process, that would help. For instance, are these numbers counts? Is there just a lot of round-off that results in integer values? And why you think you need to estimate a probability density or probability mass function, would also be helpful. In other words, what would having a function with a few parameters benefit you over just showing the histogram/frequency table?
– JimB
Dec 8 '18 at 17:46
• I don't know why but I felt if I repeated myself from 2 years ago, it might have an effect. And note that whatever you end up with, it won't be "correct" (as requested in the title). It will be (hopefully) a reasonably parsimonious description of the data (no more, no less).
– JimB
Dec 8 '18 at 17:50

From a statistical point of view, the question is not well-posed. If you insist on finding some distribution, then use FindDistribution:

data = Import["hist.dat", "List"];
th = Last @ Commonest[data];
data = Select[data, # >= th &]; (*because in a previous question you were interested only in these data *)

dist = FindDistribution[data]


MixtureDistribution[{0.859154, 0.140846}, {PascalDistribution[6, 0.834241], PoissonDistribution[12.6456]}]

t1 = Plot[PDF[dist, x], {x, th, 30}, PlotStyle -> {Black, Thick},
PlotRange -> All];
Show[P00, t1, Axes -> False] • FindDistribution is not recognized in version 9 :( Is there a way to obtain the analytical expression of dist? Oct 28 '16 at 12:56
• You can take the dist from the answer (can take also general parameters of the distributions) and PDF[dist, x] will give an analytical formula. Oct 28 '16 at 13:01
• Are there any references as to how exactly FindDistribution works? The entry in Wolfram Reference does not have much information besides the fact there is a Bayesian approach behind the scenes. Sep 21 '17 at 8:51
• The OP specifies that he is looking for a pdf (which stands for probability density function - not prob distribution function). By standard statistical nomenclature, this means s/he is looking for a continuous distribution, whereas that provided above is discrete. Perhaps the OP could clarify what s/he wants ... but if the OP is after a discrete distribution, the correct expression is pmf (not pdf). Dec 8 '18 at 13:35