Generating correlated random variables

28 visualizaciones (últimos 30 días)
Máté Kardos
Máté Kardos el 14 de Dic. de 2016
Comentada: Máté Kardos el 15 de Dic. de 2016
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!

Respuesta aceptada

the cyclist
the cyclist el 14 de Dic. de 2016
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)

Más respuestas (0)

Categorías

Más información sobre Probability Distributions and Hypothesis Tests en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by