我有以下代码:
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"
我希望你能帮助我。 预先感谢!
置信区间实际上是通过
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