This function is a wrapper around stats::cor.test(). It implements the Pearson's correlation test that tests the null hypothesis that two paired samples of values are unrelated. This function must be applied to two numeric vectors.

cor_test(x, y, method = "pearson", data)

Arguments

x

A numeric variable.

y

A numeric variable.

method

A character string indicating which correlation coefficient is to be used: "pearson", "kendall", or "spearman". Default method is "pearson".

data

A data frame containing the y and x variables

Value

A tibble data frame with the correlation statistic, and the corresponding p-value.

Examples

cor_test(y = sex_dimorph, x = attractive, data = faithfulfaces)
#> # A tibble: 1 × 4
#>     cor     t    df  p_value
#>   <dbl> <dbl> <int>    <dbl>
#> 1 0.604  9.83   168 2.68e-18
cor_test(y = sex_dimorph, x = attractive, method = "spearman", data = faithfulfaces)
#> Warning: There was 1 warning in `dplyr::summarise()`.
#>  In argument: `get_cor_test_results(attractive, sex_dimorph, "spearman")`.
#> Caused by warning in `cor.test.default()`:
#> ! Cannot compute exact p-value with ties
#> # A tibble: 1 × 3
#>     cor       t  p_value
#>   <dbl>   <dbl>    <dbl>
#> 1 0.582 342385. 8.73e-17