相关性的显著性检验

对计算好的相关系数进行显著性检验

原假设:变量间不相关,即总体的相关系数为0。

cor.test()对单个的 Pearson、Spearman 和 Kendall 相关系数进行检验。、

格式:cor.test(x, y, alternative=, method=)

x,y: 为要检验相关性的变量。

alternative: 指定双侧检验或单侧检验。two.side, less 或 greater。

method:method:指定相关系数的类型。pearson、spearman、kendall。

(1)一次检验一种相关关系

> cor.test(houseXQ[, c("house_total")],houseXQ[, c("house_area")] )

 

    Pearson's product-moment correlation

 

data:  houseXQ[, c("house_total")] and houseXQ[, c("house_area")]

t = 39.537, df = 187, p-value < 2.2e-16

alternative hypothesis: true correlation is not equal to 0

95 percent confidence interval:

 0.9274393 0.9585053

sample estimates:

      cor

0.9450675

解释:总价与面积成正相关。

(2)一次检验多种相关关系

corr.test()

检验结果的p值越小表明两个变量相关性越大,为0表示显著相关,<0.05表示相关性大,为1表示基本不相关。

> selectedColumns<- c("house_total","house_avg","house_floor_curr","house_floor_total","house_area")

> houseNum<-houseXQ[, selectedColumns]

> corr.test(houseNum, use="complete")

原文地址:https://www.cnblogs.com/quietwalk/p/8301368.html