Output from gramdemo.sas

Source
0 Graphs

Output from gramdemo.sas

NOTE: Capture of log output started.

NOTE: %INCLUDE (level 1) file c:\sasuser\psy6140\examples\iml\gramdemo.sas is
      file c:\sasuser\psy6140\examples\iml\gramdemo.sas.
544  +title 'GramDemo: Gram-Schmidt Process';
545  +data class;
546  +   input name $ sex $ age height weight;
547  +   male = (sex='M');
548  +   IQ = round(30 + height + 3*age - .1*weight -3*male +
548 !+10*normal(123411));
549  +cards;

NOTE: The data set WORK.CLASS has 15 observations and 7 variables.
565  +;
566  +proc print;
567  +	id name;
568  +	run;

NOTE: There were 15 observations read from the data set WORK.CLASS.
569  +
570  +proc iml;
NOTE: IML Ready
571  +	%include iml(matlib);
NOTE: Module ROW defined.
NOTE: Module COL defined.
NOTE: Module R defined.
NOTE: Module MINOR defined.
NOTE: Module COFACTOR defined.
NOTE: Module PROJ defined.
NOTE: Module LEN defined.
NOTE: Module DEV defined.
NOTE: Module SCP defined.
NOTE: Module CORR defined.
NOTE: Module COV defined.
NOTE: Module ROWADD defined.
NOTE: Module ROWSWAP defined.
NOTE: Module ROWMULT defined.
NOTE: Module MPOWER defined.
NOTE: Module MEDIAN defined.
806  +	
806 !+ reset print log fuzz fw=6;
807  +	
808  +	
808 !+ use class;
808 !+               *-- access the class dataset;
809  +	
809 !+ read all var{height age weight male} into X[r=name c=vars];


























                    X     15 rows      4 cols    (numeric)


                             height    age weight   male
                     Alfred      69     14  112.5      1
                     Alice     56.5     13     84      0
                     Barbara   65.3     13     98      0
                     Carol     62.8     14  102.5      0
                     Henry     63.5     14  102.5      1
                     James     57.3     12     83      1
                     Jane      59.8     12   84.5      0
                     Janet     62.5     15  112.5      0
                     Jeffrey   62.5     13     84      1
                     John        59     12   99.5      1
                     Joyce     51.3     11   50.5      0
                     Judy      64.3     14     90      0
                     Louise    56.3     12     77      0
                     Mary      66.5     15    112      0
                     Philip      72     16    150      1
810  +	
810 !+ read all var{IQ}                     into Y;

                    Y     15 rows      1 col     (numeric)



                                       117
                                       112
                                       120
                                       117
                                       142
                                       109
                                       111
                                       142
                                       133
                                       101
                                       107
                                       130
                                       111
                                       114
                                       130
811  +	
812  +	
812 !+ XPX = t(X) * X;

                   XPX      4 rows      4 cols    (numeric)



                          57888  12470  90775  383.3
                          12470   2694  19614     81
                          90775  19614 145594  631.5
                          383.3     81  631.5      6
813  +	
814  +	*-- Do the Gram-Schmidt;
815  +	
815 !+ Z1 = X[,1];

                   Z1     15 rows      1 col     (numeric)



                                        69
                                      56.5
                                      65.3
                                      62.8
                                      63.5
                                      57.3
                                      59.8
                                      62.5
                                      62.5
                                        59
                                      51.3
                                      64.3
                                      56.3
                                      66.5
                                        72
816  +	
816 !+ Z2 = X[,2] - proj(X[,2], Z1);

                   Z2     15 rows      1 col     (numeric)



                                    -0.864
                                    0.8287
                                    -1.067
                                    0.4715
                                    0.3207
                                    -0.344
                                    -0.882
                                    1.5362
                                    -0.464
                                     -0.71
                                    -0.051
                                    0.1484
                                    -0.128
                                    0.6745
                                    0.4897
817  +	
817 !+ Z3 = X[,3] - proj(X[,3], Z1) - proj(X[,3], Z2);

                   Z3     15 rows      1 col     (numeric)



                                    11.011
                                    -11.03
                                     3.889
                                     0.361
                                    0.4344
                                    -4.184
                                    -2.422
                                    2.5637
                                     -10.4
                                    12.494
                                    -29.55
                                    -11.98
                                    -10.29
                                     2.483
                                    33.294
818  +	
818 !+ Z4 = X[,4] - proj(X[,4], Z1) - proj(X[,4], Z2) - proj(X[,4], Z3);

                   Z4     15 rows      1 col     (numeric)



                                    0.1964
                                    -0.034
                                    -0.712
                                    -0.324
                                    0.6391
                                    0.6136
                                    -0.541
                                    -0.136
                                    0.6494
                                    0.2718
                                    0.1014
                                    -0.212
                                    -0.242
                                    -0.339
                                    0.1154
819  +	
820  +	*-- assmble the pieces;
821  +	
821 !+ Z = Z1 || Z2 || Z3 || Z4;

                    Z     15 rows      4 cols    (numeric)



                             69 -0.864 11.011 0.1964
                           56.5 0.8287 -11.03 -0.034
                           65.3 -1.067  3.889 -0.712
                           62.8 0.4715  0.361 -0.324
                           63.5 0.3207 0.4344 0.6391
                           57.3 -0.344 -4.184 0.6136
                           59.8 -0.882 -2.422 -0.541
                           62.5 1.5362 2.5637 -0.136
                           62.5 -0.464  -10.4 0.6494
                             59  -0.71 12.494 0.2718
                           51.3 -0.051 -29.55 0.1014
                           64.3 0.1484 -11.98 -0.212
                           56.3 -0.128 -10.29 -0.242
                           66.5 0.6745  2.483 -0.339
                             72 0.4897 33.294 0.1154
822  +	
823  +	*-- make each col unit length;
824  +	
824 !+ Z = Z * diag( 1 / len(Z) ) ;

                    Z     15 rows      4 cols    (numeric)



                         0.2868 -0.313 0.2085 0.1246
                         0.2348 0.3004 -0.209 -0.022
                         0.2714 -0.387 0.0736 -0.452
                          0.261  0.171 0.0068 -0.205
                         0.2639 0.1163 0.0082 0.4054
                         0.2382 -0.125 -0.079 0.3892
                         0.2485  -0.32 -0.046 -0.343
                         0.2598 0.5569 0.0485 -0.086
                         0.2598 -0.168 -0.197 0.4119
                         0.2452 -0.257 0.2366 0.1724
                         0.2132 -0.019 -0.559 0.0643
                         0.2672 0.0538 -0.227 -0.134
                          0.234 -0.046 -0.195 -0.153
                         0.2764 0.2445  0.047 -0.215
                         0.2993 0.1775 0.6303 0.0732
825  +	
826  +	*-- Check whether orthonormal;
827  +	
827 !+ ZPZ = t(Z) * Z;

                   ZPZ      4 rows      4 cols    (numeric)



                              1      0      0      0
                              0      1      0      0
                              0      0      1      0
                              0      0      0      1
828  +
829  +  *-- Verify with GSORTH;
830  +  call gsorth(ZZ,T,flag,X);

                   ZZ     15 rows      4 cols    (numeric)



                         0.2868 -0.313 0.2085 0.1246
                         0.2348 0.3004 -0.209 -0.022
                         0.2714 -0.387 0.0736 -0.452
                          0.261  0.171 0.0068 -0.205
                         0.2639 0.1163 0.0082 0.4054
                         0.2382 -0.125 -0.079 0.3892
                         0.2485  -0.32 -0.046 -0.343
                         0.2598 0.5569 0.0485 -0.086
                         0.2598 -0.168 -0.197 0.4119
                         0.2452 -0.257 0.2366 0.1724
                         0.2132 -0.019 -0.559 0.0643
                         0.2672 0.0538 -0.227 -0.134
                          0.234 -0.046 -0.195 -0.153
                         0.2764 0.2445  0.047 -0.215
                         0.2993 0.1775 0.6303 0.0732



                    T      4 rows      4 cols    (numeric)



                          240.6  51.83 377.29 1.5931
                              0 2.7583  21.42  -0.57
                              0      0 52.819 0.8074
                              0      0      0 1.5766



                  FLAG      1 row       1 col     (numeric)



                                         0
831  +  OK = all(ZZ = Z);

                   OK      1 row       1 col     (numeric)


                                         0
832  +
833  +	*-- Send results back to a SAS data set;	
834  +	
834 !+ zvars = {zheight zage zweight zmale};

             ZVARS      1 row       4 cols    (character, size 7)



                       ZHEIGHT ZAGE    ZWEIGHT ZMALE
835  +	
835 !+ create class2 from Z[c=zvars];
835 !+                               	
836  +	
836 !+ append from Z;
837  +	quit;
NOTE: Exiting IML.
NOTE: The data set WORK.CLASS2 has 15 observations and 4 variables.































838  +	
839  +data all;
840  +	merge class class2;
841  +run;

NOTE: There were 15 observations read from the data set WORK.CLASS.
NOTE: There were 15 observations read from the data set WORK.CLASS2.
NOTE: The data set WORK.ALL has 15 observations and 11 variables.
842  +
843  +*--Compare prediction of IQ from the two sets;
844  +proc reg data=all;
845  +	m1: model IQ =  height  age  weight  male / ss1;
846  +	m2: model IQ = zheight zage zweight zmale / ss1;
847  +	run;
848  +
849  +
NOTE: %INCLUDE (level 1) ending.