# Why does conditional NExpectation fail for a multivariate distribution?

To give an example for a multiparametric distribution let us take a binormal distribution:

binormalDist = With[
{
μ = { 0, 0 },
σ = { 1, 1 },
ρ = 7/10
},
BinormalDistribution[ μ, σ, ρ ]
];


Calculating the conditional expectation in simple cases works out:

NExpectation[2 x + 3 \[Conditioned] x < 1., {x, y} \[Distributed] binormalDist ]


2.4248

and so does this too:

NExpectation[2 x + 3 \[Conditioned] y == 2., {x, y} \[Distributed] binormalDist ]


5.8

but

NExpectation[2 x + 3 \[Conditioned] (x < 1 && y == 2.), {x, y} \[Distributed] binormalDist ]


is returned unevaluated (as is Expectation with identical args)

NExpectation[ 3+ 2 x [Conditioned] x < 1 && y == 2., {x, y} [Distributed] BinormalDistribution[{0, 0}, {1, 1}, 7/10]]

Why? And how can it be solved?

Since

Probability[x < 1 && y == 2,
{x, y} \[Distributed] BinormalDistribution[{0, 0}, {1, 1}, 7/10]]
0


and the PDF of the purported conditional distribution has that expression as a denominator, this may be the reason why your attempt remains unevaluated.

Using Method -> "Trace", we see that NExpectation[] is attempting to evaluate the following expression internally:

NIntegrate[(3 + 2 x)
PDF[StatisticsLibraryConditionalDistribution[x < 1 && y == 2,
{x, y} \[Distributed] BinormalDistribution[{0, 0}, {1, 1}, 7/10]], {x, y}],
{x, -∞, ∞}, {y, -∞, ∞}, AccuracyGoal -> ∞, Compiled -> Automatic,
PrecisionGoal -> Automatic, WorkingPrecision -> MachinePrecision,
MinRecursion -> 1]


where we see that StatisticsLibraryConditionalDistribution[] is used to represent the distribution induced by the conditional expectation. Notice that both PDF[StatisticsLibraryConditionalDistribution[x < 1, {x, y} \[Distributed] BinormalDistribution[{0, 0}, {1, 1}, 7/10]], {x, y}] and PDF[StatisticsLibraryConditionalDistribution[y == 2, {x, y} \[Distributed] BinormalDistribution[{0, 0}, {1, 1}, 7/10]], {x, y}] evaluate to expressions, but PDF[StatisticsLibraryConditionalDistribution[x < 1 && y == 2, {x, y} \[Distributed] BinormalDistribution[{0, 0}, {1, 1}, 7/10]], {x, y}] does not.

If you think Mathematica should be able to evaluate combined conditions like in the OP, you could try writing a suggestion to support.

• Yes, this probability is 0, that's the correct answer. But instead of this results, conditional expected value has a correct value 0.458101 via the formula NIntegrate[(2 x + 3)* E^(-((x^2 - 2 *0.7 x*2 *2 + 2^2)/(2 (1 - 0.7^2))))/( 2 \[Pi] Sqrt[1 - 0.7^2]), {x, -\[Infinity], 1.}] Commented Mar 6, 2018 at 9:52

As can be seen from Wikipedia for two continuous random variables the conditional expectation is given as:

\begin{align} \mathbb{E}\left(X|Y=y\right) = \int_\mathcal{X}x \frac{f_{X,Y}(x,y)}{f_Y(y)}dx \end{align}

So with the corresponding definitions:

distXY = BinormalDistribution[ {0, 0}, {1, 1}, 7/10 ];

fY[2] = PDF[ MarginalDistribution[ distXY, 2], 2 ]; (* a constant value > 0 *)

fXY[x_, 2] = PDF[ distXY, {x, 2} ];


I would assume that we then get the conditional expectation as:

condExp = 1/fy[2] NIntegrate[ (2 x + 3) fXY[x,2], {x,-∞, 1} ]


1.18159

• @JimB Excuse my ping, but I am quite sure, you would no the correct result here or could point me into the right direction. I would greatly appreciate your help here.
– gwr
Commented Mar 20, 2018 at 19:10