Integrating a bivariate distribution over a region bounded by a straight line
EDITED
As suggested by JimB I added the -y
to gx[x_,Y_]
.
mu1 = 0; sig1 = 0.1; mu2 = 0; sig2 = 0.05; corr = 0;jointdist =
MultinormalDistribution[{mu1, mu2}, {{sig1^2, 0}, {0, sig2^2}}];
cplot = ContourPlot[{PDF[jointdist, {x, y}]}, {x, -0.15,
0.15}, {y, -0.05, 0.05}, Contours -> 10];
myFxy[x_, y_] :=
31.830988618379067` E^(1/
2 (-x (0.` + 99.99999999999999` x) -
y (0.` + 399.99999999999994` y)));
coeffNorm = {0.0485058025031513, -0.006616445600455179};
xVec = D[myFxy[x, y], x] /. {x -> coeffNorm[[1]], y -> coeffNorm[[2]]};
yVec = D[myFxy[x, y], y] /. {x -> coeffNorm[[1]], y -> coeffNorm[[2]]};
gx[x_, y_] = -xVec/yVec*(x - coeffNorm[[1]]) + coeffNorm[[2]] - y
rgplot = RegionPlot[gx[x, y] >= 0, {x, -0.15, 0.15}, {y, -0.05, 0.05}];
Show[cplot, rgplot]
NProbability[
gx[x, y] >= 0 && -Infinity < x < Infinity && -Infinity < y <
Infinity, {x, y} \[Distributed] jointdist]
0.307558
expr = y <= -xVec/yVec*(x - coeffNorm[[1]]) + coeffNorm[[2]];
With the default value of 0
for the option MinRecursion
NIntegrate may miss sharp peaks of integrands
Setting a larger value for this option forces a finer subdivision of the integration region:
NIntegrate[PDF[jointdist, {x, y}] Boole[expr], {x, -∞, ∞}, {y, -∞, ∞}, MinRecursion -> 5]
0.3075579043682307`
We get the same result using NProbability
and NExpectation
with the option Method -> {"NIntegrate", MinRecursion -> 5}
:
NProbability[expr, Distributed[{x, y} jointdist],
Method -> {"NIntegrate", MinRecursion -> 5}]
0.3075579043682307`
NExpectation[Boole@expr, Distributed[{x, y} jointdist],
Method -> {"NIntegrate", MinRecursion -> 5}]
0.3075579043682307`
If you Rationalize
the numeric inputs as suggested by JimB
{mu1, mu2, sig1, sig2, coeffNorm} = Rationalize[{mu1, mu2, sig1, sig2, coeffNorm}, 0];
and add the option WorkingPrecision ->20
, NIntegrate
gives
0.307557904886364251344772597476334481735556904662953985238`20.
and NProbability
and NExpectation
both give
0.307557904886364251344772597487160029314983328842092855138`20.