Zero correlation coefficient, example

2 visualizzazioni (ultimi 30 giorni)
Jan
Jan il 13 Giu 2021
Modificato: Adam Danz il 13 Giu 2021
This question of mine is not tightly related to Matlab, but is relevant to it:
I'm looking how to fill in this matrix in a few nontrivial ways
[[a,b,c],[d,e,f]] so that as many places in the ans of this matrix
corrcoef([a,b,c],[d,e,f])
are zero. My attempts yield NaN result in most cases.
  4 Commenti
Jan
Jan il 13 Giu 2021
Modificato: Jan il 13 Giu 2021
I need the second one.
Adam Danz
Adam Danz il 13 Giu 2021
Modificato: Adam Danz il 13 Giu 2021
x = [1,2,3 ; -1,2,1]
x = 2×3
1 2 3 -1 2 1
corrcoef computes the correlation coeficient for each pair of columns. Let's look at column 1 and 2
x(:,1), x(:,2)
ans = 2×1
1 -1
ans = 2×1
2 2
corr(x(:,1),x(:,2))
ans = NaN
Notice that x(:,2) contains the same values. Now look at the link in my answer and pay attantion to the part that says, "When each value of y is identical, the result is a vector of 0s. When you divide by zero, you get NaN. ".

Accedi per commentare.

Risposte (1)

Adam Danz
Adam Danz il 13 Giu 2021
Modificato: Adam Danz il 13 Giu 2021
This answer explains why NaN values may appear in correlations.
Make sure your inputs avoid those errors. If you have trouble understanding the reasons explained in that answer or if you have trouble creating inputs that avoid NaNs after considering those reasons, share your inputs and we can help guide you in the right direction.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by