Test for Goodness of Fit to Any Distribution or Dataset
Visually compare adaptive kernel density estimates to parametric distributions and assess the fit with any one of over a dozen goodness-of-fit tests.
d = NormalDistribution;
dat = BlockRandom[SeedRandom[2];
RandomVariate[𝒹 = MixtureDistribution[Join[{1 / 2}, Table[2 ^ (1 - i) / 31, {i, -2, 2}]], Join[{d[]}, Table[d[i + 1 / 2, 1 / (2 ^ i * 10)], {i, -2, 2}]]], 10 ^ 4]];p1 = Plot[PDF[𝒹, x], {x, -4, 4}, PlotRange -> All, Filling -> Axis, Axes -> {True, False}];
p2 = SmoothHistogram[dat, {"Adaptive", Automatic, .5}, Axes -> {True, False}, PerformanceGoal -> "Quality", PlotStyle -> Red];
p3 = DistributionFitTest[dat, 𝒹, {"TestDataTable", All}];
data = BlockRandom[SeedRandom[9];
RandomVariate[MultivariateTDistribution[IdentityMatrix[2], 20], 50]];p5 = DistributionFitTest[data, Automatic, {"TestDataTable", All}];
p4 = SmoothHistogram3D[data, {"Adaptive", Automatic, .25}, PlotRange -> All, ColorFunction -> "LakeColors", Axes -> {True, False, False}, ImageSize -> 250, Boxed -> False, BoxRatios -> {1, 1, 2 / 3}, PerformanceGoal -> "Quality"];Grid[{{Show[p1, p2, ImageSize -> 250], p3}, {p5, p4}}, Spacings -> {0, 0}]