是否可以在 R 中找到 pearson 相关性的 p 值?
为了找到皮尔逊相关性,我通常这样做
col1 = c(1,2,3,4)
col2 = c(1,4,3,5)
cor(col1,col2)
# [1] 0.8315218
但是我怎么能找到这个的p值呢?
是否可以在 R 中找到 pearson 相关性的 p 值?
为了找到皮尔逊相关性,我通常这样做
col1 = c(1,2,3,4)
col2 = c(1,4,3,5)
cor(col1,col2)
# [1] 0.8315218
但是我怎么能找到这个的p值呢?
你可以使用cor.test:
col1 = c(1,2,3,4) 
col2 = c(1,4,3,5)
cor.test(col1,col2) 
这使 :
# Pearson's product-moment correlation   
# data:  col1 and col2   
# t = 2.117, df = 2, p-value = 0.1685   
# alternative hypothesis: true correlation is not equal to 0   
# 95 percent confidence interval:   
#  -0.6451325  0.9963561   
# sample estimates:   
#       cor    
# 0.8315218    
更多关于统计和额外参数的信息在官方页面:
https://stat.ethz.ch/R-manual/R-patched/library/stats/html/cor.test.html
如果您只想要 P 值:
> cor.test(col1,col2)$p.value
[1] 0.1684782
以下将按照您的要求进行:
 library(Hmisc) # You need to download it first.
 rcorr(x, type="pearson") # type can be pearson or spearman
这里 x 是一个数据帧,并且 rcorr 返回可能从“x”数据帧形成的每个相关性。
或者您可以自己计算统计数据:
在哪里是从数据估计的皮尔逊相关性,n 是样本量。