Test for association between paired samples, using one of Pearson's product moment correlation coefficient, Kendall's $$\tau$$ (tau) or Spearman's $$\rho$$ (rho). Unlike the stats version of cor.test, this function allows users to set the null to a value other than zero.

z_cor_test(
x,
y,
alternative = c("two.sided", "less", "greater", "equivalence", "minimal.effect"),
method = c("pearson", "kendall", "spearman"),
alpha = 0.05,
null = 0
)

## Arguments

x, y

numeric vectors of data values. x and y must have the same length.

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater", "less", "equivalence" (TOST), or "minimal.effect" (TOST). You can specify just the initial letter.

method

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

alpha

alpha level (default = 0.05)

null

a number indicating the null hypothesis. Default is a correlation of zero.

## Value

A list with class "htest" containing the following components:

• "p.value": the p-value of the test.

• "estimate": the estimated measure of association, with name "pb", "wincor", "cor", "tau", or "rho" corresponding to the method employed.

• "null.value": the value of the association measure under the null hypothesis.

• "alternative": character string indicating the alternative hypothesis (the value of the input argument alternative).

• "method": a character string indicating how the association was measured.

• "data.name": a character string giving the names of the data.

• "call": the matched call.

## Details

This function uses Fisher's z transformation for the correlations, but uses Fieller's correction of the standard error for Spearman's $$\rho$$ and Kendall's $$\tau$$. See vignette("correlations") for more details.

## References

Goertzen, J. R., & Cribbie, R. A. (2010). Detecting a lack of association: An equivalence testing approach. British Journal of Mathematical and Statistical Psychology, 63(3), 527-537. https://doi.org/10.1348/000711009X475853, formula page 531.

Other Correlations: boot_cor_test(), corsum_test(), plot_cor(), power_z_cor()

## Examples

# example code
x <- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
y <- c( 2.6,  3.1,  2.5,  5.0,  3.6,  4.0,  5.2,  2.8,  3.8)
# Sig test
z_cor_test(x, y, method = "kendall", alternative = "t", null = 0)
#>
#> 	Kendall's rank correlation tau
#>
#> data:  x and y
#> z = 1.616, N = 9, p-value = 0.1061
#> alternative hypothesis: true tau is not equal to 0
#> 95 percent confidence interval:
#>  -0.1013291  0.7845858
#> sample estimates:
#>       tau
#> 0.4444444
#>
# MET test
z_cor_test(x, y, method = "kendall", alternative = "min", null = .2)
#>
#> 	Kendall's rank correlation tau
#>
#> data:  x and y
#> z = 0.93028, N = 9, p-value = 0.1761
#> alternative hypothesis: minimal.effect
#> null values:
#>  tau  tau
#>  0.2 -0.2
#> 90 percent confidence interval:
#>  -0.008520225  0.746069903
#> sample estimates:
#>       tau
#> 0.4444444
#>