Search code examples
rcorrelation

Extract correlation metric rho from correlation test


How can I extract the rho value from a correlation test?

For example, here the value of interest is -0.7356124:

cor.test(x,y, alternative = "less", method = "spearman")
    Spearman's rank correlation rho

data:  x and y
S = 60.746, p-value = 0.04781
alternative hypothesis: true rho is less than 0
sample estimates:
       rho 
-0.7356124 

Data:

x <- c(1,2,3,4,5,6)
y <- c(1,0,-1,-1,0,-2)

Solution

  • It is the estimate

    unname(cor.test(x,y, alternative = "less", method = "spearman")$estimate)
    [1] -0.7356124