matlab中的相关性
以下脚本查找每对数据之间的相关性。
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)))]
此外,该脚本还在“Correlation”中说明了在生成相关值时使用了哪些数据组合。由此,我不仅尝试找到一对数据之间的相关性,还尝试找到 n 个数据之间的相关性,因此除了上面的脚本之外,我还尝试找到 3 组数据之间的相关性,然后四个...依此类推,然后将其存储在 Correlation 中。我将如何实现这一目标?
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)))]
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您的数字都是非负数,我认为只需将相关数组相乘、求和和标准化就足够了。这基本上与 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.