小编Moh*_*ere的帖子

相同维度的两个矩阵之间的 Spearman 相关性

我有两个相同维度(p 和 e)的矩阵,我想在同名的列之间进行 spearman 相关。我想在矩阵 (M) 中输出对相关性

我使用了corr.test()库 Psych 中的函数,这是我所做的:

library(psych)
M <- data.frame(matrix(ncol=3,nrow=ncol(p)))
M[,1] <- as.character()
G <- colnames(p)
for(rs in 1:ncol(p){
      M[rs,1] <- G[rs]     
      cor <- corr.test(p[,rs],e[,rs],method="spearman",adjust="none")
      M[rs,2] <- cor$r
      M[rs,3] <- cor$p
}
Run Code Online (Sandbox Code Playgroud)

但我收到一条错误消息:

Error in 1:ncol(y) : argument of length 0
Run Code Online (Sandbox Code Playgroud)

你能告诉我有什么问题吗?或建议另一种方法?

loops r matrix correlation psych

1
推荐指数
1
解决办法
1275
查看次数

标签 统计

correlation ×1

loops ×1

matrix ×1

psych ×1

r ×1