R:如何从cor.test函数中提取置信区间

use*_*949 2 r confidence-interval correlation

我试图95 percent confidence interval从皮尔逊相关性的结果中提取出来。

我的输出如下所示:

Pearson's product-moment correlation

data:  newX[, i] and newY
t = 2.1253, df = 6810, p-value = 0.0336
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.001998576 0.049462864
sample estimates:
       cor 
0.02574523 
Run Code Online (Sandbox Code Playgroud)

我用以下代码得到它

t <- apply(FNR[, -1], 2, cor.test, FNR$HDL, method="pearson")
Run Code Online (Sandbox Code Playgroud)

我将不胜感激任何帮助。谢谢。

eip*_*i10 5

cor.test返回包含各种元素(包括置信区间)的列表。您可以看到通过cor.test以下方式返回的对象的结构(使用内置mtcars数据框进行说明):

ct = cor.test(mtcars$mpg, mtcars$wt, method="pearson")

str(ct)
Run Code Online (Sandbox Code Playgroud)
List of 9
 $ statistic  : Named num -9.56
  ..- attr(*, "names")= chr "t"
 $ parameter  : Named int 30
  ..- attr(*, "names")= chr "df"
 $ p.value    : num 1.29e-10
 $ estimate   : Named num -0.868
  ..- attr(*, "names")= chr "cor"
 $ null.value : Named num 0
  ..- attr(*, "names")= chr "correlation"
 $ alternative: chr "two.sided"
 $ method     : chr "Pearson's product-moment correlation"
 $ data.name  : chr "mtcars$mpg and mtcars$wt"
 $ conf.int   : atomic [1:2] -0.934 -0.744
  ..- attr(*, "conf.level")= num 0.95
 - attr(*, "class")= chr "htest"
Run Code Online (Sandbox Code Playgroud)

现在提取置信区间:

ct$conf.int[1:2]   
Run Code Online (Sandbox Code Playgroud)

[1] -0.9338264 -0.7440872