cor.test 位于 stats 包(package)。 说明
使用 Pearson 的乘积矩相关系数、Kendall 的 或 Spearman 的 之一测试配对样本之间的关联。
用法
cor.test(x, ...)
## Default S3 method:
cor.test(x, y,
         alternative = c("two.sided", "less", "greater"),
         method = c("pearson", "kendall", "spearman"),
         exact = NULL, conf.level = 0.95, continuity = FALSE, ...)
## S3 method for class 'formula'
cor.test(formula, data, subset, na.action, ...)
参数
| x, y | 数据值的数值向量。  | 
| alternative | 表示备择假设,并且必须是  | 
| method | 指示要使用哪个相关系数进行测试的字符串。  | 
| exact | 指示是否应计算精确 p 值的逻辑。用于 Kendall 的  和 Spearman 的  。有关 | 
| conf.level | 返回的置信区间的置信水平。目前仅在至少有 4 个完整的观测值对时才用于 Pearson 积矩相关系数。 | 
| continuity | 逻辑:如果为 true,则在未精确计算时,会对 Kendall 的 和 Spearman 的 使用连续性校正。 | 
| formula | 
 | 
| data | 包含公式  | 
| subset | 一个可选向量,指定要使用的观测子集。 | 
| na.action | 一个函数,指示当数据包含  | 
| ... | 要传递给方法或从方法传递的更多参数。 | 
细节
这三种方法各自估计配对样本之间的关联并计算值为零的测试。它们使用不同的关联度量,均在 范围内,其中 表示没有关联。这些有时被称为无相关性测试,但该术语通常仅限于默认方法。
如果 method 为 "pearson" ,则检验统计量基于 Pearson 乘积矩相关系数 cor(x, y),并且如果样本遵循独立正态分布,则遵循具有 length(x)-2 自由度的 t 分布。如果至少有 4 对完整的观测值,则基于 Fisher Z 变换给出渐近置信区间。
如果 method 是 "kendall" 或 "spearman" ,则使用 Kendall 的  或 Spearman 的  统计量来估计基于排名的关联度量。如果数据不一定来自二元正态分布,则可以使用这些检验。
对于 Kendall 检验,默认情况下(如果 exact 为 NULL),如果包含有限值且不存在联系的配对样本少于 50 个,则会计算精确的 p 值。否则,检验统计量是缩放至零均值和单位方差的估计值,并且近似正态分布。
对于 Spearman 检验,p 值是使用  和 exact = TRUE 的算法 AS 89 计算的,否则通过渐近  近似计算。请注意,这些是  的 ‘exact’ ,并使用 Edgeworth 级数近似来获得更大的样本量(截止值已从原始论文中更改)。
值
类"htest" 的列表包含以下组件:
| statistic | 检验统计量的值。 | 
| parameter | 检验统计量服从 t 分布时的自由度。 | 
| p.value | 检验的 p 值。 | 
| estimate | 估计的关联度量,名称为  | 
| null.value | 原假设下关联度量的值,始终为  | 
| alternative | 说明备择假设的字符串。 | 
| method | 指示如何测量关联的字符串。 | 
| data.name | 给出数据名称的字符串。 | 
| conf.int | 关联度量的置信区间。目前仅在至少 4 个完整观测值对的情况下给出 Pearson 乘积矩相关系数。 | 
例子
## Hollander & Wolfe (1973), p. 187f.
## Assessment of tuna quality.  We compare the Hunter L measure of
##  lightness to the averages of consumer panel scores (recoded as
##  integer values from 1 to 6 and averaged over 80 such values) in
##  9 lots of canned tuna.
x <- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
y <- c( 2.6,  3.1,  2.5,  5.0,  3.6,  4.0,  5.2,  2.8,  3.8)
##  The alternative hypothesis of interest is that the
##  Hunter L value is positively associated with the panel score.
cor.test(x, y, method = "kendall", alternative = "greater")
## => p=0.05972
cor.test(x, y, method = "kendall", alternative = "greater",
         exact = FALSE) # using large sample approximation
## => p=0.04765
## Compare this to
cor.test(x, y, method = "spearm", alternative = "g")
cor.test(x, y,                    alternative = "g")
## Formula interface.
require(graphics)
pairs(USJudgeRatings)
cor.test(~ CONT + INTG, data = USJudgeRatings)
参考
D. J. Best & D. E. Roberts (1975). Algorithm AS 89: The Upper Tail Probabilities of Spearman's . Applied Statistics, 24, 377-379. doi:10.2307/2347111.
Myles Hollander & Douglas A. Wolfe (1973), Nonparametric Statistical Methods. New York: John Wiley & Sons. Pages 185-194 (Kendall and Spearman tests).
也可以看看
pKendall 和 pSpearman 位于包  SuppDists  中,spearman.test 位于包  pspearman  中,它们提供不同的(通常更准确)近似值。
相关用法
- R cor 相关性、方差和协方差(矩阵)
- R constrOptim 线性约束优化
- R confint 模型参数的置信区间
- R contrast (可能稀疏)对比矩阵
- R complete.cases 查找完整案例
- R contrasts 获取和设置对比矩阵
- R convolve 通过 FFT 进行序列卷积
- R cov.wt 加权协方差矩阵
- R cophenetic 层次聚类的共表距离
- R coef 提取模型系数
- R cancor 典型相关性
- R cutree 将树切割成数据组
- R cpgram 绘制累积周期图
- R chisq.test 计数数据的皮尔逊卡方检验
- R checkMFClasses 检查传递给模型框架的变量类型的函数
- R cmdscale 经典(公制)多维标度
- R case+variable.names 拟合模型的案例和变量名称
- R stlmethods STL 对象的方法
- R medpolish 矩阵的中值波兰(稳健双向分解)
- R naprint 调整缺失值
- R summary.nls 总结非线性最小二乘模型拟合
- R summary.manova 多元方差分析的汇总方法
- R formula 模型公式
- R nls.control 控制 nls 中的迭代
- R aggregate 计算数据子集的汇总统计
注:本文由纯净天空筛选整理自R-devel大神的英文原创作品 Test for Association/Correlation Between Paired Samples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
