cor_to_p: Convert correlation to p-values and CIs

View source: R/cor_to_p.R

cor_to_ciR Documentation

Convert correlation to p-values and CIs

Description

Get statistics, p-values and confidence intervals (CI) from correlation coefficients.

Usage

cor_to_ci(cor, n, ci = 0.95, method = "pearson", correction = "fieller", ...)

cor_to_p(cor, n, method = "pearson")

Arguments

cor

A correlation matrix or coefficient.

n

The sample size (number of observations).

ci

Confidence/Credible Interval level. If "default", then it is set to 0.95 (⁠95%⁠ CI).

method

A character string indicating which correlation coefficient is to be used for the test. One of "pearson" (default), "kendall", "spearman" (but see also the robust argument), "biserial", "polychoric", "tetrachoric", "biweight", "distance", "percentage" (for percentage bend correlation), "blomqvist" (for Blomqvist's coefficient), "hoeffding" (for Hoeffding's D), "gamma", "gaussian" (for Gaussian Rank correlation) or "shepherd" (for Shepherd's Pi correlation). Setting "auto" will attempt at selecting the most relevant method (polychoric when ordinal factors involved, tetrachoric when dichotomous factors involved, point-biserial if one dichotomous and one continuous and pearson otherwise). See below the details section for a description of these indices.

correction

Only used if method is 'spearman' or 'kendall'. Can be 'fieller' (default; Fieller et al., 1957), 'bw' (only for Spearman) or 'none'. Bonett and Wright (2000) claim their correction ('bw') performs better, though the Bishara and Hittner (2017) paper favours the Fieller correction. Both are generally very similar.

...

Additional arguments (e.g., alternative) to be passed to other methods. See stats::cor.test for further details.

Value

A list containing a p-value and the statistic or the CI bounds.

References

Bishara, A. J., & Hittner, J. B. (2017). Confidence intervals for correlations when data are not normal. Behavior research methods, 49(1), 294-309.

Examples

cor.test(iris$Sepal.Length, iris$Sepal.Width)
cor_to_p(-0.1175698, n = 150)
cor_to_p(cor(iris[1:4]), n = 150)
cor_to_ci(-0.1175698, n = 150)
cor_to_ci(cor(iris[1:4]), n = 150)

cor.test(iris$Sepal.Length, iris$Sepal.Width, method = "spearman", exact = FALSE)
cor_to_p(-0.1667777, n = 150, method = "spearman")
cor_to_ci(-0.1667777, ci = 0.95, n = 150)

cor.test(iris$Sepal.Length, iris$Sepal.Width, method = "kendall", exact = FALSE)
cor_to_p(-0.07699679, n = 150, method = "kendall")

correlation documentation built on April 6, 2023, 5:18 p.m.