## canoncor
using CrossDecomposition

X = [160.0 110 2.62 6
     160.0 110 2.875 6
     108.0 93 2.32 4
     258.0 110 3.215 6
     360.0 175 3.44 8
     225.0 105 3.46 6
     360.0 245 3.57 8
     146.7 62 3.19 4
     140.8 95 3.15 4
     167.6 123 3.44 6
     167.6 123 3.44 6
     275.8 180 4.07 8
     275.8 180 3.73 8
     275.8 180 3.78 8
     472.0 205 5.25 8
     460.0 215 5.424 8]
Y = [16.46 21.0
     17.02 21.0
     18.61 22.8
     19.44 21.4
     17.02 18.7
     20.22 18.1
     15.84 14.3
     20.0 24.4
     22.9 22.8
     18.3 19.2
     18.9 17.8
     17.4 16.4
     17.6 17.3
     18.0 15.2
     17.98 10.4
     17.82 10.4]
A = [ 1.417788386933145e-03  1.619236144909564e-03
     -9.775332442210499e-03  3.015914504480319e-03
     -7.812617447495859e-01 -1.604151289980122e+00
     -6.342024071259623e-02  6.801644113699129e-01]
B = [-1.229427332898298e-02 -6.479515829537731e-01
      2.432486132778393e-01  1.108089157422447e-01]
r = [ 9.613653095850392e-01, 7.566050927132359e-01]
U = [ 9.746560063604041e-01  9.183060808915435e-01
      7.754342614492598e-01  5.092475019466127e-01
      1.428330666607527e+00 -9.624818096570786e-02
      6.487485301538487e-01  1.225212055545089e-01
     -1.446580371165023e-01  1.483112517620803e+00
      4.594290481324588e-01  3.390102257950384e-01
     -9.304953348886833e-01  1.485686865237010e+00
      1.106536664958226e+00 -1.522688714079304e+00
      8.068362126723572e-01 -1.368550977087215e+00
      2.177172456576991e-01 -3.455848936325991e-01
      2.177172456576991e-01 -3.455848936325991e-01
     -8.051073806995649e-01  3.512370940543424e-01
     -5.394783874847054e-01  8.966485326475844e-01
     -5.785414747221846e-01  8.164409681485786e-01
     -1.693209469043055e+00 -1.148569433878937e+00
     -1.943915797694787e+00 -1.416963447029590e+00]
V = [ 7.042631384822526e-01  1.531248728206803e+00
      6.973783454180221e-01  1.168395841752691e+00
      1.115677954725050e+00  3.376088731922320e-01
      7.649256492730188e-01 -3.553234226985437e-01
      1.379065348789915e-01  9.135353355455278e-01
     -4.738430774045706e-02 -1.226395079351892e+00
     -9.178801210153013e-01  1.190558974165103e+00
      1.487786696042306e+00 -3.857495619259218e-01
      1.062935522143713e+00  2.442103417679454e+00
      2.437941716568130e-01  1.395617672358198e-01
     -1.041304509295515e-01 -4.043416645755850e-01
     -4.262370995250526e-01  4.124532278159319e-01
     -2.097722022407933e-01  3.825909353931958e-01
     -7.255119994558495e-01 -1.092884208470264e-01
     -1.892859457722898e+00 -6.282121847507255e-01
     -1.890892373990261e+00 -5.245399314781217e-01]

cc = canoncor(X, Y)
@test_approx_eq r cor(cc)
(cA, cB) = coef(cc)
@test_approx_eq A cA
@test_approx_eq B cB
cvA, cvB = map(cov, scores(cc))
@test_approx_eq eye(2) cvA
@test_approx_eq eye(2) cvB 
