This function uses a set of classification or regression trees to build an inter-point dissimilarity in which two points are similar when they tend to fall in the same leaves of trees. The user can pass in a clustering algorithm and/or ask for the dissimilarities or the set of trees.
treeClust(dfx, d.num = 1, col.range = 1:ncol(dfx), verbose = F,
final.algorithm, k, control = treeClust.control(), rcontrol = rpart.control(), ...)
Input data frame. Columns may be numeric or categorical. Missing values are permitted.
Integer: Dissimilarity specifier. When d.num = 1, the dissimilarity between two observations is the proportion of trees where they disagree. With d.num = 2, those counts are weighted according to tree quality. In d.num = 3, dissimilarities are variable with trees, reflecting the belief that some pairs of leaves are closer together than others. With d.num = 4, those dissimilarities are weighted by tree quality.
Integer: the indices of the columns used. Defaults to all.
If non-zero, print degugging messages to the screen.
Final algorithm, to be used to cluster the computed distances. This may be "pam", "agnes", "clara" or "kmeans".
If final.algorithm is supplied, the number of clusters is required.
List of the sort produced by treeClust.control
, giving
specifications for the fitting routine.
List of the sort produced by rpart.control
, giving
arguments for the rpart routine.
Other arguments, to be passed to the final clustering algorithm if specified.
If control$cluster.only is TRUE, a vector of cluster assignments, as produced by the final algorthm. Otherwise, a list with these items:
The call that produced the object
d.num, as supplied
Two-column matrix with one row for each tree retained, giving size and deviance ratio
Two-column matrix like tbl, but with one row for every variable, giving size and deviance ratio (these will be 1 and 0 for variables whose trees were discarded
final.algorithm, as supplied
If final.algorithm is supplied, the output from the final clustering algorithm; otherwise, NULL
Any additional arguments specified
If control$return.trees is TRUE, a list holding all the retained trees. This can make the resulting object very large.
If control$return.dists is TRUE, an object of class dist with the set of pairwise inter-point dissimilarities
If control$return.mat is TRUE, a data frame. If final.algorithm is "pam" or "agnes" this contains leaf assignment indices. Otherwise this holds a dataset useful as input to k-means or clara. Experimental.
The treeClust approach builds a set of classification or regresion trees, one for each variable. Trees are pruned, and those that are pruned to the root are discarded. For each remaining tree, an observation's leaf membership serves as the starting point for a dissimilarity measurement.
Buttrey and Whitaker, "treeClust: An R Package for Tree-Based Clustering Dissimilarities," The R Journal, 7/2, 2015.
# NOT RUN {
iris.km6 <- treeClust (iris[,-5], d.num = 2, final.algorithm = "kmeans", k=6)
table (iris.km6$final.clust$cluster, iris$Species)
# }
Run the code above in your browser using DataLab