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 mylib.getStarted;
array x{20} x1-x20;
call streaminit(12345);
do i = 1 to 100;
x1=rand('NORMAL'); x2=0.9*x1+0.2; x3=0.7*x1+0.6; x4=x3*x2*x1; x5=x1*x1*x1;
x6=rand('NORMAL'); 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} = rand('UNIFORM');
end;
output;
end;
run;
These statements assume that your CAS engine libref is named mylib, but you can substitute any appropriately defined CAS engine libref.
The following statements execute the GVARCLUS algorithm on the mylib.getStarted data table:
proc gvarclus data=mylib.getStarted mincluster=2 maxsteps=8
rho=0.8 outtree=mylib.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 that are used in each step sequentially. The OUTTREE= option creates the
mylib.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
| Number of Observations Read | 100 |
|---|---|
| Number of Observations Used | 100 |
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 | ||||||||
|---|---|---|---|---|---|---|---|---|
| Parameter | Step 1 | Step 2 | Step 3 | Step 4 | Step 5 | Step 6 | Step 7 | Step 8 |
| x1 | 1 | 19 | 35 | 51 | 66 | 81 | 96 | 109 |
| x2 | 2 | 19 | 35 | 51 | 66 | 81 | 96 | 109 |
| x3 | 3 | 19 | 35 | 51 | 66 | 81 | 96 | 109 |
| x4 | 4 | 20 | 36 | 52 | 67 | 82 | 96 | 109 |
| x5 | 5 | 21 | 37 | 53 | 68 | 83 | 97 | 109 |
| x6 | 6 | 22 | 38 | 54 | 69 | 84 | 98 | 110 |
| x7 | 6 | 22 | 38 | 54 | 69 | 84 | 98 | 110 |
| x8 | 6 | 22 | 38 | 54 | 69 | 84 | 98 | 110 |
| x9 | 7 | 23 | 39 | 55 | 70 | 85 | 98 | 110 |
| x10 | 8 | 24 | 40 | 54 | 69 | 84 | 98 | 110 |
| x11 | 9 | 25 | 41 | 56 | 71 | 86 | 99 | 111 |
| x12 | 10 | 26 | 42 | 57 | 72 | 87 | 100 | 112 |
| x13 | 11 | 27 | 43 | 58 | 73 | 88 | 101 | 113 |
| x14 | 12 | 28 | 44 | 59 | 74 | 89 | 102 | 114 |
| x15 | 13 | 29 | 45 | 60 | 75 | 90 | 103 | 115 |
| x16 | 14 | 30 | 46 | 61 | 76 | 91 | 104 | 116 |
| x17 | 15 | 31 | 47 | 62 | 77 | 92 | 105 | 117 |
| x18 | 16 | 32 | 48 | 63 | 78 | 93 | 106 | 118 |
| x19 | 17 | 33 | 49 | 64 | 79 | 94 | 107 | 119 |
| x20 | 18 | 34 | 50 | 65 | 80 | 95 | 108 | 120 |
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 mylib.dendrogram into the Work library:
data outtree;
set mylib.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
