Im trying to extract 95 percent confidence interval from the result of pearson correlation.
My output looks like this:
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
I get it with the following code
t <- apply(FNR[, -1], 2, cor.test, FNR$HDL, method="pearson")
I would appreciate any help. Thanks.
cor.test returns a list with various elements, including the confidence interval. You can see the structure of the object returned by cor.test as follows (using the built-in mtcars data frame for illustration):
ct = cor.test(mtcars$mpg, mtcars$wt, method="pearson")
str(ct)
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"
Now extract the confidence interval:
ct$conf.int[1:2]
[1] -0.9338264 -0.7440872
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With