Finding the covariance of two discrete random variables
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 *)
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}]