對計算好的相關系數進行顯著性檢驗。
原假設:變量間不相關,即總體的相關系數為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")
|