Correlation of two variables over time: can this happen?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
alpedhuez
am 17 Dez. 2020
Bearbeitet: alpedhuez
am 17 Dez. 2020
I have a variable x1 and x2 between January 1 till December 31. When I calculate the correlation between Janaury and June it is positive. When I calculate the correlation between July to December it is positive. But the correlation between Janauary and December is negative. Can it happen?
1 Kommentar
Matt Gaidica
am 17 Dez. 2020
Yes. However, you probably want to perform a statistical test to determine if the fluctuating correlation is significant.
Akzeptierte Antwort
the cyclist
am 17 Dez. 2020
rng default
x1 = [1 2 3 4 6 7 8 9]';
x2 = [1 2 3 4 -6 -5 -4 -3]' + 0.8*rand(8,1);
% Correlation of first half
corrcoef(x1(1:4),x2(1:4))
% Correlation of second half
corrcoef(x1(5:8),x2(5:8))
% Correlation of entire vector
corrcoef(x1,x2)
% Plot it
figure
scatter(x1,x2)
You can see that the first half and the second half are positively correlated with each other, but if you look at the trend over the entire vector, it is negative.
7 Kommentare
Weitere Antworten (1)
Matt Gaidica
am 17 Dez. 2020
Bearbeitet: Matt Gaidica
am 17 Dez. 2020
Sure, it can happen. What's your concern about it?
4 Kommentare
Image Analyst
am 17 Dez. 2020
For a thorough explanation see the Wikipedia link in the Cyclist's answer below. (He beat me to it, posting this fun paradox.)
It would be interesting for us to know what real world measurements x1 and x2 are so we can see a real world situation that gives rise to this parabox. What do x1 and x2 represent?
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!