Suppose I want to do calculations with a random variable $X$ that has a simple categorical distribution (a.k.a generalised Bernoulli distribution or discrete distribution).
I was expecting to be able to work with a distribution "symbolically". That is, I was expecting that there would be a function like CategoricalDistribution
, that we could use like this.
distX = CategoricalDistribution[{1/3, 1/2, 1/6}];
But no distributions in tutorial/DiscreteDistributions looked like they were suitable. An example of how the distribution would be used would be
{Probability[x == 0, x \[Distributed] dist],
Probability[x == 1, x \[Distributed] dist],
Probability[x == 2, x \[Distributed] dist]}
would output
{1/3, 1/2, 1/6}
In this particular case, we can do a workaround, by doing
dist = TransformedDistribution[
x1 + x2, {x1 \[Distributed] BernoulliDistribution[1/2],
x2 \[Distributed] BernoulliDistribution[1/3]}]
Unfortunately, this is not always possible, even with only 3 possible outcomes. For example, we cannot simulate CategoricalDistribution[{1/2, 0, 1/2}]
like this, as we cannot have independent Bernoulli random variables that behave like this.
I was hoping the categorical distribution might be a special case of another distribution. Especially the MultinomialDistribution
with 1 as its first argument looks useful, but I cannot transform that distribution into a distribution that gives an integer. Again it seems like I am missing a function like CategoricalDistribution
to do so. To give an example
Position[RandomVariate@MultinomialDistribution[1, {1/2, 0, 1/2}],
1][[1, 1]]
"has the right distribution", but unfortunately I cannot use Position
inside TransformedDistribution
.
I am aware of functions like RandomChoice
, but really I only want to do manipulations on distributions. Does anybody know how to do this?
dist = ProbabilityDistribution[Piecewise[{{1/2, y == 0}, {0, y == 1}, {1/2, y == 2}} ], {y, 0, 2, 1}]
, ordist = ProbabilityDistribution[Switch[y, 0, 1/2, 1, 0, 2, 1/2], {y, 0, 2, 1}];
do pretty much what I want. Maybe I should delete/close the question. $\endgroup$