I have found that Expectation
gives different results if I use the fact that expectation is linear and evaluate it on every term independently.
I reduced my problem to the following code snippet. I use Mathematica 10.0.2:
f = x1 + x1 x2 z;
d = BernoulliDistribution[1/2 - z];
t = TransformedDistribution[
f, {x1 \[Distributed] d, x2 \[Distributed] d}];
e[x_] :=
Expand @ Simplify[Expectation[x, {x1 \[Distributed] d, x2 \[Distributed] t}]]
e[f]
Total[e /@ List @@ f]
Since expectation is linear, the last two expressions should evaluate to the same expression, but they don't. I get instead:
1/2 - (3 z)/4 - (7 z^2)/8 + z^3/4 + (3 z^4)/2 - z^5
3/4 - (15 z)/8 + z^2/4 + (3 z^3)/2 - z^4
Is my understanding correct and this is a bug, or Mathematica is correct and I got it wrong?
FullForm@f
givesPlus[x1,Times[x1,x2,z]]
andList @@ f
gives{x1, x1 x2 z}
. But the expectation of a product of independent random variables is the product of their expectations, not their sum.Expectation
expects all listed distributions to be independent of each other. $\endgroup$z
is set to some specific value between 0 and 1/2 (prior to definingf
). $\endgroup$