Negative correlation between two random vectors

7 vues (au cours des 30 derniers jours)
Richard Flores
Richard Flores le 17 Avr 2020
Commenté : Image Analyst le 18 Avr 2020
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 commentaires
David Goodmanson
David Goodmanson le 17 Avr 2020
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
Image Analyst le 18 Avr 2020
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.

Connectez-vous pour commenter.

Réponses (2)

John D'Errico
John D'Errico le 17 Avr 2020
Modifié(e) : John D'Errico le 18 Avr 2020
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.

Jeff Miller
Jeff Miller le 18 Avr 2020
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

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by