r 函数 cor.test(): 如何计算皮尔逊相关性的 p 值?



这可能是一个非常简单的问题。

我在 R 的 cor.test(( 函数中找不到 pvalue 计算背后的方法。

下面是计算皮尔逊相关性的 p 值的代码:

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)
ct = cor.test(x, y, method = "pearson")
ct$p.value  ## this is what cor.test() gives
n <- length(x)
r <- cor(x, y)
df <- n - 2
t = sqrt(df) * r/sqrt(1 - r^2)
pval = 2 * min(pt(t, df), pt(t, df, lower.tail = FALSE))  ## this is calculated manually
ct$p.value == pval

最新更新