秩相关(rank-correlation)或称等级相关,是用双变量等级数据作直线相关分析,这类方法对原变量分布不作要求,属于非参数统计方法。适用于下列资料:
孙振球《医学统计学》第4版例9-8。
某省调查了1995年到1999年当地居民18类死因的构成以及每种死因导致的潜在工作损失年数WYPLL的构成。以死因构成为X,WYPLL构成为Y,作等级相关分析。
data9_8 <- foreign::read.spss("datasets/例09-08.sav", to.data.frame = T,
reencode = "gbk")
## re-encoding from gbk
str(data9_8)
## 'data.frame': 18 obs. of 3 variables:
## $ number: num 1 2 3 4 5 6 7 8 9 10 ...
## $ x : num 0.03 0.14 0.2 0.43 0.44 0.45 0.47 0.65 0.95 0.96 ...
## $ y : num 0.05 0.34 0.93 0.69 0.38 0.79 1.19 4.74 2.31 5.95 ...
## - attr(*, "variable.labels")= Named chr [1:3] "编号" "死因构成" "WYPLL构成"
## ..- attr(*, "names")= chr [1:3] "number" "x" "y"计算相关系数:
# 方法选择spearman相关
cor(data9_8$x,data9_8$y, method = "spearman")
## [1] 0.9050568计算P值:
cor.test(data9_8$x,data9_8$y, method = "spearman")
##
## Spearman's rank correlation rho
##
## data: data9_8$x and data9_8$y
## S = 92, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9050568P<0.001。
如何对相关系数进行校正?直接使用continuity即可(看帮助文档):
cor.test(data9_8$x,data9_8$y, method = "spearman",continuity=T)
##
## Spearman's rank correlation rho
##
## data: data9_8$x and data9_8$y
## S = 92, p-value < 2.2e-16
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
## rho
## 0.9050568