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?
Answer
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.
Comments
Post a Comment