Examples for 'stats::cancor'


Canonical Correlations

Aliases: cancor

Keywords: multivariate

### ** Examples
## No test: 
## signs of results are random
pop <- LifeCycleSavings[, 2:3]
oec <- LifeCycleSavings[, -(2:3)]
cancor(pop, oec)
$cor
[1] 0.8247966 0.3652762

$xcoef
              [,1]        [,2]
pop15 -0.009110856 -0.03622206
pop75  0.048647514 -0.26031158

$ycoef
             [,1]          [,2]          [,3]
sr   0.0084710221  3.337936e-02 -5.157130e-03
dpi  0.0001307398 -7.588232e-05  4.543705e-06
ddpi 0.0041706000 -1.226790e-02  5.188324e-02

$xcenter
  pop15   pop75 
35.0896  2.2930 

$ycenter
       sr       dpi      ddpi 
   9.6710 1106.7584    3.7576 
x <- matrix(rnorm(150), 50, 3)
y <- matrix(rnorm(250), 50, 5)
(cxy <- cancor(x, y))
$cor
[1] 0.3967470 0.2107417 0.1968901

$xcoef
            [,1]       [,2]        [,3]
[1,] -0.06593589 0.06098358 -0.09286588
[2,]  0.14700126 0.05603381 -0.03842151
[3,]  0.01479996 0.11122547  0.09586480

$ycoef
             [,1]        [,2]         [,3]        [,4]        [,5]
[1,]  0.132695761 -0.06085018 0.0034372155  0.01154641 -0.04490352
[2,] -0.051253981  0.01609133 0.0411734250  0.05190233 -0.13563171
[3,]  0.004648237 -0.06186305 0.0005624683  0.14340079  0.02828000
[4,]  0.091812844  0.10166133 0.0386736084  0.08020767  0.01687649
[5,]  0.008859536 -0.03213775 0.1230839807 -0.02351713  0.01795242

$xcenter
[1] -0.01811724  0.13713736 -0.04103393

$ycenter
[1]  0.30596509 -0.36281399 -0.07622503 -0.05677703  0.26467548
all(abs(cor(x %*% cxy$xcoef,
            y %*% cxy$ycoef)[,1:3] - diag(cxy $ cor)) < 1e-15)
[1] TRUE
all(abs(cor(x %*% cxy$xcoef) - diag(3)) < 1e-15)
[1] TRUE
all(abs(cor(y %*% cxy$ycoef) - diag(5)) < 1e-15)
[1] TRUE
## End(No test)

[Package stats version 4.2.3 Index]