我有两个数据框架-- motivation_on和motivation_off,分别有60个观测和146个观测,每个数据帧由21个vars和1个ID列组成,第一列是其中的一个。
现在我想知道vars是如何相互关联的,所以我使用:
rcorr(as.matrix(motivation_on[2:ncol(motivation_on)]), type = "spearman")和
rcorr(as.matrix(motivation_off[2:ncol(motivation_off)]), type = "spearman")(为了去掉ID列,执行了该子设置)
现在我想计算在线和离线vars之间的相关性,所以我尝试了:
rcorr(as.matrix(motivation_off[2:ncol(motivation_off)]), as.matrix(motivation_on[2:ncol(motivation_on)]) , type = "spearman")现在我得到了我想要的东西,但除此之外,它还显示了motivation_on和motivation_off中所有vars的相关性,这是我之前计算出来的。这使得输出非常长。如何获得on_off相关关系的rcorr输出?
编辑以获得澄清:尝试以下操作:
x <- as.matrix(mtcars[1:3])
y <- as.matrix(mtcars[4:6])
rcorr(x,y)我想要的是一个关联表: mpg,cyl,disp作为行,hp,drat,wt作为列,而不是完整的输出。我目前的工作是:
z <- rcorr(x,y)
q <- as.data.frame(z[1])
q[1:3,4:6]发布于 2017-04-08 09:13:24
似乎hmisc的rcorr没有提供提取我想要的东西的选项。我们只能手动提取结果,就像我在mtcar示例中演示的那样。但是,psych::corr.test(x, y)提供了我想要的输出--感谢@ this 20650指出这一点!
https://stackoverflow.com/questions/43262247
复制相似问题