Covariance, correlation, association measures for continuous variables

TODO

  • psych cor.plot()
  • link to diagScatter, diagMultivariate, association, associationOrder

Install required packages

coin, psych

Bivariate covariance and correlation

Covariance

Corrected (sample) covariance

[1] 19.2

Uncorrected (population) covariance

         x        y
x 21.88889 16.00000
y 16.00000 14.91667
[1] 16

Correlation

Empirical correlation

[1] 0.8854667

Fisher’s \(Z\)-transformation

Used, e.g., for averaging correlations

[1] 1.400533
[1] 0.8854667

Partial and semi-partial correlation

[1] -0.1620401

Partial correlation \(r_{(xy).z}\)

[1] -0.05298174
[1] 0.02470899

Semi-partial correlation \(r_{(x.z)y}\)

[1] -0.04772153

Covariance matrix

     X1 X2  X3
[1,] 19 95 197
[2,] 19 76 178
[3,] 31 94 189
[4,] 19 76 184
[5,] 24 76 173
      X1     X2   X3
X1 27.80  22.55  0.4
X2 22.55 102.80 82.4
X3  0.40  82.40 87.7
$cov
      X1    X2    X3
X1 22.24 18.04  0.32
X2 18.04 82.24 65.92
X3  0.32 65.92 70.16

$center
   X1    X2    X3 
 22.4  83.4 184.2 

$n.obs
[1] 5
      X1    X2    X3
X1 22.24 18.04  0.32
X2 18.04 82.24 65.92
X3  0.32 65.92 70.16

Correlation matrix

            X1        X2          X3
X1 1.000000000 0.4218204 0.008100984
X2 0.421820411 1.0000000 0.867822404
X3 0.008100984 0.8678224 1.000000000
              X1         X2         X3
[1,] -0.04054191 -0.1729373 -0.4405556

Correlation for ordinal continuous variables

Spearman’s \(\rho\)

[1] 0.7333333
            DV1        DV2        DV3        DV4
DV1  1.00000000  0.7333333 0.05487907 -0.1878788
DV2  0.73333333  1.0000000 0.11585581 -0.1636364
DV3  0.05487907  0.1158558 1.00000000  0.8963581
DV4 -0.18787879 -0.1636364 0.89635813  1.0000000

Kendall’s \(\tau\)-b

[1] 0.6444444
            DV1         DV2        DV3         DV4
DV1  1.00000000  0.64444444 0.02273314 -0.15555556
DV2  0.64444444  1.00000000 0.11366572 -0.06666667
DV3  0.02273314  0.11366572 1.00000000  0.79566006
DV4 -0.15555556 -0.06666667 0.79566006  1.00000000

Correlation tests

Pearson correlation


    Pearson's product-moment correlation

data:  DV1 and DV2
t = 3.4996, df = 8, p-value = 0.008084
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 0.2902442 0.9447410
sample estimates:
      cor 
0.7777418 
Call:corr.test(x = DVmat, adjust = "bonferroni")
Correlation matrix 
      DV1   DV2   DV3   DV4
DV1  1.00  0.78 -0.09 -0.35
DV2  0.78  1.00 -0.07 -0.39
DV3 -0.09 -0.07  1.00  0.89
DV4 -0.35 -0.39  0.89  1.00
Sample Size 
[1] 10
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
     DV1  DV2 DV3 DV4
DV1 0.00 0.05   1   1
DV2 0.01 0.00   1   1
DV3 0.80 0.86   0   0
DV4 0.32 0.27   0   0

 To see confidence intervals of the correlations, print with the short=FALSE option

Spearman’s \(\rho\)


    Spearman's rank correlation rho

data:  DV1 and DV2
S = 44, p-value = 0.02117
alternative hypothesis: true rho is not equal to 0
sample estimates:
      rho 
0.7333333 

    Approximative Spearman Correlation Test

data:  DV1 by DV2
Z = 2.2, p-value = 0.0207
alternative hypothesis: true rho is not equal to 0
Call:corr.test(x = DVmat, method = "spearman", adjust = "bonferroni")
Correlation matrix 
      DV1   DV2  DV3   DV4
DV1  1.00  0.73 0.05 -0.19
DV2  0.73  1.00 0.12 -0.16
DV3  0.05  0.12 1.00  0.90
DV4 -0.19 -0.16 0.90  1.00
Sample Size 
[1] 10
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
     DV1  DV2 DV3 DV4
DV1 0.00 0.09   1   1
DV2 0.02 0.00   1   1
DV3 0.88 0.75   0   0
DV4 0.60 0.65   0   0

 To see confidence intervals of the correlations, print with the short=FALSE option

Kendall’s \(\tau\)-b


    Kendall's rank correlation tau

data:  DV1 and DV2
T = 37, p-value = 0.009148
alternative hypothesis: true tau is not equal to 0
sample estimates:
      tau 
0.6444444 
Call:corr.test(x = DVmat, method = "kendall", adjust = "bonferroni")
Correlation matrix 
      DV1   DV2  DV3   DV4
DV1  1.00  0.64 0.02 -0.16
DV2  0.64  1.00 0.11 -0.07
DV3  0.02  0.11 1.00  0.80
DV4 -0.16 -0.07 0.80  1.00
Sample Size 
[1] 10
Probability values (Entries above the diagonal are adjusted for multiple tests.) 
     DV1  DV2  DV3  DV4
DV1 0.00 0.27 1.00 1.00
DV2 0.04 0.00 1.00 1.00
DV3 0.95 0.75 0.00 0.04
DV4 0.67 0.85 0.01 0.00

 To see confidence intervals of the correlations, print with the short=FALSE option

Difference between two independent correlations

Correlation tests 
Call:r.test(n = N, r12 = cor(DV1, DV2), r34 = cor(DV3, DV4), n2 = N)
Test of difference between two independent correlations 
 z value 0.73    with probability  0.46

Detach (automatically) loaded packages (if possible)

Get the article source from GitHub

R markdown - markdown - R code - all posts