/* -------------------------------------------------------------------------- */ /* Lab 13: Canonical Correlation */ /* -------------------------------------------------------------------------- */ /* Reading the data from a txt file */ proc import datafile="E:\Teaching\Mulivariate S09\Lab 13\sales.xls" out=temp dbms=Excel; getnames=YES; data sales; set temp; drop id; run; /* We should be informed about the nature of our data */ proc univariate data=sales all; run; /* Let us look at some of the correlations */ proc corr data=sales; proc corr data=sales outs=salescorr; var growth profitability sales; proc corr data=sales outs=scorescorr; var creativity mech_reasoning abs_reasoning mathematics; data salescor; set salescorr; if _type_='CORR'; drop _name_ _type_; data scorescor; set scorescorr; if _type_='CORR'; drop _name_ _type_; run; /* Let us test some covariance structures */ proc iml; use salescor; read all into salescor [colname=name]; use scorescor; read all into scorescor [colname=name]; N = 50; p = 3; HOE = I(3); iHOE = inv(HOE); dHOE = det(HOE); dS = det(salescor); L = (N-1) * (log(dHOE) - log(dS) + trace(salescor*iHOE) - p); print L; chi_crit = 2*(gaminv(.99, ((p*(p+1))/2 ) )); print chi_crit; quit; /* Let us look at the structure of the matrix */ proc princomp data=sales; run; /* Let us carry out a canonical correlaion */ proc cancorr data=sales out=canout vprefix=sales vname="Sales Variables" wprefix=scores wname="Test Scores"; var growth profitability sales; with creativity mech_reasoning abs_reasoning mathematics; run; /* Investigative plots */ proc gplot; title 'Canonical Correlations: Sales1 by Scores1'; axis1 length=5 in; axis2 length=7.5 in; plot sales1*scores1 / vaxis=axis1 haxis=axis2; symbol v=J f=special h=1 i=r color=black; run; proc gplot; title 'Canonical Correlations: Sales2 by Scores2'; axis1 length=5 in; axis2 length=7.5 in; plot sales2*scores2 / vaxis=axis1 haxis=axis2; symbol v=J f=special h=1 i=r color=black; run; proc gplot; title 'Canonical Correlations: Sales3 by Scores3'; axis1 length=5 in; axis2 length=7.5 in; plot sales3*scores3 / vaxis=axis1 haxis=axis2; symbol v=J f=special h=1 i=r color=black; run; proc gplot; title 'Canonical Correlations: Sales1 by Scores3'; axis1 length=5 in; axis2 length=7.5 in; plot sales1*scores3 / vaxis=axis1 haxis=axis2; symbol v=J f=special h=1 i=r color=black; run; /* Let's verify */ proc corr data=sales cov; run; proc corr data=canout; var growth profitability sales sales1 sales2 sales3; run; proc corr data=canout; var creativity mech_reasoning abs_reasoning mathematics scores1 scores2 scores3; run;