title 'IMLSSCP: Computing Cross-product Summary Matrices'; * ------- -----------------------------------------; proc iml; reset print log fuzz fw=4; *[GREEN AND CARROLL, TABLE 2.3]; Y ={1 0 1 4 3 2 5 6 9 13 15 16}; X1={1 2 2 3 5 5 6 7 10 11 11 12}; X2={1 1 2 2 4 6 5 4 8 7 9 10}; *-- Shape variables into a matrix; A = t(Y)|| t(X1) || t(X2); reset fw=6; *-- 1. Raw cross-product matrix, X'X ; XPX = t(A) * A; *-- 2. (mean-corrected) SSCP matrix; MEAN = A[:,]; n = nrow(A); p = ncol(A); * subtract col means and take crossproducts; D = A - shape(MEAN, n, p); XPX = t(D) * D; *-- 3. variance - covariance matrix; COV = XPX / (n-1); *-- 4. correlation matrix; * Extract standard deviations, divide left and right; STD = diag(COV)##.5; CORR = inv(STD) * COV * inv(STD); *-- 5. labels for result; label = {Y X1 X2}; print COV[r=label c=label f=6.3] ' ' CORR[r=label c=label]; *-- 6. Using MATLIB functions; %include iml(matlib); d = dev(A); c = cov(A); r = corr(A); quit;