所有 . 我想使用 dplyr and/or broom packages and testing multiple variables at the same time 从相关矩阵中获取p值 . 我知道其他方法,但dplyr对我来说似乎更容易,更直观 . 此外,dplyr需要关联每个变量以获得特定的p值,这使得过程更容易和更快 .
我检查了其他链接,但它们不适用于这个问题(example 1,example 2,example 3)当我使用此代码时,会报告相关系数 . 但是,P值不是 .
agreg_base_tipo_a %>%
dplyr::select(S2.RT, BIS_total, IDATE, BAI, ASRS_total) %>%
do(as.data.frame(cor(., method="spearman", use="pairwise.complete.obs")))
请查看此可重现的代码:
set.seed(1164)
library(tidyverse)
ds <- data.frame(id=(1) ,a=rnorm(10,2,1), b=rnorm(10,3,2), c=rnorm(5,1,05))
ds %>%
select(a,b,c) %>%
do(as.data.frame(cor(., method="spearman", use="pairwise.complete.obs")))
1 回答
这个答案是基于akrun对此post的评论 . 通过使用
rcorr
函数,我们可以计算相关性和P值 . 要访问这些组件,请使用ds_cor$r
和ds_cor$P
.