Simple Biplot Example


dm "output;clear;log;clear";
******************************************************;
* bpdemo.sas -- Biplot Demonstration Using 2-D Data. *;
******************************************************;
Options PS=55 LS=90 NoNumber NoDate
        FORMCHAR='|----|+|---+=|-/\<>*';

Title1 "Biplot Examples";

Data One;
  Input Id $ X1-X2;
Datalines;
O 0 0
A 2 0
B 0 2
C 1.5 1.8
D 2.0 1.9
E 1.7 1.6
;

Proc Corr Data=One Cov;
 Var X1-X2;
Run;

Proc Iml;
 Reset Nolog NoPrint;
 Use One;
 Read All Var{X1 X2} Into X;
 Close One;
 N=NRow(X);
 One=J(n,1,1);
 Xbar=(X`*One)/n;        /* Find the Centroid */
 XTilde=X-One*Xbar`;     /* Center the Data */
 Call SVD(u,l,v,XTilde); /* Compute SVD */
 Title2 "Biplot Analysis -- Alpha=0 With n-1 Scaling";
 DGamma=diag(l);         /* Construct DGamma */
 G=U*sqrt(n-1);          /* Form G and H */
 H=V*DGamma*(1/sqrt(n-1));
 GGprime=G*G`;
 HHprime=H*H`;
 Print X,XTilde,U,DGamma,V,G,H,GGprime,HHprime;
 Create Obs From G;      /* Output the vectors for plotting */
 Append From G;
 Close Obs;
 Create Vars From H;
 Append From H;
 Close Vars;
Quit;

Data Obs;
 Merge Obs One;  /* Merge Back the ID information */
Run;

Data Vars;
 Set Vars;
 Id=Put(_N_,1.); /* Just Number the Variables */
Run;

Data Both;       /* Need Both Together for the Biplot */
 Set Vars Obs;
Run;

Title3 "Biplot Data -- Row and Column Coordinates";
Proc Print Data=Both;
 Var Id Col1 Col2;
Run;

Proc Plot Data=Both;
 Title2 "Observations in Original Variable Space";
 Plot X1*X2 $ Id="*" / VRef=0 HRef=0 Box 
     VAxis=By 0.5 HAxis=By 0.5 VPos=30 HPos=60;
Run;
 Title2 "Observations and Variables in Biplot";
 Plot Col2*Col1 $ Id="*" / VRef=0 HRef=0 Box 
     VAxis=By 0.5 HAxis=By 0.5 VPos=40 HPos=60;
Run; Quit;


                                     Biplot Examples

                                   Correlation Analysis

                            2 'VAR' Variables:  X1       X2      


                               Covariance Matrix     DF = 5

                                            X1                X2

                          X1      0.9000000000      0.0920000000
                          X2      0.0920000000      0.9056666667


                                    Simple Statistics
 
  Variable            N         Mean      Std Dev          Sum      Minimum      Maximum

  X1                  6      1.20000      0.94868      7.20000            0      2.00000
  X2                  6      1.21667      0.95167      7.30000            0      2.00000


         Pearson Correlation Coefficients / Prob > |R| under Ho: Rho=0 / N = 6  

                                            X1                X2

                          X1           1.00000           0.10190
                                        0.0               0.8477

                          X2           0.10190           1.00000
                                        0.8477            0.0   


                                     Biplot Examples

                                           X
                                           0         0
                                           2         0
                                           0         2
                                         1.5       1.8
                                           2       1.9
                                         1.7       1.6


                                      XTILDE
                                        -1.2 -1.216667
                                         0.8 -1.216667
                                        -1.2 0.7833333
                                         0.3 0.5833333
                                         0.8 0.6833333
                                         0.5 0.3833333


                                           U
                                   -0.766173 -0.007212
                                   -0.141927 0.7059029
                                   -0.122406 -0.698703
                                   0.2814024 -0.094718
                                   0.4696523 0.0489865
                                   0.2794503 0.0457429


                                      DGAMMA
                                   2.2303329         0
                                           0  2.013442


                                           V
                                   0.6961385 0.7179076
                                   0.7179076 -0.696138


                                           G
                                   -1.713214 -0.016126
                                   -0.317357 1.5784468
                                   -0.273707 -1.562347
                                   0.6292348 -0.211795
                                   1.0501744 0.1095371
                                   0.6248698 0.1022843


                                           H
                                    0.694353 0.6464317
                                   0.7160663  -0.62683



                                     Biplot Examples
                       Biplot Analysis -- Alpha=0 With n-1 Scaling

                 GGPRIME
               2.9353637  0.518247 0.4941138 -1.074599  -1.80094 -1.072185
                0.518247 2.5922101 -2.379219    -0.534 -0.160382 -0.036857
               0.4941138 -2.379219 2.5158436 0.1586713 -0.458575 -0.330835
               -1.074599    -0.534 0.1586713 0.4407936 0.6376069 0.3715265
                -1.80094 -0.160382 -0.458575 0.6376069 1.1148647 0.6674262
               -1.072185 -0.036857 -0.330835 0.3715265 0.6674262 0.4009243


                                     HHPRIME
                                         0.9     0.092
                                       0.092 0.9056667



                                     Biplot Examples
                       Biplot Analysis -- Alpha=0 With n-1 Scaling
                        Biplot Data -- Row and Column Coordinates

                            OBS    ID      COL1        COL2

                             1     1      0.69435     0.64643
                             2     2      0.71607    -0.62683
                             3     O     -1.71321    -0.01613
                             4     A     -0.31736     1.57845
                             5     B     -0.27371    -1.56235
                             6     C      0.62923    -0.21180
                             7     D      1.05017     0.10954
                             8     E      0.62487     0.10228


                                     Biplot Examples
                         Observations in Original Variable Space

                         Plot of X1*X2$ID.  Symbol used is '*'.

                --+-------------+-------------+-------------+-------------+---
             X1 | |                                                          |
            2.0 + * A                                                  * D   +
                | |                                                          |
                | |                                                          |
                | |                                                          |
                | |                                            * E           |
                | |                                                          |
                | |                                                          |
            1.5 + |                                                 * C      +
                | |                                                          |
                | |                                                          |
                | |                                                          |
                | |                                                          |
                | |                                                          |
                | |                                                          |
            1.0 + |                                                          +
                | |                                                          |
                | |                                                          |
                | |                                                          |
                | |                                                          |
                | |                                                          |
                | |                                                          |
            0.5 + |                                                          +
                | |                                                          |
                | |                                                          |
                | |                                                          |
                | |                                                          |
                | |                                                          |
                | |                                                          |
            0.0 +-*-O-----------------------------------------------------*-B+
                --+-------------+-------------+-------------+-------------+---
                 0.0           0.5           1.0           1.5           2.0

                                              X2

NOTE: 2 obs had missing values.


                                     Biplot Examples
                           Observations and Variables in Biplot

                       Plot of COL2*COL1$ID.  Symbol used is '*'.

                --+-------+-------+-------+-------+-------+-------+-------+---
           COL2 |                                 |                          |
                |                                 |                          |
                |                                 |                          |
                |                                 |                          |
            2.0 +                                 |                          +
                |                                 |                          |
                |                                 |                          |
                |                            * A  |                          |
            1.5 +                                 |                          +
                |                                 |                          |
                |                                 |                          |
                |                                 |                          |
            1.0 +                                 |                          +
                |                                 |                          |
                |                                 |                          |
                |                                 |          * 1             |
            0.5 +                                 |                          +
                |                                 |                          |
                |                                 |                          |
                |                                 |         * E    * D       |
            0.0 +------*-O------------------------+--------------------------+
                |                                 |                          |
                |                                 |         * C              |
                |                                 |                          |
           -0.5 +                                 |                          +
                |                                 |          * 2             |
                |                                 |                          |
                |                                 |                          |
           -1.0 +                                 |                          +
                |                                 |                          |
                |                                 |                          |
                |                                 |                          |
           -1.5 +                             * B |                          +
                |                                 |                          |
                |                                 |                          |
                |                                 |                          |
           -2.0 +                                 |                          +
                |                                 |                          |
                |                                 |                          |
                |                                 |                          |
                --+-------+-------+-------+-------+-------+-------+-------+---
                -2.0    -1.5    -1.0    -0.5     0.0     0.5     1.0     1.5

                                             COL1