I would like to know how to implement a bivariate normal distribution.

I have the following formula(see picture) and I know that
R=-2.25 rhoR=0.5 and the result I should get is ~0.17%.
I read the instructions on Mathworks for the mvnpdf but I dont know how to use it with my data.
I am thankful for any help and suggestions on how I need to enter my data into the formula.

 Accepted Answer

rhoR=0.5;
fun=@(x,y)1/(2*pi*sqrt(1-rhoR^2))*exp(-1/(2*(1-rhoR^2))*(x.^2-2*rhoR*x.*y+y.^2));
intfun=@(R)integral2(fun,-Inf,R,-Inf,R)-0.0017;
R0=-2.25;
sol=fzero(intfun,R0)
gives you the R-value for which the integral equals 0.17 %.
Btw: The "pi" in the exponential term seems to be wrong.
Best wishes
Torsten.

2 Comments

Correct. pi does not belong inside the exponential there.
Thanks! So I guess they wrote it wrong in the paper but since they got the same result as I got using the mvncdf, the probably calculated it using the correct formula.

Sign in to comment.

More Answers (1)

Using the stats toolbox, you want to use mvncdf, not mvnpdf anyway. (Ok, you could integrate the pdf. But why would you here?)
R = -2.25;
rhoR=0.5;
mvncdf([R,R],[0 0],[1 rhoR;rhoR 1])
ans =
0.0017093
Which is roughly 0.17%.
Note that mvncdf expects a covariance matrix. And you have supplied a correlation, not apparently a covariance. But since the presumed variances were 1 by default, the correlation matrix will be the same as the covariance matrix here.

1 Comment

Thanks so much! That is how I implemented it and it obviously worked.

Sign in to comment.

Categories

Tags

Asked:

on 15 May 2018

Edited:

on 19 May 2018

Community Treasure Hunt

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

Start Hunting!