A wrapper for cor.test function, except if spearman selected and ties in at least one variable, in which case this is a wrapper for coin::spreaman_test in with approximate method.

cor_test(x, y, method = c("pearson", "kendall", "spearman"),
  seed = 68954857, B = 10000, exact = TRUE, verbose = FALSE)

Arguments

x

numeric vector (can include NA values)

y

numeric vector (can include NA values)

method

a character string indicating which correlation coefficient is to be used for the test. One of "pearson", "kendall", or "spearman", can be abbreviated

seed

seed (only used if method = "spearman")

B

number of reps (only used if method = "spearman")

exact

Should exact method be used. Ingorned it method = "spearman" and ties present

verbose

a logical variable indicating if warnings and messages should be displayed

Value

spearman_test pvalue

Details

To always get reproducible results when using approximate method we need to set seed inside of the call, and order the data

Examples

set.seed(5432322) x <- rnorm(20,0,3) y <- x + rnorm(20,0,5) cor_test(x,y, method = 'pearson')
#> [1] 0.003244366
cor_test(x,y, method = 'kendall')
#> [1] 0.0237345
cor_test(x,y, method = 'spearman')
#> [1] 0.01473093