The GVARCLUS Procedure

Example 12.3 Output the Covariance Matrix in LIL Format

This example shows how to output a covariance matrix in list-of-list (LIL) format.

The following DATA step generates a data table that has 2,000 observations and contains both interval variables (x1x2) and a categorical variable (a):

data mycas.data2;
    array x{2};
    do i=1 to 2000;
        a=int(rand('UNIFORM')*2);
        do j=1 to 2;
            x{j}=rand('UNIFORM');
        end;
        output;
    end;
run;

These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

The following statements invoke the GVARCLUS procedure:

 title  "Output the Covariance Matrix in LIL Format";

 proc gvarclus data=mycas.data2 maxiter=4 outcp=mycas.cov_lil/list eps=0.01;
     input a /level=nominal;
     input x1-x2 /level=interval;
 run;

 proc print data=mycas.cov_lil;
 run;

The OUTCP= option creates an output data table named mycas.cov_lil, which contains the covariance matrix. Output 12.3.1 shows the correlation matrix in LIL format.

Output 12.3.1: Output the Correlation Matrix in LIL Format

Output the Covariance Matrix in LIL Format

Obs_TYPE__ID__NAME1__NAME2__VAL_
1S1samples 2000.00
2S2nVar 3.00
3S3nEff 4.00
4M1x1 0.49
5M2x2 0.50
6F3a 0 993.00
7F4a 1 1007.00
8V111168.83
9V2210.20
10V322166.32
11V431-0.84
12V53211.87
13V633499.98
14V7410.84
15V842-11.87
16V943-499.98
17V1044499.98


The column _TYPE_ defines the type of each row:

  • When the _TYPE_ column displays S, the corresponding row contains the statistics of the data table. More specifically, when the _TYPE_ column displays S and the _NAME1_ column displays samples, the _VAL_ column in the corresponding row contains the number of samples in the data table. Similarly, when the _TYPE_ column displays S and the _NAME1_ column displays nVar, the _VAL_ column contains the number of variables. And when the _TYPE_ column displays S and the _NAME1_ column displays nEff, the _VAL_ column in the corresponding row contains the number of effects.

  • When the _TYPE_ column displays F, the row contains the frequency of a level of a nominal variable. In this case, the _NAME1_ column contains the name and level of the nominal variable.

  • When the _TYPE_ column displays M, the row contains the mean of an interval variable. In this case, the _NAME1_ column contains the name of the variable and the _NAME2_ column is empty.

  • When the _TYPE_ column displays R, the row contains an entry in the correlation matrix. In this case, the _NAME1_ column contains the row ID, the _NAME2_ column contains the column ID, and the _VAL_ column contains the value.

  • When the _TYPE_ column displays V or P, the corresponding row contains an entry of a COV matrix or an SSCP matrix, respectively.

Only entries in the lower triangle of the correlation matrix are written to the file, because the correlation matrix is symmetric. Also because EPS=0.01 is specified, any entry of the matrix whose value is smaller than 0.01 is ignored in the output; this saves storage space.

Last updated: December 09, 2022