如何在 MATLAB 上使用 Pearson 相关性替换缺失值

发布于 2024-10-09 10:02:57 字数 406 浏览 7 评论 0原文

我在 MATLAB 中使用“corr”函数时遇到问题,

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

当我手动计算时,缺失值 (NaN) 是因为分母为零 (0)。 尽管如此,我们可以看到第 3 列和第 4 列的相似度为 1 (+1)。

有人知道如何增强或替换缺失的值吗?

谢谢之前。

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 ONE (+1).

Anyone know how to enhance or replace the missing value?

Thank's Before.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巴黎夜雨 2024-10-16 10:02:57

您期望什么,相关性是两个变量之间线性相关性的度量,
计算为由标准差标准化的协方差(变量一起变化的程度)。

因此,如果一个变量是常量,则毫无意义(您得到零除以零,这是未定义的并报告为 NaN)...

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)...

预谋 2024-10-16 10:02:57

正如 Amro 所说,corr 正在报告正确的答案,但该答案是未定义的。如果您想以特殊方式处理未定义,例如设置为 1,您可以这样做:

a(isnan(a)) = 1;

但听起来您的数据有一些更深层次的问题 - 没有足够的观察?为什么不删除相同的系列?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文