cancor: Canonical Correlations

Description Usage Arguments Details Value References See Also Examples

Description

Compute the canonical correlations between two data matrices.

Usage

1
cancor(x, y, xcenter = TRUE, ycenter = TRUE)

Arguments

x

numeric matrix (n * p1), containing the x coordinates.

y

numeric matrix (n * p2), containing the y coordinates.

xcenter

logical or numeric vector of length p1, describing any centering to be done on the x values before the analysis. If TRUE (default), subtract the column means. If FALSE, do not adjust the columns. Otherwise, a vector of values to be subtracted from the columns.

ycenter

analogous to xcenter, but for the y values.

Details

The canonical correlation analysis seeks linear combinations of the y variables which are well explained by linear combinations of the x variables. The relationship is symmetric as ‘well explained’ is measured by correlations.

Value

A list containing the following components:

cor

correlations.

xcoef

estimated coefficients for the x variables.

ycoef

estimated coefficients for the y variables.

xcenter

the values used to adjust the x variables.

ycenter

the values used to adjust the x variables.

References

Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988). The New S Language. Wadsworth & Brooks/Cole.

Hotelling H. (1936). Relations between two sets of variables. Biometrika, 28, 321–327. \Sexpr[results=rd,stage=build]{tools:::Rd_expr_doi("biomet/28.3-4.321")}.

Seber, G. A. F. (1984). Multivariate Observations. New York: Wiley. Page 506f.

See Also

qr, svd.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## signs of results are random
pop <- LifeCycleSavings[, 2:3]
oec <- LifeCycleSavings[, -(2:3)]
cancor(pop, oec)

x <- matrix(rnorm(150), 50, 3)
y <- matrix(rnorm(250), 50, 5)
(cxy <- cancor(x, y))
all(abs(cor(x %*% cxy$xcoef,
            y %*% cxy$ycoef)[,1:3] - diag(cxy $ cor)) < 1e-15)
all(abs(cor(x %*% cxy$xcoef) - diag(3)) < 1e-15)
all(abs(cor(y %*% cxy$ycoef) - diag(5)) < 1e-15)

Example output

$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 

$cor
[1] 0.4740416 0.4350887 0.1840635

$xcoef
            [,1]        [,2]         [,3]
[1,] -0.05805871 -0.11845027  0.003957496
[2,]  0.11271807 -0.03195520 -0.059697556
[3,]  0.04936375 -0.04839952  0.132880831

$ycoef
            [,1]        [,2]        [,3]        [,4]         [,5]
[1,]  0.11151932  0.04028142 -0.09406904 -0.07006153 -0.001090128
[2,] -0.11716955  0.01446688 -0.02261359 -0.08726157  0.110828044
[3,]  0.06774501  0.07576598  0.06276196 -0.03506544  0.100498319
[4,] -0.02131512 -0.12114322  0.03652535 -0.05148778  0.007506557
[5,]  0.01030764 -0.08657330 -0.05390988  0.07085360  0.094946659

$xcenter
[1]  0.06685727 -0.07592397  0.14567416

$ycenter
[1] -0.20781221  0.08918529 -0.16191806 -0.25456655 -0.02371629

[1] TRUE
[1] TRUE
[1] TRUE