Hello there,
I am trying to use the code below to find the bivariate normal cdf
given an x-value , a y-value and a correlation r. I actually have
vectors of equal length for x,y and r. I was wondering does anyone
know how to convert from correlation to covariance matrix and means,
which is what I need to use the MATLAB code below. Given vectors (or
scalars?) x,y and r is there a formula? I apologise in advance for the
possibly trivial nature of this question but I am definitely a novice
when it comes to statistics.
Hope someone can help me.
Kind regards,
Edward
function [p, dp] = mvncdf(x,mu,sigma,n)
% MVNCDF Multivariate normal cumulative distribution function.
% P = MVNCDF(X, MU, SIGMA) returns the joint probability using
% a Monte Carlo approach. X is a vector of values, MU is the
% mean parameter vector, and SIGMA is the covariance matrix.
% [P, DP] = MVNCDF(X,MU,SIGMA, N) also returns the standard
deviation
% of P in DP.
% N is the number of random samples generated (Default: N = 10000)
% for the Monte Carlo probability estimate, P.
% Ex. [p, dp] = mvncdf([0 0],[0 0],[1 0;0 1])
% B.A. Jones 5-09-96
% Copyright (c) 1993-96 by The MathWorks, Inc.
if nargin < 4
n = 10000;
end
if size(x) ~= size(mu)
error('The first two inputs must be vectors of the same length.')'
end
dim = max(size(x));
if size(sigma) ~= [dim dim]
error('The third input must be a square matrix.');
end
r = mvnrnd(mu,sigma,n)';
x = x(:);
X = x(:,ones(n,1));
p = sum(prod(X>r))/n;
dp = sqrt(p*(1-p)/n);
.
.
=================================================================
Instructions for joining and leaving this list, remarks about the
problem of INAPPROPRIATE MESSAGES, and archives are available at:
. http://jse.stat.ncsu.edu/ .
=================================================================