colors2data | R Documentation |
Assigns colors to data points according to cluster membership, when the clusters are defined as high density regions
colors2data(dendat, pcf, lst, paletti = NULL, clusterlevel = NULL, nodes = NULL, type = "regular")
dendat |
n*d matrix of real numbers; the data matrix. |
pcf |
piecewise constant function; output of "pcf.kern", or "pcf.func", for example. |
lst |
level set tree; a list of vectors. The list contains at least vectors "level", "volume", and "parent". For example, function "leafsfirst" computes a level set tree. |
paletti |
a vector of names of colors; for example paletti=c("black","red","blue"). |
clusterlevel |
a positive real number; gives the level which is such that the disconnected components of the level set with this level define the clusters. |
nodes |
a vector of positive integers; contains pointers to the nodes of level set tree "lst"; the nodes indicate which disconnected components of level sets define the clusters. |
type |
either "regular" or "adaptive"; if type="regular", then the piecewise constant function has a regular partition; if type="adaptive", then the piecewise constant function has an adaptive partition. |
a list with components "datacolo" and "ord". "datacolo" is a vector of color names. This vector assigns a color to each row of matrix "dendat". "ord" is a vector of positive integers. This vector contains pointers to rows of the matrix "dendat". The pointers indicate the order so that the data points with the lowest estimated density are first.
Jussi Klemela
pcf.kern
leafsfirst
# generate data seed<-1 n<-50 d<-2 l<-3; D<-4; c<-D/sqrt(2) M<-matrix(0,l,d); M[2,]<-c; M[3,]<--c sig<-matrix(1,l,d) p<-rep(1/l,l) dendat<-sim.data(type="mixt",n=n,M=M,sig=sig,p=p,seed=seed) # colored volume function h<-(4/(d+2))^(1/(d+4))*n^(-1/(d+4))*apply(dendat,2,sd) N<-rep(20,d) pcf<-pcf.kern(dendat,h,N) lst<-leafsfirst(pcf) # colored scatter plot cd<-colors2data(dendat,pcf,lst) plot(dendat,col=cd$datacolo) # colored scatter plot: plot the observations so that the observations with # the highest density value are plotted last cd<-colors2data(dendat,pcf,lst) plot(dendat[cd$ord,1],dendat[cd$ord,2],col=cd$datacolo[cd$ord])