Why do I get correlation result NaN?
이전 댓글 표시
I have two matrices A is of 1*1058 and B is 1*1058, both matrices have some NaN values included in them. Is there any way to get correlation between these two matrices.
채택된 답변
추가 답변 (1개)
Chunru
2021년 8월 13일
0 개 추천
Use "fillmissing" to fill up the nans before computing the correlation. doc fillmissing for more details.
댓글 수: 7
Bharath kumar boyanapalli
2021년 8월 16일
Walter Roberson
2021년 8월 16일
fillmissing() cannot work in cases where the NaN are at the beginning or end.
Bharath kumar boyanapalli
2021년 8월 16일
fillmissing has a lot of options:
A = [NaN NaN 5 3 NaN 5 7 NaN 9 NaN;
8 9 NaN 1 4 5 NaN 5 NaN 5;
NaN 4 9 8 7 2 4 1 1 NaN]
F = fillmissing(A,'linear',2,'EndValues','nearest')
Bharath kumar boyanapalli
2021년 8월 17일
Chunru
2021년 8월 17일
Anyway, if you have data with so many NANs, you need to doubt your data first before doubting the processing techniques. There is not fool proof technique for filling missing data. It all depends on what data you have and what you want.
Walter Roberson
2021년 8월 17일
Mathematically, if you have vectors A and B, then
cAB = corr(A,B);
P = randperm(numel(A));
pA = A(P);
pB = B(P);
cpAB = corr(pA, pB);
then cAB needs to equal cpAB to within round-off. The order of the elements relative to each other in their same vectors do not matter: only the correspondance between the two vectors matter.
If, though, you were to fillmissing(A) and compare that to fillmissing(pA) then you would get different results, because fillmissing works based upon nearby values, under the assumption there is some kind of smooth continuity. This is not really compatible with the mathematics of correlation which does not care about order within the sequence.
If you have some prediction function for your vectors, then Yes, it might make sense to apply that prediction function. It might even make sense to apply something like narx to predict in some cases. But that would have to be done based upon knowledge of what the vectors represent. fillmissing() has no knowledge of what they represent.
카테고리
도움말 센터 및 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!