两个向量之间的相关性? [英] Correlation between two vectors?

查看:1659
本文介绍了两个向量之间的相关性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个向量:

A_1 = 

      10
      200
      7
      150

A_2 = 
      0.001
      0.450
      0.0007
      0.200

我想知道这两个向量之间是否存在相关性.

I would like to know if there is correlation between these two vectors.

我可以将向量的均值减去每个值,然后比:

I could subtract to each value the mean of the vector and than do:

  A_1' * A_2

还有更好的方法吗?

推荐答案

给出:

A_1 = [10 200 7 150]';
A_2 = [0.001 0.450 0.007 0.200]';

(正如其他人已经指出的那样),有一些工具可以简单地计算相关性,最明显的是corr:

(As others have already pointed out) There are tools to simply compute correlation, most obviously corr:

corr(A_1, A_2);  %Returns 0.956766573975184  (Requires stats toolbox)

您还可以使用基本的Matlab的corrcoef函数,如下所示:

You can also use base Matlab's corrcoef function, like this:

M = corrcoef([A_1 A_2]):  %Returns [1 0.956766573975185; 0.956766573975185 1];
M(2,1);  %Returns 0.956766573975184 

cov函数密切相关:

cov([condition(A_1) condition(A_2)]);


正如您几乎在最初的问题中提到的那样,您可以根据需要自己缩放和调整向量,这使您对所发生的事情有了更好的了解.首先创建一个条件函数,将其减去平均值,然后除以标准差:


As you almost get to in your original question, you can scale and adjust the vectors yourself if you want, which gives a slightly better understanding of what is going on. First create a condition function which subtracts the mean, and divides by the standard deviation:

condition = @(x) (x-mean(x))./std(x);  %Function to subtract mean AND normalize standard deviation

然后相关性似乎是(A_1 * A_2)/(A_1 ^ 2),如下所示:

Then the correlation appears to be (A_1 * A_2)/(A_1^2), like this:

(condition(A_1)' * condition(A_2)) / sum(condition(A_1).^2);  %Returns 0.956766573975185

通过对称,这也应该起作用

By symmetry, this should also work

(condition(A_1)' * condition(A_2)) / sum(condition(A_2).^2); %Returns 0.956766573975185

确实如此.

我相信,但现在还没有力量去确认,只要处理维度时要格外小心,在处理多维输入时就可以使用相同的数学来计算相关项和互相关项和输入数组的方向.

I believe, but don't have the energy to confirm right now, that the same math can be used to compute correlation and cross correlation terms when dealing with multi-dimensiotnal inputs, so long as care is taken when handling the dimensions and orientations of the input arrays.

这篇关于两个向量之间的相关性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆