1
$\begingroup$

Suppose there is a random variable $X$ that can take on values $-1,0,1$, with probabilities $P(X=1)=P(X=-1)=.25$ and $P(X=0)=.5$.

How can I work with such a random variable in mathematica? (Find the mean, transform it -- for example by adding it to another random variable -- etc).

The EmpiricalDistribution command seems to do this, but creates a DataDistribution instead of distribution.

So my question is whether using EmpiricalDistribution is the correct way to model such a random variable, and if so is there downfalls/issues that DataDistribution objects have that typical distributions dont? (For example, perhaps they are much slower?)

(Aside: Instead of a random variable $X$ taking on 3 values, a more practical example is perhaps a distribution for a "weighted/damaged" dice that has $0$ probability of showing 6, and $1/3$ probability of showing 1)

$\endgroup$
2
$\begingroup$

I only address your first question "How can I work with such a random variable in mathematica? (Find the mean, transform it -- for example by adding it to another random variable -- etc)."

Despite me not liking the name of 'EmpiricalDistribution` for dealing with legitimate discrete distributions, going that route seems to allow the use of most of Mathematica's random variable functions. (But despite using Mathematica for quite some time, there is so much I don't know about it.)

d1 = EmpiricalDistribution[{1/4, 1/2, 1/4} -> {-1, 0, 1}];
d2 = EmpiricalDistribution[{1/8, 1/2, 1/8, 1/4} -> {-1, 0, 1/2, 1}];

dSum = TransformedDistribution[x1^2 + 7 Cos[x2], {x1 \[Distributed] d1, x2 \[Distributed] d2}];

Mean[dSum]
(* Oops, this doesn't work *)

Output of Mean[dSum]

Expectation[z, z \[Distributed] dSum]
(* 4 + 7/8 Cos[1/2] + (21 Cos[1])/8 *)

Expectation[z^2, z \[Distributed] dSum]
(* 1/16 (652 + 14 Cos[1/2] + 91 Cos[1] + 147 Cos[2]) *)

PDF[dSum, z]

PDF of dSum

SeedRandom[12345];
RandomVariate[dSum, 25]
(* {1 + 7 Cos[1], 7 Cos[1], 8, 7 Cos[1], 1 + 7 Cos[1/2], 7, 
 7 Cos[1], 7, 8, 8, 7, 7, 7 Cos[1], 7, 7, 7 Cos[1], 8, 
 7 Cos[1], 8, 7, 7, 1 + 7 Cos[1/2], 7 Cos[1], 8, 7} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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