R/statistical_tests_and_estimates.R
cor_test.Rd
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)
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 |
B | number of reps (only used if |
exact | Should exact method be used. Ingorned it |
verbose | a logical variable indicating if warnings and messages should be displayed |
spearman_test pvalue
To always get reproducible results when using approximate method we need to set seed inside of the call, and order the data
set.seed(5432322) x <- rnorm(20,0,3) y <- x + rnorm(20,0,5) cor_test(x,y, method = 'pearson')#> [1] 0.003244366cor_test(x,y, method = 'kendall')#> [1] 0.0237345cor_test(x,y, method = 'spearman')#> [1] 0.01473093