How to generate random numbers correlated to a given dataset in matlab
11 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (2 件)
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
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/144741/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/144742/image.png)
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
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Random Number Generation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!