Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Integrate Bivariate Lognormal

Subject: Integrate Bivariate Lognormal

From: Bob Johnson

Date: 25 Sep, 2010 05:24:09

Message: 1 of 5

Hi,

I have a question about integrating a bivariate lognormal distirbution. Suppose the inner integral is over x and the outer integral is over y. I would like to integrate the bivariate lognormal over x from 0 to a function of y, and y from 0 to infinity (i.e. - a large number). Does anyone know the best way to do this? If you can point me in the direction of some code that you think accomplishes this, I would really appreciate. I tried to do a change of variables and then calculate the resulting double integral over the resulting region with the dblquad function, but the result I get is greater than 1, so that can't be correct. Any help would be greatly appreciated.

Thanks.

All the best,
Bob

Subject: Integrate Bivariate Lognormal

From: Roger Stafford

Date: 26 Sep, 2010 03:23:03

Message: 2 of 5

"Bob Johnson" <michorig@yahoo.com> wrote in message <i7k11p$jtt$1@fred.mathworks.com>...
> Hi,
>
> I have a question about integrating a bivariate lognormal distirbution. Suppose the inner integral is over x and the outer integral is over y. I would like to integrate the bivariate lognormal over x from 0 to a function of y, and y from 0 to infinity (i.e. - a large number). Does anyone know the best way to do this? If you can point me in the direction of some code that you think accomplishes this, I would really appreciate. I tried to do a change of variables and then calculate the resulting double integral over the resulting region with the dblquad function, but the result I get is greater than 1, so that can't be correct. Any help would be greatly appreciated.
>
> Thanks.
>
> All the best,
> Bob
- - - - - - - - - - -
  The quad2d function computes a double integral in which the inner integration limits are allowed to be variable. That should be very convenient for you.

  As for your attempt to make a change of variables, did you make a correction with the appropriate Jacobian? If you did this correctly, that should also give you a valid integration with dblquad.

Roger Stafford

Subject: Integrate Bivariate Lognormal

From: Bob Johnson

Date: 26 Sep, 2010 20:52:04

Message: 3 of 5

Roger, thank you very much for your suggestion. I really appreciate it. That function will work well.

Right now, I am trying to use the multivariate normal, to check my understanding of the functions dblquad, quad2d, before I move on to the bivariate lognormal, which is what I'm really interested in.

Do you happen to know if there is a way to use mvncdf.m with variable limits on the inner integration, for a bivariate normal. That would be helpful for me to check what I'm doing. I looked at the documentation, it appears to me that the function only allowed fixed limits of integration, and I can't think of a creative way to get around that. Thanks for all of your help.

All the best,
Bob


"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i7mean$20d$1@fred.mathworks.com>...
> "Bob Johnson" <michorig@yahoo.com> wrote in message <i7k11p$jtt$1@fred.mathworks.com>...
> > Hi,
> >
> > I have a question about integrating a bivariate lognormal distirbution. Suppose the inner integral is over x and the outer integral is over y. I would like to integrate the bivariate lognormal over x from 0 to a function of y, and y from 0 to infinity (i.e. - a large number). Does anyone know the best way to do this? If you can point me in the direction of some code that you think accomplishes this, I would really appreciate. I tried to do a change of variables and then calculate the resulting double integral over the resulting region with the dblquad function, but the result I get is greater than 1, so that can't be correct. Any help would be greatly appreciated.
> >
> > Thanks.
> >
> > All the best,
> > Bob
> - - - - - - - - - - -
> The quad2d function computes a double integral in which the inner integration limits are allowed to be variable. That should be very convenient for you.
>
> As for your attempt to make a change of variables, did you make a correction with the appropriate Jacobian? If you did this correctly, that should also give you a valid integration with dblquad.
>
> Roger Stafford

Subject: Integrate Bivariate Lognormal

From: Roger Stafford

Date: 27 Sep, 2010 00:23:03

Message: 4 of 5

"Bob Johnson" <michorig@yahoo.com> wrote in message <i7obpk$p5t$1@fred.mathworks.com>...
> Roger, thank you very much for your suggestion. I really appreciate it. That function will work well.
>
> Right now, I am trying to use the multivariate normal, to check my understanding of the functions dblquad, quad2d, before I move on to the bivariate lognormal, which is what I'm really interested in.
>
> Do you happen to know if there is a way to use mvncdf.m with variable limits on the inner integration, for a bivariate normal. That would be helpful for me to check what I'm doing. I looked at the documentation, it appears to me that the function only allowed fixed limits of integration, and I can't think of a creative way to get around that. Thanks for all of your help.
>
> All the best,
> Bob
- - - - - - - - -
  As to using mvncdf for your purposes, if your inner variable limit were a linear function of the outer variable, I think you could adapt mvncdf to your purpose by redefining the variables involved linearly so that the limits would be changed from some wedge shape to the constant limits that mvncdf can handle. However it would mean recalculating the covariance and perhaps the mean values appropriately. If the inner limit is not a linear function, this wouldn't work, because only a linear transformation will preserve the jointly Gaussian nature of the distribution.

  If you simply want to check your methods, why not devise some simple double integral problem with variable inner limits where you already know the answer from elementary calculus? You could compare that with the results from quad2d and see how well it lives up to the tolerance you set for it.

Roger Stafford

Subject: Integrate Bivariate Lognormal

From: Bob Johnson

Date: 27 Sep, 2010 15:59:20

Message: 5 of 5

Thanks, Roger.

I have used the quad2d function with constant limits, and setting the pdf value to 0 outside of my region of integration, and with accept-reject monte carlo, and I am able to get the same answer (prob =0.249114631640137). However, when I try to use the variable limit, I don't get the same answer..not even close. I was wondering if you might be able to spot the mistake. I guess I'm wondering if I have the syntax for the quad2d command correct. I would like to integrate the bivariate lognormal from with x (outer integral) from 0 to inf, and y (inner integral) from 0 to x-1. Thanks a lot for your help.

M = 40;

mu = [-0.9498 0.0337];
sigma = [0.0118 0.0132;0.0132 0.1955];

inner_up_bound = @(x) x-1;

a = 0;
b = M;
c = 0;
d = inner_up_bound;

bind1 = @(x,y) func_mvlognpdf_quad2d(x,y,mu,sigma);
val1 = quad2d(bind1,a,b,c,d);

function [z] = func_mvlognpdf_quad2d(x,y,mu,sigma)
[m,n] = size(x);
x_vec = reshape(x,m*n,1);
y_vec = reshape(y,m*n,1);
log_x_vec = log(x_vec);
log_y_vec = log(y_vec);
z_vec = 1./(x_vec.*y_vec).*mvnpdf([log_x_vec log_y_vec],mu,sigma);
z = reshape(z_vec,m,n);

All the best,
Bob


> As to using mvncdf for your purposes, if your inner variable limit were a linear function of the outer variable, I think you could adapt mvncdf to your purpose by redefining the variables involved linearly so that the limits would be changed from some wedge shape to the constant limits that mvncdf can handle. However it would mean recalculating the covariance and perhaps the mean values appropriately. If the inner limit is not a linear function, this wouldn't work, because only a linear transformation will preserve the jointly Gaussian nature of the distribution.
>
> If you simply want to check your methods, why not devise some simple double integral problem with variable inner limits where you already know the answer from elementary calculus? You could compare that with the results from quad2d and see how well it lives up to the tolerance you set for it.
>
> Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us