Summary of problem: I'm using Mathematica version 8 to try to integrate the bivariate distribution over a region bounded by a straight line. The two random variables are uncorrelated. When I use Nintegrate
, I get the following error message:
"NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small."
Do I simply have to live with this problem or is there something I can do to get rid of the error message and gain assurance that my result is correct?
Model: I give an example using the Bivariate Normal, though I find that this problem also exists with other distributions linked using the product copula.
Assume that the bivariate distribution is given by:
mu1 = 0; sig1 = 0.1; mu2 = 0; sig2 = 0.05; corr = 0; jointdist =
MultinormalDistribution[{mu1, mu2}, {{sig1^2, 0}, {0, sig2^2}}];
Definition of the region: We have a point on the Cartesian plane which we will use to determine the straight line that defines the region. This is calculated as
coeffNorm = {0.0485058025031513, -0.006616445600455179};
The straight line (defining the region to be integrated) is the projection of the tangent to the joint PDF
going through that point. This is calculated and visualized as follows (on the Cartesian plane):
PDF[jointdist, {x, y}];
myFxy[x_, y_] :=
31.830988618379067` E^(
1/2 (-x (0.` + 99.99999999999999` x) -
y (0.` + 399.99999999999994` y)));
xVec = D[myFxy[x, y], x] /. {x -> coeffNorm[[1]], y -> coeffNorm[[2]]};
yVec = D[myFxy[x, y], y] /. {x -> coeffNorm[[1]], y -> coeffNorm[[2]]};
Show[RegionPlot[
PDF[jointdist, {x, y}] >= contourval, {x, -0.15, 0.15}, {y, -0.05,
0.05}], Plot[-xVec/yVec*(x - coeffNorm[[1]]) +
coeffNorm[[2]], {x, -7, 3}],
Graphics[Point[{coeffNorm[[1]], coeffNorm[[2]]}]]];
The region over which the PDF to be integrated is visualized as follows (though it extends to infinity in both directions):
RegionPlot[
y <= -xVec/yVec*(x - coeffNorm[[1]]) + coeffNorm[[2]], {x, -0.15,
0.15}, {y, -0.05, 0.05}];
Integral: So the probability that I wish to calculate is given by:
NIntegrate[
PDF[jointdist, {x, y}]*
Boole[y <= -xVec/yVec*(x - coeffNorm[[1]]) +
coeffNorm[[2]]], {x, -Infinity, Infinity}, {y, -Infinity,
Infinity}, WorkingPrecision -> 20];
Error message: I get a numerical output (a value of 0.30755790488620519025), but an error message also. I've extended the WorkingPrecision
to 20 as a result of getting the error, but this doesn't seem to help. I get the following errors:
"NIntegrate::precw: The precision of the argument function (31.831 E^(1/2 (-x (0. +100. x)-y (0. +400. y))) Boole[y<=-0.00661645+1.83277 (-0.0485058+x)] ) is less than WorkingPrecision (20.`). >>
NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. >>"
Can you suggest how I can improve my code to get rid of these errors? I would not have expected the second one, given that the Normal distribution is quite well behaved. Regarding the first one, does it mean that I need to improve the working precision of all of the calculations that I use to derive the numbers going into the specification of the distribution, or is there something else I should do? How accurate is the integral that is being calculated?
Rationalize
all of the constants, you'll get rid of the first warning but not the second. In other words, usesig1 = 1/10;
andRationalize[coeffNorm,0]
, etc. $\endgroup$contourval
. It should becontourval = PDF[jointdist, coeffNorm]
. $\endgroup$