matlab中的相关性

发布于 2024-12-26 23:34:15 字数 535 浏览 1 评论 0原文

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

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 技术交流群。

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

发布评论

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

评论(1

月寒剑心 2025-01-02 23:34:15

由于您的数字都是非负数,我认为只需将相关数组相乘、求和和标准化就足够了。这基本上与 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.

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