3
$\begingroup$

Execute the following code:

   Clear[d1, d2, x, y, dd]
   d1 = EmpiricalDistribution[{6, 65/10, 7, 75/10, 8}];
   d2 = EmpiricalDistribution[{3, 45/10, 6, 75/10, 9, 105/10, 12, 135/10}];
   dd = TransformedDistribution[x > y, {x \[Distributed] d1, y \[Distributed] d2}];
   PDF[dd, x]

in the result, I find a strange thing:

 3/8   False != x && True == x   
 5/8   False == x && True != x
 1     False == x && True == x
 0      True

for this, I have some doubts about False == x && True == x.

How to explain this thing

$\endgroup$
4
  • 3
    $\begingroup$ I don't believe that expr in TransformedDistribution can be an inequality. You can however calculate the Probability of the inequality being True: p = Probability[x > y, {x \[Distributed] d1, y \[Distributed] d2}] evaluates to 3/8 $\endgroup$
    – Bob Hanlon
    Dec 1, 2016 at 4:46
  • $\begingroup$ Hi Bob Hanlon; can you flesh that out a bit, so I can upvote? $\endgroup$
    – bobbym
    Dec 1, 2016 at 4:56
  • 1
    $\begingroup$ @bobbym - you need to use @username to have the user receive a notification. Also in @username all spaces need to be removed from the user name. $\endgroup$
    – Bob Hanlon
    Dec 1, 2016 at 5:51
  • $\begingroup$ @BobHanlon. I thought you were still hanging around so I got lazyl. My apologies. $\endgroup$
    – bobbym
    Dec 1, 2016 at 9:54

2 Answers 2

3
$\begingroup$
Clear[d1, d2, x, y, dd]
d1 = EmpiricalDistribution[{6, 65/10, 7, 75/10, 8}];
d2 = EmpiricalDistribution[{3, 45/10, 6, 75/10, 9, 105/10, 12, 135/10}];

The expr in TransformedDistribution, e.g., TransformedDistribution[expr, {Subscript[x, 1] \[Distributed] Subscript[dist, 1], Subscript[x, 2] \[Distributed] Subscript[dist, 2] , …}] should be a function of the random variables rather than a predicate (Boolean-valued expression such as an inequality). For a predicate you would use Probability to determine the probability of the event represented by the predicate: Probability[pred, {Subscript[x, 1] \[Distributed] Subscript[dist, 1], Subscript[x, 2] \[Distributed] Subscript[dist, 2], …}]

dd = TransformedDistribution[
   x - y, {x \[Distributed] d1, y \[Distributed] d2}];

pdf = PDF[dd, x]

(*  1/40 Boole[6 == 3 + x] + 1/40 Boole[6 == 9/2 + x] + 1/40 Boole[6 == 6 + x] + 
 1/40 Boole[6 == 15/2 + x] + 1/40 Boole[6 == 9 + x] + 
 1/40 Boole[6 == 21/2 + x] + 1/40 Boole[6 == 12 + x] + 
 1/40 Boole[6 == 27/2 + x] + 1/40 Boole[13/2 == 3 + x] + 
 1/40 Boole[13/2 == 9/2 + x] + 1/40 Boole[13/2 == 6 + x] + 
 1/40 Boole[13/2 == 15/2 + x] + 1/40 Boole[13/2 == 9 + x] + 
 1/40 Boole[13/2 == 21/2 + x] + 1/40 Boole[13/2 == 12 + x] + 
 1/40 Boole[13/2 == 27/2 + x] + 1/40 Boole[7 == 3 + x] + 
 1/40 Boole[7 == 9/2 + x] + 1/40 Boole[7 == 6 + x] + 
 1/40 Boole[7 == 15/2 + x] + 1/40 Boole[7 == 9 + x] + 
 1/40 Boole[7 == 21/2 + x] + 1/40 Boole[7 == 12 + x] + 
 1/40 Boole[7 == 27/2 + x] + 1/40 Boole[15/2 == 3 + x] + 
 1/40 Boole[15/2 == 9/2 + x] + 1/40 Boole[15/2 == 6 + x] + 
 1/40 Boole[15/2 == 15/2 + x] + 1/40 Boole[15/2 == 9 + x] + 
 1/40 Boole[15/2 == 21/2 + x] + 1/40 Boole[15/2 == 12 + x] + 
 1/40 Boole[15/2 == 27/2 + x] + 1/40 Boole[8 == 3 + x] + 
 1/40 Boole[8 == 9/2 + x] + 1/40 Boole[8 == 6 + x] + 
 1/40 Boole[8 == 15/2 + x] + 1/40 Boole[8 == 9 + x] + 
 1/40 Boole[8 == 21/2 + x] + 1/40 Boole[8 == 12 + x] + 
 1/40 Boole[8 == 27/2 + x]  *)

Then for the distribution of x-y the probability that x > y is

1 - CDF[dd, 0]

(*  3/8  *)

Or using Probability

p = Probability[x > y, {x \[Distributed] d1, y \[Distributed] d2}]

(*  3/8  *)
$\endgroup$
1
  • $\begingroup$ thanks for the follow up, it clears up some problems for me. +1 $\endgroup$
    – bobbym
    Dec 1, 2016 at 9:55
1
$\begingroup$

It seems the code produced by TransformedDistribution[x > y,..] calculates the probability accurately, even if it contains impossible cases and redundant conditions for the intended input. It is, of course, a discrete PDF. The input should be Boolean, either True or False.

Note PDF[dd] or PDF[dd][x] produces a somewhat more sensible-looking function.

PDF[dd][x] 

Mathematica graphics

The following will simplify the extraneous conditions in the OP's PDF[dd, x]. It seems hard to get rid of the last one (the default), without rewriting the expression. (This is true in general about the default case of Piecewise.)

Simplify[PDF[dd, x], TransformationFunctions -> {Automatic, Reduce[#, x] &}]

Mathematica graphics

And an explicit value works fine, too:

PDF[dd, True]
(*  3/8  *)
$\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.