Although the cor function finds the correlations for a matrix, it does not report probability values. corr.test uses cor to find the correlations for either complete or pairwise data and reports the sample sizes and probability values as well. For symmetric matrices, raw probabilites are reported below the diagonal and correlations adjusted for multiple comparisons above the diagonal. In the case of different x and ys, the default is to adjust the probabilities for multiple tests.
corr.test(x, y = NULL, use = "pairwise",method="pearson",adjust="holm", alpha=.05,ci=TRUE) corr.p(r,n,adjust="holm",alpha=.05)
| x | A matrix or dataframe |
|---|---|
| y | A second matrix or dataframe with the same number of rows as x |
| use | use="pairwise" is the default value and will do pairwise deletion of cases. use="complete" will select just complete cases. |
| method | method="pearson" is the default value. The alternatives to be passed to cor are "spearman" and "kendall" |
| adjust | What adjustment for multiple tests should be used? ("holm", "hochberg", "hommel", "bonferroni", "BH", "BY", "fdr", "none"). See |
| alpha | alpha level of confidence intervals |
| r | A correlation matrix |
| n | Number of observations if using corr.p. May be either a matrix (as returned from corr.test, or a scaler. Set to n- np if finding the significance of partial correlations. (See below). |
| ci | By default, confidence intervals are found. However, this leads to a great slowdown of speed. So, for just the rs, ts and ps, set ci=FALSE |
corr.test uses the cor function to find the correlations, and then applies a t-test to the individual correlations using the formula
$$t = \frac{r * \sqrt(n-2)}{\sqrt(1-r^2)}
$$
$$se = \sqrt(\frac{1-r^2}{n-2}) $$
The t and Standard Errors are returned as objects in the result, but are not normally displayed. Confidence intervals are found and printed if using the print(short=FALSE) option. These are found by using the fisher z transform of the correlation, and the standard error of the z transforms is $$se = \sqrt(\frac {1}{n-3}) $$.
The probability values may be adjusted using the Holm (or other) correction. If the matrix is symmetric (no y data), then the original p values are reported below the diagonal and the adjusted above the diagonal. Otherwise, all probabilities are adjusted (unless adjust="none"). This is made explicit in the output.
corr.p may be applied to the results of partial.r if n is set to n - s (where s is the number of variables partialed out) Fisher, 1924.
The matrix of correlations
Number of cases per correlation
value of t-test for each correlation
two tailed probability of t for each correlation. For symmetric matrices, p values adjusted for multiple tests are reported above the diagonal.
standard error of the correlation
the alpha/2 lower and upper values
For very large matrices (> 200 x 200), there is a noticeable speed improvement if confidence intervals are not found.
cor.test for tests of a single correlation, Hmisc::rcorr for an equivalant function, r.test to test the difference between correlations, and cortest.mat to test for equality of two correlation matrices.
Also see cor.ci for bootstrapped confidence intervals of Pearson, Spearman, Kendall, tetrachoric or polychoric correlations. In addition cor.ci will find bootstrapped estimates of composite scales based upon a set of correlations (ala cluster.cor).
In particular, see p.adjust for a discussion of p values associated with multiple tests.
Other useful functions related to finding and displaying correlations include lowerCor for finding the correlations and then displaying the lower off diagonal using the lowerMat function. lowerUpper to compare two correlation matrices.
ct <- corr.test(attitude) #find the correlations and give the probabilities ct #show the results#> Call:corr.test(x = attitude) #> Correlation matrix #> rating complaints privileges learning raises critical advance #> rating 1.00 0.83 0.43 0.62 0.59 0.16 0.16 #> complaints 0.83 1.00 0.56 0.60 0.67 0.19 0.22 #> privileges 0.43 0.56 1.00 0.49 0.45 0.15 0.34 #> learning 0.62 0.60 0.49 1.00 0.64 0.12 0.53 #> raises 0.59 0.67 0.45 0.64 1.00 0.38 0.57 #> critical 0.16 0.19 0.15 0.12 0.38 1.00 0.28 #> advance 0.16 0.22 0.34 0.53 0.57 0.28 1.00 #> Sample Size #> [1] 30 #> Probability values (Entries above the diagonal are adjusted for multiple tests.) #> rating complaints privileges learning raises critical advance #> rating 0.00 0.00 0.19 0.00 0.01 1.00 1.00 #> complaints 0.00 0.00 0.02 0.01 0.00 1.00 1.00 #> privileges 0.02 0.00 0.00 0.07 0.15 1.00 0.51 #> learning 0.00 0.00 0.01 0.00 0.00 1.00 0.03 #> raises 0.00 0.00 0.01 0.00 0.00 0.36 0.01 #> critical 0.41 0.32 0.44 0.54 0.04 0.00 0.90 #> advance 0.41 0.23 0.06 0.00 0.00 0.13 0.00 #> #> To see confidence intervals of the correlations, print with the short=FALSE optioncorr.test(attitude[1:3],attitude[4:6]) #reports all values corrected for multiple tests#> Call:corr.test(x = attitude[1:3], y = attitude[4:6]) #> Correlation matrix #> learning raises critical #> rating 0.62 0.59 0.16 #> complaints 0.60 0.67 0.19 #> privileges 0.49 0.45 0.15 #> Sample Size #> [1] 30 #> Probability values adjusted for multiple tests. #> learning raises critical #> rating 0.00 0.00 0.96 #> complaints 0.00 0.00 0.96 #> privileges 0.03 0.05 0.96 #> #> To see confidence intervals of the correlations, print with the short=FALSE option#corr.test(sat.act[1:3],sat.act[4:6],adjust="none") #don't adjust the probabilities #take correlations and show the probabilities as well as the confidence intervals print(corr.p(cor(attitude[1:4]),30),short=FALSE)#> Call:corr.p(r = cor(attitude[1:4]), n = 30) #> Correlation matrix #> rating complaints privileges learning #> rating 1.00 0.83 0.43 0.62 #> complaints 0.83 1.00 0.56 0.60 #> privileges 0.43 0.56 1.00 0.49 #> learning 0.62 0.60 0.49 1.00 #> Sample Size #> [1] 30 #> Probability values (Entries above the diagonal are adjusted for multiple tests.) #> rating complaints privileges learning #> rating 0.00 0 0.02 0.00 #> complaints 0.00 0 0.00 0.00 #> privileges 0.02 0 0.00 0.01 #> learning 0.00 0 0.01 0.00 #> #> To see confidence intervals of the correlations, print with the short=FALSE option #> #> Confidence intervals based upon normal theory. To get bootstrapped values, try cor.ci #> lower r upper p #> ratng-cmpln 0.66 0.83 0.91 0.00 #> ratng-prvlg 0.08 0.43 0.68 0.02 #> cmpln-prvlg 0.34 0.62 0.80 0.00 #> ratng-lrnng 0.25 0.56 0.76 0.00 #> cmpln-lrnng 0.30 0.60 0.79 0.00 #> prvlg-lrnng 0.16 0.49 0.72 0.01#don't adjust the probabilities print(corr.test(sat.act[1:3],sat.act[4:6],adjust="none"),short=FALSE)#> Call:corr.test(x = sat.act[1:3], y = sat.act[4:6], adjust = "none") #> Correlation matrix #> ACT SATV SATQ #> gender -0.04 -0.02 -0.17 #> education 0.15 0.05 0.03 #> age 0.11 -0.04 -0.03 #> Sample Size #> ACT SATV SATQ #> gender 700 700 687 #> education 700 700 687 #> age 700 700 687 #> ACT SATV SATQ #> gender 0.33 0.62 0.00 #> education 0.00 0.22 0.36 #> age 0.00 0.26 0.37 #> #> To see confidence intervals of the correlations, print with the short=FALSE option #> #> Confidence intervals based upon normal theory. To get bootstrapped values, try cor.ci #> lower r upper p #> gendr-ACT -0.11 -0.04 0.04 0.33 #> edctn-ACT 0.08 0.15 0.23 0.00 #> age-ACT 0.04 0.11 0.18 0.00 #> gendr-SATV -0.09 -0.02 0.06 0.62 #> edctn-SATV -0.03 0.05 0.12 0.22 #> age-SATV -0.12 -0.04 0.03 0.26 #> gendr-SATQ -0.24 -0.17 -0.09 0.00 #> edctn-SATQ -0.04 0.03 0.11 0.36 #> age-SATQ -0.11 -0.03 0.04 0.37