Matlab中的相关性 [英] correlation in matlab

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

问题描述

以下脚本查找每对数据之间的相关性.

The following script finds the correlation between each pair of data.

clear all
LName={'Name1','Name2','Name3','Name4','Name5'};
Data={rand(12,1),rand(12,1),rand(12,1),rand(12,1),rand(12,1)};
%place in a structure
d = [LName;Data];
Data = struct(d{:});

d1 = cell2mat(struct2cell(Data)');
[R,P] = corrcoef(d1);
Correlation = [LName(nchoosek(1:length(R),2)) num2cell(nonzeros(tril(R,-1)))]

此外,该脚本还在关联"中指出在生成关联值时使用了哪种数据组合.由此,我不仅尝试查找一对数据之间的相关性,而且还尝试查找n个数据之间的相关性,因此,除了上面的脚本之外,我还尝试查找3组数据之间的相关性,然后四个...等等,然后将其存储在Correlation中.我将如何实现?

Furthermore, the script also states in 'Correlation' which combination of data was used in generating the correlation value. From this I am attempting to not only find the correlation between a pair of data but also find the correlation between n number of data, so in addition to the script above I'm trying to find the correlation between 3 sets of data, and then four... and so on, then store this in Correlation. How would I acheive this?

推荐答案

由于您的数字均为非负数,我认为将相关数组相乘,求和和归一化就足够了.这与corrcoef基本相同,只是一次只能将两个数组相乘.

Since your numbers are all non-negative I think simply multiplying the relevant arrays together, summing, and normalizing would be sufficient. This is basically the same thing that corrcoef does, except it only multiplies two arrays together at a time.

但是请注意,这不适用于负数.例如,假设所有三个数组在某个时刻都为负值.就它们之间的相关性而言,这将是一件好事.不过,只要简单地将它们相乘,便会得到负相关,这表明此时的相关性相反.

Please note, though, that this wouldn't work for negative numbers. For instance, imagine that all three arrays have a negative value at some point. This would be good, in the sense that they are well correlated. Simply multiplying them, though, would give you a negative correlation, which would indicate opposite correlation at that point.

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

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