2
$\begingroup$

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?

$\endgroup$

2 Answers 2

2
$\begingroup$

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[Statistics`Library`ConditionalDistribution[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 Statistics`Library`ConditionalDistribution[] is used to represent the distribution induced by the conditional expectation. Notice that both PDF[Statistics`Library`ConditionalDistribution[x < 1, {x, y} \[Distributed] BinormalDistribution[{0, 0}, {1, 1}, 7/10]], {x, y}] and PDF[Statistics`Library`ConditionalDistribution[y == 2, {x, y} \[Distributed] BinormalDistribution[{0, 0}, {1, 1}, 7/10]], {x, y}] evaluate to expressions, but PDF[Statistics`Library`ConditionalDistribution[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.

$\endgroup$
1
  • $\begingroup$ 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.}] $\endgroup$ Commented Mar 6, 2018 at 9:52
0
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ @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. $\endgroup$
    – gwr
    Commented Mar 20, 2018 at 19:10

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.