Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Generation of Correlated Data
Date: Tue, 12 Aug 2008 15:26:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 32
Message-ID: <g7sa29$gnv$1@fred.mathworks.com>
References: <g7ri75$8hr$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1218554761 17151 172.30.248.38 (12 Aug 2008 15:26:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 12 Aug 2008 15:26:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:485060



"Deva MDP" <devasiri@gmail.com> wrote in message <g7ri75$8hr
$1@fred.mathworks.com>...
> Can some one tell how to generate two random data sets 
> with known correlation, (say Corr. Coef. = 0.5)

  Generate any two mutually independent variables, x and y, whose means are 
0 and variances 1.  For example x = randn(n,1) and y = randn(n,1).  Then we 
have

 E(x) = E(y) = 0,
 E(x^2) = E(y^2) = 1
 E(x*y) = E(x)*E(y) = 0

  Then construct z = x + k*y where k is some constant yet to be determined.  
Now we have

 E(z) = 0,
 E(z^2) = E(x^2) + 2*k*E(x*y) + k^2*E(y^2) = 1 + k^2,
 E(x*z) = E(x^2) + k*E(x*y) = 1

Hence

 corr(x,z) = E(x*z)/sqrt(E(x^2)*E(z^2)) = 1/sqrt(1+k^2)

Therefore solve for the value of k that gives you the desired correlation 
coefficient.  For corr = .5 it would be k = sqrt(3).

  Are you sure you don't have further requirements?  You have left a lot of 
freedom in your description here.

Roger Stafford