开发者

How to replace missing value with Pearson Correlation on MATLAB

I have problem with using 'corr' function in MATLAB,

a =

     1     4     3     2
     2     3     3     2
     3     2     3     2
     4     1     3     2

>> corr(a)

ans =

     1    -1   NaN   NaN
    -1     1   NaN   NaN
   NaN   NaN   NaN   NaN
   NaN   NaN   NaN   NaN

When I calculate manually, the Missing Value (NaN) is because the denominator is ZERO (0). Although, we can be see that similarity of column 3 and 4 is O开发者_C百科NE (+1).

Anyone know how to enhance or replace the missing value?

Thank's Before.


What do you expect, correlation is a measure of linear dependence between two variables, computed as the covariance (how much the variables change together) normalized by the standard deviations.

Thus it makes no sense if one variable is constant (you get zero divided by zero which is undefined and reported as NaN)...


As Amro said, corr is reporting the correct answer, which is undefined. If you want to handle the undefineds a special way, such as setting to 1, you can do this:

a(isnan(a)) = 1;

But it sounds like you have some deeper issues with your data - not enough observations? Why not remove identical series?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜