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.
load carbig;
data = [Displacement Horsepower Weight Acceleration MPG];
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.
nans = sum(isnan(data),2) > 0;
X = data(~nans,1:3);
Y = data(~nans,4:5);
Compute the sample canonical correlation.
[A,B,r,U,V] = canoncorr(X,Y);
View the output of A to determine the linear combinations of displacement, horsepower, and weight that make up the canonical variables of X.
A
A = 3×2
0.0025 0.0048
0.0202 0.0409
-0.0000 -0.0027
A(3,1) is displayed as —0.000 because