我有两个变量和第三个协变量调整器。如何获得调整后的 Kendall tau 估计值加上一个 p 值?
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)
我希望获得与
cor.test(a, b, method = "kendall")
类似的输出,该输出已针对 c
进行了调整。
这是一个运行偏相关测试的函数
pcor.test
。该函数基于函数 pcor
,包 ppcor
。
pcor.test <- function (x, y, z, method = c("pearson", "kendall", "spearman"), conf.level = 0.95, ...) {
d1 <- deparse(substitute(x))
d2 <- deparse(substitute(y))
d3 <- deparse(substitute(z))
data.name <- paste0(d1, " and ", d2, "; controlling: ", d3)
method <- match.arg(method)
Method <- paste0("Partial correlation (", method, ")")
alternative <- "true partial correlation is not equal to 0"
x <- as.vector(x)
y <- as.vector(y)
z <- as.data.frame(z)
xyz <- data.frame(x, y, z)
pc <- ppcor::pcor(xyz, method = method)
estimate <- pc$est[1, 2]
p.value <- pc$p.value[1, 2]
parameter <- c(n = pc$n, gp = pc$gp)
statistic <- c(Stat = pc$statistic[1, 2])
ht <- list(
statistic = statistic,
parameter = parameter,
p.value = p.value,
estimate = c(partial.cor = estimate),
alternative = alternative,
method = Method,
data.name = data.name
)
class(ht) <- "htest"
ht
}
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)
pcor.test(a, b, c, method = "kendall")
#>
#> Partial correlation (kendall)
#>
#> data: a and b; controlling: c
#> Stat = 2.5651, n = 10, gp = 1, p-value = 0.01032
#> alternative hypothesis: true partial correlation is not equal to 0
#> sample estimates:
#> partial.cor
#> 0.6834271
创建于 2024-04-19,使用 reprex v2.1.0