/************************************************* * This program creates two interlocking semi- * * circles in 3D when r is 0. For r>0, trivariate * * normal noise with standard deviation r is added * * to these arcs. Spread controls how close * * together these arcs are. * *************************************************/ %let r=0.06 ; ** r<.1 is good ; %let spread= -.3; %let npts = 200; ** Pick sample size in each arc; data macaroni; do i = 1 to &npts; * First semicircle ; angle = i*3.14159/&npts; Y1 = sin(angle) + &r*normal(123) + &spread; Y2 = cos(angle) + &r*normal(123); Y3 = &r*normal(123); cval="green"; output; * Second semicircle; Y1 = 1-sin(angle) + &r*normal(123) - &spread ; Y2 = &r*normal(123); Y3 = cos(angle) + &r*normal(123); cval="red"; output; end; proc g3d; scatter y1*y2=Y3/shape="balloon" color=cval noneedle; Title h=1.5 "Spread = &spread std. dev. = &r "; run; *** Cluster in SAS/STAT ***; proc cluster method=single ccc outtree=tree data=macaroni noprint; var y1 y2 y3; proc print data=tree(obs=10); run; proc tree data=tree height=ncl spaces=1 inc=1 out=outclus ncl=2; copy y1 y2 y3; *** Graph, colored by cluster ***; data outclus; set outclus; length cval $8; if cluster = 1 then cval="red"; if cluster = 2 then cval= "green"; if cluster = 3 then cval = "blue"; if cluster = 4 then cval="gray"; if cluster = 5 then cval="black"; if cluster > 5 then cval="gray"; proc g3d; scatter Y1*Y2=Y3/color=cval shape = "balloon" noneedle size=0.8; run; quit;