Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Generation of Correlated Data Date: Mon, 29 Apr 2013 20:12:12 +0000 (UTC) Organization: EDF Trading North America LLC Lines: 40 Message-ID: <klmk6s$lug$1@newscl01ah.mathworks.com> References: <g7ri75$8hr$1@fred.mathworks.com> <g7sa29$gnv$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-06-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1367266332 22480 172.30.248.38 (29 Apr 2013 20:12:12 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Mon, 29 Apr 2013 20:12:12 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2852015 Xref: news.mathworks.com comp.soft-sys.matlab:794573 Hi Roger, Is it possible to generalize this to data sets with any mean, variance and covariance? I did some calculations at home, but I find that the correlation(X,Z) does not change much from the original correlation of (X,Y) . Infact the correlation as a function of K declines asymptotically. I could be totally wrong of course - but if you provide me an email address, I can send you my file - if you care to look that is. Ty Chet "Roger Stafford" wrote in message <g7sa29$gnv$1@fred.mathworks.com>... > "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 >