I am trying to specify a user-defined probability distribution with ProbabilityDistribution
and am running into errors when I try to obtain the distribution parameters for data using EstimatedDistribution
in Mathematica.
(*Define the Distribution*)
ClearAll[stackheightfraction, BETDistribution, x, c];
stackheightfraction[x_, c_, k_Integer] := (1 - x)/(1 + (c - 1)*x) /;
k == 0
stackheightfraction[x_, c_, k_Integer] :=
c*(1 - x)*(x^k)/(1 + (c - 1)*x) /; k > 0
BETDistribution[x_, c_] :=
ProbabilityDistribution[
stackheightfraction[x, c, k], {k, 0, 1000, 1},
Assumptions -> x > 0 && c >= 1 && x < 1] // Evaluate
I wanted the upper limit of k to be Infinity
but after I settled for 1000 instead, I got Mean
,Variance
,Skewness
, PDF
and CDF
to work with the distribution. However, I could not get RandomVariate
to work.
{CDF[BETDistribution[.5, 5], 5], PDF[BETDistribution[.5, 5], 5],
Mean[BETDistribution[.5, 5]], Variance[BETDistribution[.5, 5]],
Skewness[BETDistribution[.5, 5]]}
I tested PDF
and CDF
using.
DiscretePlot[PDF[BETDistribution[.75, 10], k], {k, 0, 5},
ExtentSize -> Right, PlotRange -> All]
DiscretePlot[CDF[BETDistribution[.75, 10], k], {k, 0, 5},
ExtentSize -> Right, PlotRange -> All, PlotStyle -> Red]
But when I fit data, I run into issues:
data={0, 2, 0, 2, 0, 1, 0, 0, 1, 0, 0, 3, 0, 0, 1, 2, 1, 3, 0, 1, 0, 0, 0, \
2, 1, 0, 4, 2, 8, 4, 1, 2, 1, 10, 11, 10, 10, 5, 7, 5, 1, 12, 7, 7, \
12, 13, 3, 6, 9, 1, 5, 14, 6, 2, 2, 9, 8, 7, 6, 4, 7, 2, 5, 4, 8, 19}
EstimatedDistribution[data, BETDistribution[xx, cc]]
I get output that looks likes this:
EstimatedDistribution[{0, 2, 0, 2, 0, 1, 0, 0, 1, 0, 0, 3, 0, 0, 1, 2,
1, 3, 0, 1, 0, 0, 0, 2, 1, 0, 4, 2, 8, 4, 1, 2, 1, 10, 11, 10, 10,
5, 7, 5, 1, 12, 7, 7, 12, 13, 3, 6, 9, 1, 5, 14, 6, 2, 2, 9, 8, 7,
6, 4, 7, 2, 5, 4, 8, 19}, ProbabilityDistribution[stackheightfraction[xx, cc, \[FormalX]], {\[FormalX], 0, 1000, 1},
Assumptions -> xx > 0 && cc >= 1 && xx < 1]]
I am assuming that it has something to do with my ProbabilityDistribution
because I had to add \\Evaluate
before that that definition would work at k = 1.
RandomVariate
to work with version 12.0 (Windows 10) but notEstimatedDistribution
with your example. $\endgroup$BETDistribution[x_, c_] := ProbabilityDistribution[ Piecewise[{{(1 - x)/(1 + (c - 1)*x), k == 0}, {c*(1 - x)*(x^k)/(1 + (c - 1)*x), k > 0}}], {k, 0, Infinity}, Assumptions -> {0 < x < 1, c > 1}]
. That works with theInfinity
term for $k$. $\endgroup$Manipulate
) to see if you can match the calculated PDF of your distribution to the experimental PDF of your data (e.g. fromHistogram[data, Automatic, "PDF"]
. That might give you better starting points for theEstimatedDistribution
, or forFindDistributionParameters
. $\endgroup$Piecewise
like the plague inProbabilityDistribution
(129690). $\endgroup$