Generating correlated random variables

조회 수: 28 (최근 30일)
Máté Kardos
Máté Kardos 2016년 12월 14일
댓글: Máté Kardos 2016년 12월 15일
Dear all,
I have already been reading a little bit about this issue, and I see, that if the variables are not normally distributed, the problem is not at all trivial.
My specific problem is: I need three variables; first and second has lognormal distribution (mu1, sigma1, mu2, sigma2 specified). The third variable has uniform distribution on a given interval. Even the full (3x3) correlation matrix is specified.
For the first two variables I can use MvLogNRand on File Exchange, but can't cope with the third one. I don't know if copula method works here. Code from stat gurus would be appreciated.
Thanks in advance!

채택된 답변

the cyclist
the cyclist 2016년 12월 14일
The Higher-Order Copulas section of the documentation on Simulating Dependent Random Variables Using Copulas has a very good explanation of the general approach.
The first example in that section shows how to generate three correlated distributions. I've adapted that to your case, using two lognormals and one uniform distribution. Note that it is crucial that MATLAB has the ability to generate the inverses of all those distributions, because that is key to the copula method.
mu1 = 0;
sigma1 = 0.5;
mu2 = 0;
sigma2 = 0.5;
a3 = 0;
b3 = 1;
figure
% subplot(1,1,1);
n = 5000;
Rho = [1.0 0.4 0.2;
0.4 1.0 -0.8;
0.2 -0.8 1.0];
Z = mvnrnd([0 0 0], Rho, n);
U = normcdf(Z,0,1);
X = [logninv(U(:,1),mu1,sigma1) logninv(U(:,2),mu2,sigma2) unifinv(U(:,3),a3,b3)];
plot3(X(:,1),X(:,2),X(:,3),'.');
grid on;
view([-55, 15]);
xlabel('U1');
ylabel('U2');
zlabel('U3');
figure
subplot(3,1,1); histogram(X(:,1)); xlabel('U1')
subplot(3,1,2); histogram(X(:,2)); xlabel('U2')
subplot(3,1,3); histogram(X(:,3)); xlabel('U3')
See the resulting distributions below. They distributions also have the expected correlation structure, as can be shown using
corr(X)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Probability Distributions and Hypothesis Tests에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by