0
$\begingroup$

I am confused by the behavior of MixtureDistribution, even though that sounds like what I would need.

Let's say I want to get a parametric solution for the variance of the compound lottery of either playing the 50-50 lottery of \$0 or \$4 with probability a, or playing a separate 50-50 lottery of \$0 or \$2 (with the complementary probability).

I can get this done with EmpiricalDistribution but that's becoming unwieldy in more complicated cases.

emp = EmpiricalDistribution[{a/2,a/2,(1-a)/2,(1-a)/2}->{0,4,0,2}]
    Variance[emp]

Make no mistake, this is not about a linear combination of random variables. It is trivial to work with (say) convex combinations of random variables or probability distributions, but that's not the same thing. (Easy to see with discrete random variables: the mixture yields outcomes from the union of the original outcomes, e.g. a few integers, while the linear combination can have a (discrete set) of real numbers, depending on the weights, a in my example.)

To see, TransformedDistribution does not do mixtures, compare this to the solution above:

Variance[TransformedDistribution[a*4*y+(1-a)*2*z,{y\[Distributed]BernoulliDistribution[0.5],z\[Distributed]BernoulliDistribution[0.5]}]]

MixtureDistributions sound like just what we need here, they just looked a bit obscure in the documentation and functions recommended automatically.

$\endgroup$
5
  • 1
    $\begingroup$ The correct associated EmpiricalDistribution is EmpiricalDistribution[{1/4, 1/4, 1/4, 1/4} -> {0, 2 - 2 a, 4 a, 2 (1 + a)}] which gives the same exact variance. (There are 4 outcomes each with a probability of $1/4$.) Note that Mathematica also has a MixtureDistribution function. $\endgroup$
    – JimB
    Commented Jan 18, 2019 at 14:23
  • $\begingroup$ Can you give a more concrete example of what you're after? Currently, I don't see the connection between the two examples you give. For instance, your TransformedDistribution returns discrete values, which you say is only the case for mixtures. $\endgroup$
    – Lukas Lang
    Commented Jan 18, 2019 at 14:38
  • $\begingroup$ Thanks, @JimB. emp is the "correct" distribution function that would be nice to construct from y' and z'. MixtureDistribution might be it, somehow I overlooked it. $\endgroup$
    – László
    Commented Jan 18, 2019 at 14:38
  • $\begingroup$ @LukasLang Let me work through MixtureDistribution here (I'm still surprising the documentation and googling did not led me there sooner), but on your point: Indeed, I was imprecise (will edit soon). The outcomes remain discrete after a transformation, but not the original outcomes with mixed probabilities. E.g. my outcomes were three integers, which the mixture preserves whatever a is, while the transformation maps into fractions. $\endgroup$
    – László
    Commented Jan 18, 2019 at 14:43
  • 1
    $\begingroup$ I'm even more confused by your edit. However, the overall issue might be summarized as the difference between a function of the random variables (TransformedDistribution) and a function of the associated probability density functions (MixtureDistribution). (That's a bit of an oversimplification but it might work here.) $\endgroup$
    – JimB
    Commented Jan 18, 2019 at 15:16

2 Answers 2

2
$\begingroup$

What you seem to have is a function of 3 random variables rather than 2. The resulting random variable is defined by

$X=\alpha*4 Y+(1-\alpha)*2Z$

where $Y\sim Bernoulli(1/2)$, $Z\sim Bernoulli(1/2)$, $\alpha\sim Bernoulli(a)$, and $Y$, $Z$, and $\alpha$ are all independent.

One could use TransformedDistribution to define the resulting distribtion:

mixture = TransformedDistribution[α*4 y + (1 - α)*2 z, 
  {y \[Distributed] BernoulliDistribution[1/2], 
   z \[Distributed] BernoulliDistribution[1/2],
   α \[Distributed] BernoulliDistribution[a]}]
Variance[mixture]
(* 1 + 4 a - a^2 *)

But it is equivalent (in terms of results - I don't know about speed) to using MixtureDistribution as shown in your answer.

So TransformedDistribution will do "mixture distributions".

$\endgroup$
3
  • $\begingroup$ That's cool, I have not thought of mixtures this way, but of course they work like this. That said, and sorry for not upvoting or accepting your answer, I think a mixture of two random variables is the intuitive and standard terminology here. Cf. en.wikipedia.org/wiki/Mixture_distribution $\endgroup$
    – László
    Commented Jan 18, 2019 at 15:44
  • $\begingroup$ I love it. You're telling me (a Ph. D. statistician for over 40 years) what the standard terminology is. That's one of the things I like about this forum. I'm constantly challenged. $\endgroup$
    – JimB
    Commented Jan 18, 2019 at 15:48
  • $\begingroup$ But make no mistake: your answer is the way one should do it in Mathematica. I was only trying to show how mixture distributions come about. I've modified my answer so yours can be selected as the accepted answer. $\endgroup$
    – JimB
    Commented Jan 18, 2019 at 15:59
1
$\begingroup$

This is all we need, MixtureDistribution does what it is supposed to, just use weights correctly. In my case:

p=TransformedDistribution[4*z,z\[Distributed]BernoulliDistribution[0.5]]
q=TransformedDistribution[2*s,s\[Distributed]BernoulliDistribution[0.5]]
mix=MixtureDistribution[{a,1-a},{p,q}]
Variance[mix]

(Thanks to JimB for pointing me to MixtureDistribution in a comment.)

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.