Library: | xclust |
See also: | adap |
Quantlet: | adaptive | |
Description: | performs an adaptive K-means cluster analysis with appropriate (adaptive) multivariate graphic using the principal components |
Usage: | ca = adaptive(x, k, w, m, t) | |
Input: | ||
x | n x p matrix of n row points to be clustered | |
k | scalar the number of clusters | |
w | p x 1 matrix of weights of column points | |
m | n x 1 matrix of weights (masses) of row points | |
t | n x 1 matrix of the true partition (only if known, else a matrix containing 1) | |
Output: | ||
ca.b | n x 1 matrix partition of n points into k clusters | |
ca.c | k x p matrix of means (centroids) of clusters | |
ca.v | k x p matrix of within cluster variances divided by the corresponding weights (masses) of clusters | |
ca.s | k x 1 matrix of weights (masses) of clusters | |
ca.a | p x 1 matrix of adaptive weights of variables |
; load the library xclust library("xclust") ; initialize random generator randomize(0) ; generate some normal data x = normal(200, 5) x1 = x - #(2,1,3,0,0)' x2 = x + #(1,1,3,1,0.5)' x3 = x + #(0,0,1,5,1)' ; make one data set x = x1|x2|x3 ; compute column variances w = 1./var(x) ; generate row weights(here : 1) m = matrix(rows(x)) ; generate true partition t = matrix(200)|matrix(200).+1|matrix(200).+2 ; apply adaptive clustering ca = adaptive(x, 3, w, m, t)
gives a partition ca.b of n row points into 3 clusters which minimizes the sum of within cluster variances according to the column weights (1/pooled within cluster variances)