value2 = as.integer() HierarchicalClustering <- function(couplingdata, tcluster, met="complete") { d <- dist(as.matrix(couplingdata)) dendrogram <- hclust(d, method = met) plot(dendrogram, check = TRUE, labels = colnames(couplingdata)) rect.hclust(dendrogram,k = tcluster, border = 2) # making clusters variable as global clusters <<- cutree(dendrogram, k= tcluster) clusters } Precision <- function(observed, gold1) { library(clusterCrit) print(observed) print(gold1) ext <- extCriteria(observed, gold1,"all") return(ext) } Recall <- function(observed, gold1) { library(clusterCrit) value2 <- as.numeric(extCriteria(observed, gold1,"Recall")) return(value2) } # initialization of variables totalClusters = 4 method = "ward.D2" goldStandard = as.integer(JUnitGoldStandard) # performing hierarchical clustering HierarchicalClustering(ClassCouplingData, totalClusters, method) # generating all possible permutations val <- vector() library(combinat) for(i in 1: totalClusters) val <- c(val, i) permutation <- permn(val) # evaluating clustering obtained for(i in 1: length(permutation)) { str2 = "" library(car) print(permutation[i]) gold1 <- as.integer(recode(goldStandard,"1=permutation[[i]][1];2=permutation[[i]][2];3=permutation[[i]][3]; 4=permutation[[i]][4]"),as.numeric.result=FALSE) precision = 0 ext <- Precision(clusters, gold1) recall = Recall(clusters, gold1) cat("Iteration = ", i, " Precision = ", ext$precision," Recall= ",recall, "\n") }