How to generate random numbers correlated to a given dataset in matlab

조회 수: 6 (최근 30일)
Paba
Paba 2015년 7월 28일
댓글: Dian Fan 2020년 4월 21일
I have a matrix x with 10,000 rows and 20 columns. I want to generate another new matrix of random numbers , y, where y is correlated to x with correlation coefficient q.
Note that the matrix x is not normally distributed - it has the power law distribution.

답변 (2개)

John D'Errico
John D'Errico 2015년 7월 28일
편집: John D'Errico 2015년 7월 29일
Ah. Every once in a while, I see a question come up that is interesting. In this case, it should not be difficult to do. In fact, I can see at least one solution, and maybe a second way to do so. (I'll post an answer later today. Must run out now. Sorry, but at least you can know to expect an answer if nobody else gives you one.)
A question first though. Since the mean of a variable has no impact on the correlation, do you care what the mean of y will be? Or can it simply have mean 0?
Next, I assume you mean the traditional correlation coefficient, thus the Pearson version?
Hmm, as I think, a more interesting question is, given a set of n variables, with their own set of inter-correlations, is can we choose a new variable that has a given set of n specified correlations with each of those n variables? And I think the answer is yes, of course we can do so, as long as we have sufficient degrees of freedom.
Before I go for now though, here is a fun paper on the subject.
Later... (m-file solution attached to this answer.)
The basic idea is for a variable x, find a new vector y0, such that y0 is orthogonal to x. Then choose some linear combination of x and y0 that has the desired correlation.
  댓글 수: 7
Aditya Nanda
Aditya Nanda 2019년 1월 17일
Thanks for the great answer, John.
I am working on the exact problem you mention in your answer.
Hmm, as I think, a more interesting question is, given a set of n variables, with their own set of inter-correlations, is can we choose a new variable that has a given set of n specified correlations with each of those n variables?
Can this be done? Please help! The correlation is the cosine of angle between two vectors (length is n). Can we construct a new vector that has specified correlations to existing vectors . All the vectors $x_1, x_2 \,\, \mathrm{etc. } $ are n-dimensional vectors and n>m
Dian Fan
Dian Fan 2020년 4월 21일
John, the file only works for rho=1 or -1? It is strange that a non-unity rho gives errors.

댓글을 달려면 로그인하십시오.


Josué Ortega
Josué Ortega 2017년 9월 14일
편집: Josué Ortega 2017년 9월 14일
This is a great answer @John D'Errico, but I have a further question. Suppose I have a vector 2 1 3 5 4 ... 10 of 10 numbers, from 1 to 10, ordered randomly, could be generated by
x=randperm(10).'
Now I want to generate another vector of 10 numbers, containing all numbers from 1 to 10 again, that has a correlation of at least p with my previous vector x. Any ideas? Your code works but of course produces real numbers between -1 and 1.

카테고리

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