How can I do bivariate numerical integration in Matlab for computing joint probabilities?

Hi all, I have to compute the probabilities listed below for each row i of the matrices b and c. I assume that (u_1,u_2) are distributed as a bi-variate normal with mean mu and var-cov matrix sigma. Could you help me please?
b= unidrnd(10,100,2);
c= unidrnd(10,100,2);
sigma=[1 0.3;0.3 1];
mu=[0 0];
(1) Pr(u_1<-b(i,1); u_2<-b(i,2))
(2) Pr(u_1>=-c(i,1); u_2>=-c(i,2))
(3) Pr(u_1>-b(i,1); u_2<-b(i,2))
(4) Pr(u_1>-c(i,1);-b(:,2)<=u_2<=-c(i,2))
(5) Pr(u_1>-b(i,1); u_2<-c(i,2))
(6) Pr(u_1<-c(i,1); u_2> -c(i,2))
(7) Pr(u_1<-b(i,1);-b(:,2)<=u_2<=-c(i,2)
(8) Pr(u_1<-c(i,1); u_2>-b(i,2))

 Accepted Answer

These can all be expressed in terms of the 'mvncdf' function. For (1) it would be:
P1 = mvncdf(-b,mu,sigma);
For (4) it would be: (I assume you meant "Pr(u_1>-c(i,1);-b(i,2)<=u_2<=-c(i,2))" rather than "Pr(u_1>-c(i,1);-b(:,2)<=u_2<=-c(i,2))" .)
P4 = mvncdf([-c(:,1),-b(:,2)],[repmat(inf,size(b,1),1),-c(:,2)],mu,sigma);
This latter uses the "rectangle" form of the 'mvncdf' call.
I think you should be able to work out the remaining cases for yourself using the concepts demonstrated here.

3 Comments

Thank you, but I have some doubts regarding (2):
b= unidrnd(10,100,2);
c= unidrnd(10,100,2);
sigma=[1 0.3;0.3 1];
mu=[0 0];
%(2) Pr(u_1>=-c(i,1); u_2>=-c(i,2))
P21=mvncdf([-c(:,1), -c(:,2)],[inf*ones(size(c,1),1), inf*ones(size(c,1),1)], mu, sigma);
% or, using the property of the cdf
P22=1-mvncdf(-c, mu, sigma);
% I expect sum(P21-P22) to be almost zero, but it is not!
Do you know why?
I agree with your method for P21. However, I see no reason why you should expect that sum(P21-P22) to be almost zero. P22 includes all the cases where u_1>-c(i,1) OR u_2>-c(i,2) which will in general be a lot larger than P21 which contain those where u_1>-c(i,1) AND u_2>-c(i,2). What I am saying is that P21 contains a rectangle, whereas P22 contains everything outside the diagonally opposite rectangle and is therefore much larger. You have received a sizable negative value for sum(P21-P22). Am I right?

Sign in to comment.

More Answers (0)

Asked:

on 9 Feb 2014

Commented:

on 9 Feb 2014

Community Treasure Hunt

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

Start Hunting!