Generating correlated random numbers

8 ビュー (過去 30 日間)
Stavros Zanos
Stavros Zanos 2013 年 7 月 22 日
編集済み: krana 2017 年 12 月 29 日
I have 2 independent variables X={x1,x2,...,xn} and Y={y1,y2,...,yn}.
I want to generate a random dependent variable Z={z1,z2,...,zn} that will bear a correlation coefficient Czx with X and Czy with Y.
I found the way to do this for one independent variable X that takes values between 0 and 1:
Z = Czx * rand(n,1) + sqrt(1-Czx^2)*X
It's not clear to me how to do that for two independent variables that both are correlated to Z and can take values from different ranges (e.g. 0<X<1 and 1<Y<10).
Any help will be appreciated.

回答 (1 件)

krana
krana 2017 年 12 月 29 日
編集済み: krana 2017 年 12 月 29 日
I guess I'm a little late here but perhaps some other people might find this response useful. I created this simple function that I used as a workaround.
% code
function [Zv Zs]= randomcorrelatednum(rho)
Zv= rand(1);
Zs = rho*Zv + sqrt(1-rho^2)*rand(1);
while Zv> 1.00000001
Zv= rand(1);
Zs = rho*Zv + sqrt(1-rho^2)*rand(1);
end
end

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by