6
$\begingroup$

I have two discrete random variavles; $X$ and $Y$ with:

enter image description here

And I want to calculate $Cov(Y,Y+e^X)$, and I've tried the following:

\[ScriptCapitalD] = EmpiricalDistribution[{1/8, 2/8, 5/8} -> {1, 2, 3}];
\[ScriptCapitalD]1 = EmpiricalDistribution[{1/5, 4/5} -> {-1, 1}];
Covariance[\[ScriptCapitalD]1, \[ScriptCapitalD]1 + e^\[ScriptCapitalD]]

But this doesnt return any value, what am I doing wrong?

I have also tried calculating stuff like $P(X=3,Y=1)$ and $P(X\cdot Y \geq 2)$ without any luck

$\endgroup$
3
  • 1
    $\begingroup$ And $X$ and $Y$ are independent? $\endgroup$
    – JimB
    Commented Dec 20, 2016 at 18:13
  • $\begingroup$ Yes, they are, forgot to mention. $\endgroup$
    – Ahmed C.
    Commented Dec 20, 2016 at 19:12
  • 1
    $\begingroup$ This isn't a fix of your problem, but you should be aware that there's no such thing as e; there's E - Mathematica is case sensitive. $\endgroup$
    – corey979
    Commented Dec 20, 2016 at 19:51

2 Answers 2

12
$\begingroup$

This solution uses built-in functions :

dx = EmpiricalDistribution[{1/8, 2/8, 5/8} -> {1, 2, 3}];
dy = EmpiricalDistribution[{1/5, 4/5} -> {-1, 1}];
Covariance[
 TransformedDistribution[{y, y + Exp[x]}, {x \[Distributed] dx, 
   y \[Distributed] dy}], 1, 2]
(* 16/25 *)
$\endgroup$
5
$\begingroup$

To calculate these kinds of expressions, use Expectation:

\[ScriptCapitalD] = EmpiricalDistribution[{1/8, 2/8, 5/8} -> {1, 2, 3}];
\[ScriptCapitalD]1 = EmpiricalDistribution[{1/5, 4/5} -> {-1, 1}];

mu = Expectation[Exp[x], x \[Distributed] \[ScriptCapitalD]]
mu1 = Expectation[y, y \[Distributed] \[ScriptCapitalD]1]

Expectation[(y - mu1) (y + Exp[x] - mu1 - mu), {x \[Distributed] \[ScriptCapitalD], y \[Distributed] \[ScriptCapitalD]1}]
$\endgroup$
1
  • 1
    $\begingroup$ Mathematica 10.4.1 needs a Simplify or Expand applied to the last line to simplify to the answer of 16/25. $\endgroup$
    – JimB
    Commented Dec 20, 2016 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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