Negative correlation between two random vectors
조회 수: 9 (최근 30일)
이전 댓글 표시
Hi,
I would like to know how to negatively correlate two random vectors without using any command from the Statistics and Machine learning toolbox.
Thanks in advanced
댓글 수: 2
David Goodmanson
2020년 4월 17일
Hi Richard,
if both vectors are independetly random, i,i,d, there of course will be no correlation, so what do you have in mind to alter them in order to get negative correlation? The bivariate normal distribution is one possibliity.
Image Analyst
2020년 4월 18일
What exactly does "negatively correlate" mean? I mean, if you compute the correlation coefficient, it is what it is. It might be any value between -1 and +1. What you got is what you got for your two input vectors. Might be positive, might be negative - could be whatever. Are you allowed to change anything? Like change one of the vectors like John suggested below? Otherwise, if you can't change anything, you're stuck with what you got.
답변 (2개)
John D'Errico
2020년 4월 17일
편집: John D'Errico
2020년 4월 18일
Trivial.
Generate two random vectors. As long as they are random, the probability they have a zero correlation is zero. So the correlation is either positve or negative.
0. Compute the correlation coefficient. This is trivial. Find the formula for it anywhere. I'll just use corr, since I have no need to do homework.
1. If the correlation was actually negative, then you are done.
2. If the correlation was positve, then multiply one of the vectors by -1.
For example:
x = rand(3,1)
x =
0.0938200267748656
0.525404403859336
0.530344218392863
y = rand(3,1)
y =
0.347712671277525
0.149997253831683
0.586092067231462
corr(x,y)
ans =
0.0635961821440689
So had the correlation been negative, you would be done.
y = -y;
corr(x,y)
ans =
-0.0635961821440689
Could you have done this other ways? Yes. I can think of at least a few. You did not ask for anything specific however.
댓글 수: 0
Jeff Miller
2020년 4월 18일
Alternatively, generate independent variables and then combine them to create a new variable that they are correlated with. E.g.
xp = rand(3,1);
xn = rand(3,1);
y = xp - xn; % y will be positively correlated with xp & negatively correlated with xn
% use multipliers to adjust the strength of the correlations. e.g.
y2 = 0.2*xp - 0.8*xn; % y2 has weak positive correlation with xp and strong negative with xn
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!