The GVARCLUS Procedure

Getting Started: GVARCLUS Procedure

Note: Input data must be in a CAS table that is accessible in your CAS session. You must refer to this table by using a two-level name. The first level must be a CAS engine libref, and the second level must be the table name. For more information, see the sections Using CAS Sessions and CAS Engine Librefs and Loading a SAS Data Set onto a CAS Server in Chapter 2, Shared Concepts.

This example demonstrates how you can use the GVARCLUS procedure to cluster variables into homogeneous groups and construct a hierarchy.

The following DATA step generates a data table and loads the table into your CAS session. The table consists of 100 observations and 20 continuous variables (x1–x20). There are two groups of five variables, and 10 variables that are randomly generated from an uniform distribution. The initial variables for each group, x1 and x6, are independently generated from a normal distribution. Two of the variables from each group are linearly correlated to their initial variables, and the other two variables have a nonlinear relationship.

data mycas.getStarted;
    array x{20}  x1-x20;
    do i = 1 to 100;
        x1=rannor(12334); x2=0.9*x1+0.2; x3=0.7*x1+0.6; x4=x3*x2*x1; x5=x1*x1*x1;
        x6=rannor(56757); x7=0.9*x6+0.2; x8=0.7*x6+0.6; x9=x8*x6; x10=x6*x6*x6;
        do j= 11 to 20;
            x{j} = ranuni(10);
        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 execute the GVARCLUS algorithm on the mycas.getStarted data table:

 proc gvarclus data=mycas.getStarted mincluster=2 maxsteps=8
               rho=0.8 outtree=mycas.dendrogram;
     input x1-x20 / level=interval;
 run;

The INPUT statement defines the input variables x1 to x20 as interval variables. The MINCLUSTER= option in the PROC GVARCLUS statement specifies the minimum number of clusters as 2, so the clustering process stops when the number of clusters is less than or equal to 2. The MAXSTEPS= option specifies the maximum number of steps in the clustering process as 8. The RHO= option specifies a value of 0.8, which determines the sequence of regularization parameters left-bracket 0.8 Superscript 1 Baseline comma 0.8 squared comma 0.8 cubed comma ellipsis right-bracket that are used in each step sequentially. The OUTTREE= option creates the mycas.dendrogram table to contain information about the tree structure of hierarchical clustering.

The output from this analysis is presented in Figure 1 and Figure 2.

Figure 1 displays the "Number of Observations" tables. This table shows that all 100 observations in the data table are used in the analysis.

Figure 1: Number of Observations

The GVARCLUS Procedure

Number of Observations Read100
Number of Observations Used100


Figure 2 shows the "Cluster Summary" table, which shows the cluster structure in each step. The variable (or level for nominal variables) is assigned to a unique cluster in each step, and the clusters from sequential steps are nested to form a hierarchical structure.

Figure 2: Cluster Summary

Cluster Summary
ParameterStep 1Step 2Step 3Step 4Step 5Step 6Step 7Step 8
x11193652688296108
x22193652688296108
x33203652688296108
x44213753698396108
x55223854688296108
x66233955708497109
x76233955708497109
x86233955708497109
x97244056718597109
x108254157708497109
x119264258728698110
x1210274359738799111
x13112844607488100112
x14122945617589101113
x15133046627690102114
x16143147637791103115
x17153248647892104116
x18163349657993105117
x19173450668094106118
x20183551678195107119


You can define a dendrogram in the Graph Template Language (GTL) and display the hierarchical clustering results from the GVARCLUS algorithm.

The following code copies mycas.dendrogram into the Work library:

data outtree;
    set mycas.dendrogram;
run;

The following code defines the parent node, child node and the height in the dendrogram through the DENDROGRAM statement in GTL. The dendrogram is then plotted using the SGRENDER procedure.

 proc template;
     define statgraph dendrogram;
     begingraph;
     layout overlay;
     dendrogram nodeID=_CHILD_ parentID=_PARENT_ clusterheight=_HEIGHT_;
     endlayout;
     endgraph;
 end;

 proc sgrender data=outtree template=dendrogram;
 run;

Figure 3 shows the dendrogram.

Figure 3: Hierarchical Clustering

 Hierarchical Clustering


Last updated: November 11, 2020