Perform canonical correlation analysis for a sample data set.
The data set carbig
contains measurements for 406 cars from the years 1970 to 1982.
Load the sample data.
Define X as the matrix of displacement, horsepower, and weight observations, and Y
as the matrix of acceleration and MPG observations. Omit rows with insufficient data.
Compute the sample canonical correlation.
View the output of A
to determine the linear combinations of displacement, horsepower, and weight that make up the canonical variables of X
.
A = 3×2
0.0025 0.0048
0.0202 0.0409
-0.0000 -0.0027
A(3,1)
is displayed as —0.000
because it is very small. Display A(3,1)
separately.
The first canonical variable of X
is u1 = 0.0025*Disp + 0.0202*HP — 0.000025*Wgt
.
The second canonical variable of X
is u2 = 0.0048*Disp + 0.0409*HP — 0.0027*Wgt
.
View the output of B to determine the linear combinations of acceleration and MPG that make up the canonical variables of Y
.
B = 2×2
-0.1666 -0.3637
-0.0916 0.1078
The first canonical variable of Y
is v1 =
—
0.1666*Accel — 0.0916*MPG
.
The second canonical variable of Y
is v2 = —0.3637*Accel + 0.1078*MPG
.
Plot the scores of the canonical variables of X
and Y
against each other.
The pairs of canonical variables are ordered from the strongest to weakest correlation, with all other pairs independent.
Return the correlation coefficient of the variables u1
and v1
.