Python Igraph
Python Igraph
Nathaniel E. Helwig
Updated 16-Mar-2017
Copyright
c 2017 by Nathaniel E. Helwig
Canonical Correlations
The first pair of canonical variates (U1 , V1 ) is defined via the pair of
linear combination vectors {a1 , b1 } that maximize
Cov(U, V ) a0 ΣXY b
Cor(U, V ) = p =√ 0 √
a ΣX a b0 ΣY b
p
Var(U) Var(V )
subject to U1 and V1 having unit variance.
where
−1/2 −1/2
uk is the k -th eigenvector of ΣX ΣXY Σ−1
Y ΣYX ΣX
−1/2 −1/2
vk is the k -th eigenvector of ΣY ΣYX Σ−1
X ΣXY ΣY
Cor(Uk , Vk ) = ρk
−1/2 −1/2
where ρ2k is the k -th eigenvalue of ΣX ΣXY Σ−1
Y ΣYX ΣX
−1/2 −1/2
[ρ2k is also the k -th eigenvalue of ΣY ΣYX Σ−1
X ΣXY ΣY ]
Nathaniel E. Helwig (U of Minnesota) Canonical Correlation Analysis Updated 16-Mar-2017 : Slide 8
Canonical Correlations Population Definition
Cov(U, X ) = Cov(A0 X , X ) = A0 ΣX
Cov(U, Y ) = Cov(A0 X , Y ) = A0 ΣXY
Cov(V , X ) = Cov(B0 Y , X ) = B0 ΣYX
Cov(V , Y ) = Cov(B0 Y , Y ) = B0 ΣY
If the first few pairs of canonical variables do not well explain the
variability in ΣX and ΣY , then the interpretation becomes less clear.
and let the sample mean vector and covariance matrix be denoted by
x̄ SX SXY
z̄ = and S =
ȳ SYX SY
where
Pn Pn
x̄ = (1/n) i=1 xi and ȳ = (1/n) i=1 yi
1 Pn 0
SX = n−1 i=1 (xi − x̄)(xi − x̄)
1 Pn 0
SY = n−1 i=1 (yi − ȳ)(yi − ȳ)
1 Pn
SXY = S0YX = n−1 i=1 (xi − x̄)(yi − ȳ)
0
The first pair of sample canonical variates (U1 , V1 ) is defined via the
pair of linear combination vectors {a1 , b1 } that maximize
Cov(U,
d V) a0 SXY b
Cor(U,
d V) = q =√ 0 √
a SX a b0 SY b
q
Var(U)
c c )
Var(V
subject to U1 and V1 having unit variance.
where
−1/2 −1/2
ûk is the k -th eigenvector of SX SXY S−1
Y SYX SX
−1/2 −1/2
v̂k is the k -th eigenvector of SY SYX S−1
X SXY SY
d Â0 X , X ) = Â0 SX
d Û, X ) = Cov(
Cov(
d Â0 X , Y ) = Â0 SXY
d Û, Y ) = Cov(
Cov(
d B̂0 Y , X ) = B̂0 SYX
d V̂ , X ) = Cov(
Cov(
d B̂0 Y , Y ) = B̂0 SY
d V̂ , Y ) = Cov(
Cov(
d Û) = Â0 SX Â = Ip
Cov(
Â0 SX Â = Ip
(Â0 )−1 Â0 SX Â(Â−1 ) = (Â0 )−1 (Â−1 )
SX = (Â−1 )0 (Â−1 )
p
X
= (â(j) )(â(j) )0
j=1
d V̂) = B̂0 SY B̂ = Iq
Cov(
B̂0 SY B̂ = Iq
(B̂0 )−1 B̂0 SY B̂(B̂−1 ) = (B̂0 )−1 (B̂−1 )
SY = (B̂−1 )0 (B̂−1 )
q
X
= (b̂(j) )(b̂(j) )0
j=1
The error matrices provide a descriptive measure of how well the first r
pairs of canonical variates explain the covariation in the data.
Nathaniel E. Helwig (U of Minnesota) Canonical Correlation Analysis Updated 16-Mar-2017 : Slide 20
Canonical Correlations Large Sample Inference
Decathlon Example
> decathlon[1:9,]
run100 long.jump shot high.jump run400 hurdle discus pole.vault javelin run1500 score
Schenk 11.25 7.43 15.48 2.27 48.90 15.13 49.28 4.7 61.32 268.95 8488
Voss 10.87 7.45 14.97 1.97 47.71 14.46 44.36 5.1 61.76 273.02 8399
Steen 11.18 7.44 14.20 1.97 48.29 14.81 43.66 5.2 64.16 263.20 8328
Thompson 10.62 7.38 15.02 2.03 49.06 14.72 44.80 4.9 64.04 285.11 8306
Blondel 11.02 7.43 12.92 1.97 47.44 14.40 41.20 5.2 57.46 256.64 8286
Plaziat 10.83 7.72 13.58 2.12 48.34 14.18 43.06 4.9 52.18 274.07 8272
Bright 11.18 7.05 14.12 2.06 49.34 14.39 41.68 5.7 61.60 291.20 8216
De.Wit 11.05 6.95 15.34 2.00 48.21 14.36 41.32 4.8 63.00 265.86 8189
Johnson 11.15 7.12 14.52 2.03 49.15 14.66 42.36 4.9 66.46 269.62 8180
X Coefficients Y Coefficients
0.5
6
discus high.jump
4
javelin
0.0
A2 Coefficients
B2 Coefficients
2
−0.5
long.jump
run400
0
run1500
shot run100
−1.0
pole.vault hurdle
−2
−2.0 −1.5 −1.0 −0.5 0.0 −2.0 −1.5 −1.0 −0.5 0.0
A1 Coefficients B1 Coefficients
> round(cov(V),4)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 0 0 0 0 0
[2,] 0 1 0 0 0 0
[3,] 0 0 1 0 0 0
[4,] 0 0 0 1 0 0
[5,] 0 0 0 0 1 0
[6,] 0 0 0 0 0 1
> round(cov(U,V),4)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.7702 0.0000 0.0000 0.0000 0 0
[2,] 0.0000 0.5034 0.0000 0.0000 0 0
[3,] 0.0000 0.0000 0.4184 0.0000 0 0
[4,] 0.0000 0.0000 0.0000 0.3053 0 0
> rho
[1] 0.7702006 0.5033532 0.4184145 0.3052556
X Coefficients Y Coefficients
2.0
discus run400
high.jump
1.5
0.5
long.jump
1.0
A2 Coefficients
B2 Coefficients
0.0
0.5
javelin
run100
−0.5
−0.5
pole.vault
−1.0
shot
−1.5
hurdle run1500
−2.0 −1.5 −1.0 −0.5 0.0 −0.4 −0.2 0.0 0.2 0.4
A1 Coefficients B1 Coefficients
If Xs = {(xij − x̄j )/sxj }n×p and Ys = {(yij − ȳj )/syj }n×q , then
Û = Xs  = {ûij }n×p where columns of Û contain the canonical
variables for the Xs set
V̂ = Ys B̂ = {v̂ij }n×q where columns of V̂ contain the canonical
variables for the Ys set
> round(cov(V),4)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 0 0 0 0 0
[2,] 0 1 0 0 0 0
[3,] 0 0 1 0 0 0
[4,] 0 0 0 1 0 0
[5,] 0 0 0 0 1 0
[6,] 0 0 0 0 0 1
> round(cov(U,V),4)
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.7702 0.0000 0.0000 0.0000 0 0
[2,] 0.0000 0.5034 0.0000 0.0000 0 0
[3,] 0.0000 0.0000 0.4184 0.0000 0 0
[4,] 0.0000 0.0000 0.0000 0.3053 0 0
> rho
[1] 0.7702006 0.5033532 0.4184145 0.3052556