Negative correlation between two random vectors
8 次查看(过去 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!