R 中,cor.test ()提供了三種檢驗方法:Pearson相關性檢驗(R默認);Spearman秩檢驗;Kendall檢驗。調用格式爲:
cor.test ( x, y, alternative=c("two.side" , "less" , " greater"),
method=c("Pearson" , " Kendall" ," Spearman"),
exact= NULL, conf.level=........)
【備註:alternative是備擇假設,默認1;method 是檢驗方法,默認1;coef.level是置信水平,默認0,95】
根據前面文章中相關分析的理論知識,若(X,Y)服從二元正太分佈(即相關分析文章中提到的t 檢驗),可進行Pearson相關性檢驗。
這裏在Rstudio 中進行了一組數據的相關性分析。
散點圖:
x<-c(........) y<-c(........) 【x,y 長度相同】
test<-data.frame(x,y)
plot(x,y)
相關性判斷:
attach(test)
cor.test(x,y)