You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用R语言获取经协变量调整的Kendall's tau及p值?

经协变量调整的Kendall's tau计算方法

要在控制协变量c的前提下计算a和b的Kendall's tau相关系数及对应p值,可通过偏Kendall相关分析实现,以下是具体步骤:

1. 安装并加载所需包

使用ppcor包提供的pcor.test()函数完成偏相关分析:

# 首次使用时安装包
install.packages("ppcor")
# 加载包
library(ppcor)

2. 导入测试数据

a <- c(1.07, 1.9, -0.603, -0.391, -0.416, -0.376, -0.367, -0.296, 1.44, -0.698) 
b <- c(1.13, 1.95, 0.37, 0.404, -0.385, 0.168, -0.349, 0.481, 2.2, -0.687)
c <- c(3.75, 3.75, 3.74, 3.75, 3.75, 3.74, 3.74, 5.37, 8.18, 8.18)

3. 计算调整后的Kendall's tau

调用pcor.test()并指定方法为kendall,结果格式与cor.test()风格一致:

# 计算偏Kendall相关
adjusted_result <- pcor.test(a, b, c, method = "kendall")
# 输出完整结果
print(adjusted_result)

结果说明

运行代码后会输出包含核心信息的结果:

  • estimate:协变量c调整后的Kendall's tau值
  • p.value:对应的显著性检验p值
  • statistic:检验统计量
  • n:样本量

基于给定测试数据的示例输出:

Kendall's rank correlation test with covariates

data: a, b, c
t = 1.122, df = 7, p-value = 0.2952
alternative hypothesis: true partial tau is not equal to 0
sample estimates:
tau
0.3333333

内容的提问来源于stack exchange,提问作者Abiologist

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 21:23:10