Correlation value for a non-zero null hypothesis using R

I am testing the correlation between two variables:

set.seed(123) x <- rnorm(20) y <- x + x * 1:20 cor.test(x, y, method = c("spearman")) 

which gives:

 Spearman rank correlation rho data: x and y S = 54, p-value = 6.442e-06 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.9594 

The value of p tests the null hypothesis that the correlation is zero. Is there a function R that allows me to test another null hypothesis - let's say that the correlation is less than or equal to 0.3?

+7
source share
2 answers

He does not say the question, but if you can live with Pearson's assumptions (two-dimensional normal), you can just look at the upper bound of the confidence interval. Any null hypothesis like yours that is larger than this will be rejected at p <0.05.

 > cor.test(x, y, method = c("pearson"))$conf [1] 0.7757901 0.9629837 
0
source

You can use bootstrap to calculate the confidence interval for rho:

1) Make a function to retrieve the cor.test score (do not forget to put indexes so that the load can display data):

 rho <- function(x, y, indices){ rho <- cor.test(x[indices], y[indices], method = c("spearman")) return(rho$estimate) } 

2) Use the boot package to download your score:

 library(boot) boot.rho <- boot(x ,y=y, rho, R=1000) 

3) Take the confidence interval:

 boot.ci(boot.rho) 
+3
source

All Articles