I run the following Chapter 8 Section 8.9 code from Simulating Data with SAS (Wicklin 2013) and get different output than shown in Figure 8.17. What am I doing wrong? I also downloaded code from textbook web page and run it. It produces different results too. Any help is appreciated. Just curious.
Data A (type=corr);
_type_='CORR';
input x1-x3;
cards;
1.0 . .
0.7 1.0 .
0.2 0.4 1.0
;
run;
/* Obtain factor pattern matrix from PROC FACTOR */
*ods trace on;
proc factor data=A N=3 eigenvectors;
ods select FactorPattern;
run;
*ods trace off;
/* perform the same computation in SAS/IML language */
proc iml;
R={1.0 0.7 0.2, 0.7 1.0 0.4, 0.2 0.4 1.0};
/*factor pattern matrix via the eigenvalue decomp. R = U*diag(D)*U` = H`*H = F*F` */
call eigen(D, U, R);
/*F is returned by PROC FACTOR */
F=sqrt(D`) # U;
Verify=F*F`;
print F[format=8.5] Verify;
/*the following SAS/IML code statements simulate from an MVN distribution where the variables are correlated accaordingto the R matrix. The output */
/*shows that the columns of X are correlated and the sample correlation is close to R (the correlation matrix). The spectral decomposition is used*/
/*in Section 10.8 and Section 16.11. */
z=j(1000, 3);
/*uncorrelated normal obs: z~MVN(0,I) */
call randgen(z, "Normal");
/* Compute x` = F*z` or its transpose x = x*F` */
/* x ~ MVN(0,R) where R = FF` = corr matrix */
x=z*F`;
/* sample correlation is close to R */
corr=corr(x);
print corr[format=5.3];
call randgen(z, "Normal");