build.clusters: Apply cluster analysis to build variable groups

View source: R/build_clusters.R

build.clustersR Documentation

Apply cluster analysis to build variable groups

Description

This function generates variables groups of relation information that was obtained by var.relations function applying getLinkCommunities.

Usage

build.clusters(rel, hcmethod = "ward.D")

Arguments

rel

a list containing variables, surr.res, threshold, and var. This is the output of var.relations function.

hcmethod

the hierarchical clustering method that is used. (see getLinkCommunities)

Value

a data frame containing the variable names and their associated clusters.

Examples

# read data
data("SMD_example_data")


 # get trees and variable names
 x = SMD_example_data[,2:ncol(SMD_example_data)]
 y = SMD_example_data[,1]
 allvariables = colnames(x)# extract variables names
 nvar = length(allvariables)   # count number of variables
 set.seed(42)
 RF = ranger::ranger(data = SMD_example_data, dependent.variable.name = "y", num.trees = 10, keep.inbag = TRUE,mtry = floor(nvar^(3/4)), min.node.size = 1)
 trees = getTreeranger(RF = RF, ntree = 10)
 trees.lay = addLayer(trees)
 trees.surr = addSurrogates(RF = RF, trees = trees.lay, s = 10, Xdata = x, num.threads = NULL)

 # investigate variable relations
 rel=var.relations(forest = list(trees = trees.surr, allvariables = allvariables), variables = allvariables, candidates = allvariables, t = 10)
 groups = build.clusters(rel)



StephanSeifert/SurrogateMinimalDepth documentation built on Aug. 7, 2023, 1:59 a.m.