Description Usage Arguments Details Value References Examples
Performs a correlation analysis.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  correlation(
data,
data2 = NULL,
method = "pearson",
p_adjust = "holm",
ci = 0.95,
bayesian = FALSE,
bayesian_prior = "medium",
bayesian_ci_method = "hdi",
bayesian_test = c("pd", "rope", "bf"),
redundant = FALSE,
include_factors = FALSE,
partial = FALSE,
partial_bayesian = FALSE,
multilevel = FALSE,
robust = FALSE,
...
)

data 
A data frame. 
data2 
An optional data frame. 
method 
A character string indicating which correlation coefficient is to be used for the test. One of "pearson" (default), "kendall", or "spearman", "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, pointbiserial if one dichotomous and one continuous and pearson otherwise). 
p_adjust 
Correction method for frequentist correlations. Can be one of "holm" (default), "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr" or "none". 
ci 
Confidence/Credible Interval level. If "default", then it is set to 0.95 (95% CI). 
bayesian 
If TRUE, will run the correlations under a Bayesian framework. Note that for partial correlations, you will also need to set 
bayesian_prior 
For the prior argument, several named values are recognized: "medium.narrow", "medium", "wide", and "ultrawide". These correspond to scale values of 1/sqrt(27), 1/3, 1/sqrt(3) and 1, respectively. See the 
bayesian_ci_method 
See arguments in 
bayesian_test 
See arguments in 
redundant 
Should the data include redundant rows (where each given correlation is repeated two times). 
include_factors 
If 
partial 
Can be TRUE or "semi" for partial and semipartial correlations, respectively. 
partial_bayesian 
If TRUE, will run the correlations under a Bayesian framework. Note that for partial correlations, you will also need to set 
multilevel 
If 
robust 
If TRUE, will ranktransform the variables prior to estimating the correlation. Note that, for instance, a Pearson's correlation on ranktransformed data is equivalent to a Spearman's rank correlation. Thus, using 
... 
Arguments passed to or from other methods. 
Pearson's correlation: This is the most common correlation method. It corresponds to the covariance of the two variables normalized (i.e., divided) by the product of their standard deviations.
Spearman's rank correlation: A nonparametric measure of rank correlation (statistical dependence between the rankings of two variables). The Spearman correlation between two variables is equal to the Pearson correlation between the rank values of those two variables; while Pearson's correlation assesses linear relationships, Spearman's correlation assesses monotonic relationships (whether linear or not). Confidence Intervals (CI) for Spearman's correlations are computed using the Fieller et al. (1957) correction (see Bishara and Hittner, 2017).
Kendall's rank correlation: In the normal case, the Kendall correlation is preferred than the Spearman correlation because of a smaller gross error sensitivity (GES) and a smaller asymptotic variance (AV), making it more robust and more efficient. However, the interpretation of Kendall's tau is less direct than that of Spearman's rho, in the sense that it quantifies the difference between the % of concordant and discordant pairs among all possible pairwise events. Confidence Intervals (CI) for Kendall's correlations are computed using the Fieller et al. (1957) correction (see Bishara and Hittner, 2017).
Biweight midcorrelation: A measure of similarity that is medianbased, instead of the traditional meanbased, thus being less sensitive to outliers. It can be used as a robust alternative to other similarity metrics, such as Pearson correlation (Langfelder \& Horvath, 2012).
Distance correlation: Distance correlation measures both linear and nonlinear association between two random variables or random vectors. This is in contrast to Pearson's correlation, which can only detect linear association between two random variables.
Percentage bend correlation: Introduced by Wilcox (1994), it is based on a downweight of a specified percentage of marginal observations deviating from the median (by default, 20%).
Shepherd's Pi correlation: Equivalent to a Spearman's rank correlation after outliers removal (by means of bootstrapped Mahalanobis distance).
Blomqvist’s coefficient: The Blomqvist’s coefficient (also referred to as Blomqvist's Beta or medial correlation; Blomqvist, 1950) is a medianbased nonparametric correlation that has some advantages over measures such as Spearman's or Kendall's estimates (see Shmid and Schimdt, 2006).
Hoeffding’s D: The Hoeffding’s D statisticis a nonparametric rank based measure of association that detects more general departures from independence (Hoeffding 1948), including nonlinear associations. Hoeffding’s D varies between 0.5 and 1 (if there are no tied ranks, otherwise it can have lower values), with larger values indicating a stronger relationship between the variables.
PointBiserial and biserial correlation: Correlation coefficient used when one variable is continuous and the other is dichotomous (binary). PointBiserial is equivalent to a Pearson's correlation, while Biserial should be used when the binary variable is assumed to have an underlying continuity. For example, anxiety level can be measured on a continuous scale, but can be classified dichotomously as high/low.
Gamma correlation: The GoodmanKruskal gamma statistic is similar to Kendall's Tau coefficient. It is relatively robust to outliers and deals well with data that have many ties.
Gaussian rank Correlation: The Gaussian rank correlation estimator is a simple and wellperforming alternative for robust rank correlations (Boudt et al., 2012). It is based on the Gaussian quantiles of the ranks.
Polychoric correlation: Correlation between two theorised normally distributed continuous latent variables, from two observed ordinal variables.
Tetrachoric correlation: Special case of the polychoric correlation applicable when both observed variables are dichotomous.
Partial correlations are estimated as the correlation between two variables after adjusting for the (linear) effect of one or more other variable.
The correlation test is then run after having partialized the dataset, independently from it. In other words, it considers partialization as an independent step generating a different dataset, rather than belonging to the same model.
This is why some discrepancies are to be expected for the t and pvalues, CIs, BFs etc (but not the correlation coefficient) compared to other implementations (e.g., ppcor
).
(The size of these discrepancies depends on the number of covariates partialledout and the strength of the linear association between all variables.)
Such partial correlations can be represented as Gaussian Graphical Models (GGM), an increasingly popular tool in psychology. A GGM traditionally include a set of variables depicted as circles ("nodes"), and a set of lines that visualize relationships between them, which thickness represents the strength of association (see Bhushan et al., 2019).
Multilevel correlations are a special case of partial correlations where the variable to be adjusted for is a factor and is included as a random effect in a mixed model.
Kendall and Spearman correlations when bayesian=TRUE
: These are technically Pearson Bayesian correlations of rank transformed data, rather than pure Bayesian rank correlations (which have different priors).
A correlation object that can be displayed using the print
, summary
or table
methods.
About multiple tests corrections.
Boudt, K., Cornelissen, J., & Croux, C. (2012). The Gaussian rank correlation estimator: robustness properties. Statistics and Computing, 22(2), 471483.
Bhushan, N., Mohnert, F., Sloot, D., Jans, L., Albers, C., & Steg, L. (2019). Using a Gaussian graphical model to explore relationships between items and variables in environmental psychology research. Frontiers in psychology, 10, 1050.
Bishara, A. J., & Hittner, J. B. (2017). Confidence intervals for correlations when data are not normal. Behavior research methods, 49(1), 294309.
Fieller, E. C., Hartley, H. O., & Pearson, E. S. (1957). Tests for rank correlation coefficients. I. Biometrika, 44(3/4), 470481.
Langfelder, P., & Horvath, S. (2012). Fast R functions for robust correlations and hierarchical clustering. Journal of statistical software, 46(11).
Blomqvist, N. (1950). On a measure of dependence between two random variables,Annals of Mathematical Statistics,21, 593–600
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  library(correlation)
results < correlation(iris)
results
summary(results)
summary(results, redundant = TRUE)
# Grouped dataframe
if (require("dplyr")) {
iris %>%
group_by(Species) %>%
correlation()
}
# automatic selection of correlation method
correlation(mtcars[2], method = "auto")

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.