Generating correlated random numbers

조회 수: 11 (최근 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 CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by