# Proper probability distribution formatting for DistributionFitTest

I am trying to use an exponentially modified gaussian to fit a distribution, but I think I may be misunderstanding something about how probability distributions work in Mathematica. Running

DistributionFitTest[data, NormalDistribution[mu, sigma], "FittedDistribution"]


works for a gaussian but

DistributionFitTest[data,
ProbabilityDistribution[E^((x - \[Mu])^2 / \[Sigma]^2) /
(\[Sigma] (2*Pi)^(1/2)),
{x, -Infinity, Infinity}], "FittedDistribution"]


does not. Does anybody know why this is happening? Once I clear this up I should be able to use other PDFs like the exponentially modified gaussian properly. Thanks!

Clear["Global*"]


An exponentially modified Gaussian distribution (EMG) describes the sum of independent normal and exponential random variables. wiki

SeedRandom[1234];

n = 200;

data = RandomVariate[NormalDistribution[3, 1], n] +
RandomVariate[ExponentialDistribution[2], n];

{min, max} = MinMax[data];
m = Mean[data];
s = StandardDeviation[data];


From the definition of an EMG and using TransformedDistribution

distEMG1 = TransformedDistribution[x + y,
{x \[Distributed] NormalDistribution[μ, σ],
y \[Distributed] ExponentialDistribution[λ]}];


The PDF is

PDF[distEMG1, x]

(* 1/2 E^(1/2 λ (-2 x + 2 μ + λ σ^2)) λ *
Erfc[(-x + μ + λ σ^2)/(Sqrt[2] σ)] *)


Estimating the distribution from the data using EstimatedDistribution

estDist1 =
EstimatedDistribution[data,
distEMG1, {{μ, m}, {σ, s}, {λ, 1}}]

(* TransformedDistribution[\[FormalX]1 + \[FormalX]2, {\[FormalX]1 \
\[Distributed]
NormalDistribution[2.9841, 0.849997], \[FormalX]2 \[Distributed]
ExponentialDistribution[1.99775]}] *)

DistributionFitTest[data, estDist1, "PValueTable"]


Using TransformedDistribution the constrains on the parameters are automatically taken from the underlying distributions. However, if the distribution is defined with ProbabilityDistribution, you must specify the constraints on the parameters as Assumptions

dpa = DistributionParameterAssumptions[distEMG1]

(* μ ∈ Reals && σ > 0 && λ > 0 *)

distEMG2 =
ProbabilityDistribution[PDF[distEMG1, x], {x, -Infinity, Infinity},
Assumptions -> dpa];


Estimating the distribution from the data

estDist2 =
EstimatedDistribution[data,
distEMG2, {{μ, m}, {σ, s}, {λ, 1}}]

(* ProbabilityDistribution[
0.998876 E^(0.998876 (7.41156 - 2 \[FormalX]))
Erfc[0.831893 (4.42746 - \[FormalX])], {\[FormalX], -∞, ∞}] *)


However, this form of the distribution does not play well with DistributionFitTest and the following is very slow to evaluate.

DistributionFitTest[data, estDist2, "PValueTable"]


Comparing the Histogram of the data with the PDF of the EstimatedDistributions

Show[
Histogram[data, Automatic, "PDF"],
Plot[{PDF[estDist1, x], PDF[estDist2, x]}, {x, min, max},
PlotStyle -> {{Red, Thick}, {Blue, Dashed}},
PlotLegends -> "Expressions"]]
`