# Problem with mvncdf - returning NaN

조회 수: 3(최근 30일)
Georgios Apostolakis 2021년 7월 12일
댓글: Georgios Apostolakis 2021년 7월 28일
Hello, I am having some problems when using 'mvncdf'. Consider:
mu = [0.4704 14.5809];
cov = [0.0030 0.0922; 0.0922 2.8597];
xl = [8 0];
xu = [12 4];
Then, mvncdf(xl, xu, mu, cov) returns NaN but I cannot understand why. What is more, the documentation doesn't mention anything relative. And, what is even more strange, mvncdf(xu, mu, cov) - mvncdf(xl, mu, cov) (which is equivalent) returns a double, instead of Nan. Is that due to a bug in mvncdf, or do I miss something important?

댓글을 달려면 로그인하십시오.

### 채택된 답변

Paul 2021년 7월 12일
편집: Paul 2021년 7월 12일
The limits of area of integration defined in xl and xu are way, way, out in the tails of the density function, which may be why mvncdf is having an issue.
As I understand mvncdf ...let p(x1,x2) be the joint density. Then mvncdf computes the probability, P, given by:
syms p(x1,x2)
xl = sym('xl',[1 2]);
xu = sym('xu',[1 2]);
P = int(int(p,x1,xl(1),xu(1)),x2,xl(2),xu(2))
P =
First, let's take a look at the pdf as defined by the parameters in the question
mu = [0.4704 14.5809];
cov = [0.0030 0.0922; 0.0922 2.8597];
func(mu,cov);
Now, redraw but with a rectangle showing the area of integration:
xlower = [8 0];
xupper = [12 4];
func(mu,cov,xlower,xupper)
As you can see, the area of integration is way out there. I don't know why mvncdf returns NaN in this case instead of zero, but it probably has something to do with trying to integrate a function with incredibly small values.
Now try with a more reasonable area of integration
xlower = [0.4 13];
xupper = [0.5 15];
func(mu,cov,xlower,xupper);
The probability is:
mvncdf(xlower,xupper,mu,cov)
ans = 0.4229
which seems pretty reasoable.
Also, I don't think that mvncdf(xu, mu, cov) - mvncdf(xl, mu, cov) is equivalent
mvncdf(xupper, mu, cov) - mvncdf(xlower, mu, cov)
ans = 0.4985
because it includes area outside of the red rectangle, particularly the light blue region where x1 > 0.4 and x2 < 13.
function func(mu,cov,xlower,xupper)
x1 = 0.2:.001:.8;
x2 = 10:.001:18;
[X1,X2] = meshgrid(x1,x2);
X = [X1(:) X2(:)];
p = mvnpdf(X,mu,cov);
p = reshape(p,length(x2),length(x1));
figure
xlabel('x1'),ylabel('x2')
if nargin == 4
rectangle('Position',[xlower(1) xlower(2) xupper(1)-xlower(1) xupper(2)-xlower(2)],'EdgeColor','r');
axis auto
end
end
##### 댓글 수: 7표시숨기기 이전 댓글 수: 6
Georgios Apostolakis 2021년 7월 28일
Great. Thank you!!

댓글을 달려면 로그인하십시오.

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by