簡體   English   中英

r函數cor.test():如何計算皮爾遜相關系數的p值?

[英]r function cor.test(): How is the p-value calculated for pearson correlation?

這可能是一個非常簡單的問題。

我在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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM