cor.test中如何获取置信区间?

问题描述 投票:0回答:1

我有以下代码:

corMy_PSQ_T <- cor.test(datET$My_scale, datET$PSQ, method="spearman", exact=FALSE)

我的数据集是这样的:

但是当我尝试获得置信区间时,它根本不会显示。我什至得到了结构,但它不包括在内:

List of 8
 $ statistic  : Named num 29760
  ..- attr(*, "names")= chr "S"
 $ parameter  : NULL
 $ p.value    : num 0.186
 $ estimate   : Named num 0.173
  ..- attr(*, "names")= chr "rho"
 $ null.value : Named num 0
  ..- attr(*, "names")= chr "rho"
 $ alternative: chr "two.sided"
 $ method     : chr "Spearman's rank correlation rho"
 $ data.name  : chr "datET$My_scale and datET$PSQ"
 - attr(*, "class")= chr "htest"

我希望你能帮助我。 预先感谢!

r correlation confidence-interval
1个回答
0
投票

置信区间实际上是通过

print()
函数计算并显示的。因此,您可以通过保存
print(cor.test(...))
的结果然后查看
conf.int
元素来获取它:

out <- cor.test(mtcars$mpg, mtcars$hp)
p <- print(out)
#> 
#>  Pearson's product-moment correlation
#> 
#> data:  mtcars$mpg and mtcars$hp
#> t = -6.7424, df = 30, p-value = 1.788e-07
#> alternative hypothesis: true correlation is not equal to 0
#> 95 percent confidence interval:
#>  -0.8852686 -0.5860994
#> sample estimates:
#>        cor 
#> -0.7761684
p$conf.int
#> [1] -0.8852686 -0.5860994
#> attr(,"conf.level")
#> [1] 0.95

创建于 2023-08-08,使用 reprex v2.0.2

© www.soinside.com 2019 - 2024. All rights reserved.