# What is the best distribution for my histogram?

I defined a security bound for a random walk (cube with 15 lengh) and i have this code to obtain a sample of the random times at which the random walk crosses the boundary for the first time:

w = Do[i = 0; NestWhile[(i++; # + RandomReal[{-1, 1}, 3]) &, {0, 0, 0},Norm[#] < 15 &];    Sow[i], {1000}] // Reap


(take the code from here Sample of the random times at which the random walk crosses the boundary)

And i constructed a histogram with w:

And now i want to know the distribution of this data, i tought that is was a gamma because of the histogram but i run some tests in excel and i concluded that it isnt but i would like to confirm that with mathematica, is that possible?

And when i do this

\[ScriptCapitalH] = DistributionFitTest[w[[2, 1]], Automatic, "HypothesisTestData"];

\[ScriptCapitalH]["FittedDistribution"]


I have for output: NormalDistribution[233.588, 150.231], but sweekness[w]=1.83 (if it was a normal it should be aproxematly zero).

Would like some help please :)

-
@Szabolcs doesn't this question boil down to "How do I use DistributionFitTest to determine whether or not my data fit a gamma distribution?"? If so, then mma.se may be more appropriate than math. –  bobthechemist Mar 25 at 13:56
@bobthechemist You're right, I was focusing on "And now i want to know the distribution of this data". –  Szabolcs Mar 25 at 14:05
The documentation on this is not at all clear, but I don't think Automatic as the second argument does at all what you think. It seems to just assume a normal dist and the Automatic argument specifies the test type. (Can anyone cook up an example where Automatic returns anything other than NormalDistribution ) ? –  george2079 Mar 25 at 15:55
Just for clarity, DistributionFitTest defaults to a test for normality. The fitted distribution is NOT the best fitting distribution. It is the best fitting distribution in the family you are testing. When setting the distribution family to Automatic you are using the normal family of distributions. –  Andy Ross Mar 25 at 18:32
thanks for help, didnt find that anywhere @Andy Ross, now i have my answer :) –  Mariana da Costa Mar 25 at 19:28

The mathematica help is very thorough and is very indicative of what you should do next. By way of the histogram diagram obtained, you can compare your data against the proposed distribution.

Show[Histogram[w[[2, 1]], Automatic, "ProbabilityDensity"],
Plot[PDF[h["FittedDistribution"], x], {x, 0, 1500},
PlotStyle -> Thick]]


The reference points you to run the ProbabilityPlot function so you can see how well the curve fits.

ProbabilityPlot[w[[2, 1]], h["FittedDistribution"]]


Not that great.

By further exploring the parametric distributions available in Mathematica, all very well documented in the help , the Gamma distribution looks like a good candidate.

dist = GammaDistribution[α, β, γ, μ]
myFit = DistributionFitTest[w[[2, 1]], dist, "HypothesisTestData"]
Show[Histogram[w[[2, 1]], Automatic, "ProbabilityDensity"],
Plot[PDF[myFit["FittedDistribution"], x], {x, 0, 1500},
PlotStyle -> Thick]]


This looks much more like it.

ProbabilityPlot[w[[2, 1]], myFit["FittedDistribution"]]


-
thanks for help :D not exactly what i wanted but it was really helpfull. I dont understand is why the output for [ScriptCapitalH]["FittedDistribution"] is not Gammadistribution. And other question when i do KolmogorovSmirnovTest[w[[2, 1]]] mathematica gives me zero, do u have any ideia why this is happening? –  Mariana da Costa Mar 25 at 13:48
DEar @MarianadaCosta, I'm not privy to how the algorithms have been developed. It might be that Automatic just defaults to the most used distribution, namely, the Normal Distribution. I would recommend that you take a look a look at EDA (exploratory data analysis). A starting point en.wikipedia.org/wiki/Exploratory_data_analysis –  Zviovich Mar 25 at 14:55

If you wanted to automate things you might do something like this:

 tests = Sort[(g =
DistributionFitTest[
w, #, {"PValue", "FittedDistribution"}])  & /@  {
NormalDistribution[a, b],
ChiSquareDistribution[a],
HalfNormalDistribution[a],
LogNormalDistribution[a, b]}]

{{0., NormalDistribution[232.755, 156.711]},
{7.09814*10^-19, ChiSquareDistribution[195.469]},
{1.34007*10^-16, HalfNormalDistribution[0.00446664]},