Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion R/mlClusteringHierarchical.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mlClusteringHierarchical <- function(jaspResults, dataset, options, ...) {
if (options[["linkage"]] == "wardD") {
linkage <- "ward.D"
} else if (options[["linkage"]] == "wardD2") {
linkage <- "ward.D"
linkage <- "ward.D2"
} else {
linkage <- options[["linkage"]]
}
Expand Down
68 changes: 34 additions & 34 deletions tests/testthat/test-mlclusteringhierarchical.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ options <- initMlOptions("mlClusteringHierarchical")
options$addPredictions <- FALSE
options$predictionsColumn <- ""
options$validationMeasures <- TRUE
options$linkage <- "wardD"
options$linkage <- "wardD2"
options$modelOptimization <- "optimized"
options$predictors <- c("Alcohol", "Malic", "Ash", "Alcalinity", "Magnesium", "Phenols", "Flavanoids", "Nonflavanoids", "Proanthocyanins", "Color", "Hue", "Dilution", "Proline")
options$predictors.types <- rep("scale", length(options$predictors))
Expand All @@ -172,56 +172,56 @@ options$tableClusterMeans <- TRUE
set.seed(1)
results <- jaspTools::runAnalysis("mlClusteringHierarchical", "wine.csv", options)

test_that("Evaluation Metrics table results match", {
test_that("Model Performance Metrics table results match", {
table <- results[["results"]][["clusterEvaluationMetrics"]][["data"]]
jaspTools::expect_equal_tables(table,
list("Maximum diameter", 8.97000459794371, "Minimum separation", 1.65382813821881,
"Pearson's <unicode><unicode>", 0.576069991420004, "Dunn index",
0.184373165048091, "Entropy", 1.6642067641347, "Calinski-Harabasz index",
39.017310096389))
list("Maximum diameter", 8.65188420870295, "Minimum separation", 1.65382813821881,
"Pearson's <unicode>", 0.568236148438596, "Dunn index", 0.191152366158023,
"Entropy", 1.63956317716101, "Calinski-Harabasz index", 39.1289637915435
))
})

test_that("Cluster Information table results match", {
table <- results[["results"]][["clusterInfoTable"]][["data"]]
jaspTools::expect_equal_tables(table,
list(1, 0.242534984865065, 56, 261.487531765994, 2, 0.109109073675993,
9, 117.635245012931, 3, 0.230765129303098, 36, 248.797937801422,
4, 0.202904096764332, 34, 218.759745022484, 5, 0.123616307170801,
23, 133.27612536436, 6, 0.0910704082207109, 20, 98.1869740392464
list(1, 0.268080239675824, 58, 288.590093334574, 2, 0.0399824529712903,
6, 43.0413664531293, 3, 0.241885028860911, 30, 260.390781281077,
4, 0.216632828426341, 36, 233.206625935916, 5, 0.142210541161857,
28, 153.090557501325, 6, 0.0912089089037752, 20, 98.1869740392464
))
})

test_that("Cluster Means table results match", {
table <- results[["results"]][["clusterMeansTable"]][["data"]]
jaspTools::expect_equal_tables(table,
list(-0.781843207924736, 0.92528108110726, 0.259388633050896, 0.215037009410226,
0.752415021725891, 0.953961965305775, 0.444752190789042, 0.431937572019575,
-0.307951562262038, -0.600313943067432, 0.86635481402651, 0.519144294355176,
1.19360329436145, "Cluster 1", 0.800021509606689, -0.195110344255247,
0.806509041705175, -0.553225269607803, 0.686211357071248, 0.70153100492565,
0.925047041258243, 1.90074197012781, -0.552711437686052, -0.291662537479379,
0.604330654214653, 1.05254674333779, 0.00810138286916384, "Cluster 2",
-0.146542572260378, -0.82982447794628, -0.989694853778986, -0.788552397373411,
0.507805196178362, 0.266590155973554, 0.268797435339725, -0.674284826744811,
-0.464440878157909, -0.617532099990733, 0.243488671519124, 0.204205628662902,
-0.777138085789446, "Cluster 3", 0.299192917546764, -0.120317329484489,
0.0287774127101431, 0.178313085214061, -1.190459435479, -1.24951928741746,
-0.834245202930723, -0.134293424521656, 0.816264749488125, 0.861878951732851,
-1.0157378437394, -1.11512524607075, -0.401366333769037, "Cluster 4",
0.712359274776484, -1.16078628111573, 0.144235344247606, -1.03779952171632,
0.0833591124064994, -0.209508778429251, 0.643821364725174, -0.712506031006811,
-0.12321813836773, 0.854994624710662, -0.512525358967146, -0.0904475233946064,
-0.767174266522769, "Cluster 5", 0.765086807112473, 0.530140371524544,
0.477441248000354, 1.95657926535688, -1.40168846358879, -1.1015268520218,
-1.46759041083875, 0.196634357272983, 0.701028886969743, 0.475246926074739,
-0.819863385236042, -0.295092620065656, -0.382313118173636,
"Cluster 6"))
list(-0.814718951000308, 0.896746630031742, 0.188036161313956, 0.225350706617625,
0.747514865472435, 0.962345918273369, 0.453938607686343, 0.381452016581806,
-0.327160651969942, -0.620302837886437, 0.867053370206996, 0.561736591613942,
1.1611068462929, "Cluster 1", 1.59353832340386, 0.116258853404513,
1.93850225204976, -0.375172259495944, 0.988249857530258, 1.16706232279381,
0.929908149450233, 1.10333941218387, -0.335391806622396, -0.0684642069921506,
1.07568881611213, 0.48180924284713, -0.0748153887034146, "Cluster 2",
-0.328868448134948, -0.945954923754754, -1.12213198429158, -0.84160883941751,
0.458665253616639, 0.138555138801212, 0.442825108612933, -0.25496777432356,
-0.51233076482022, -0.692526739034442, 0.173450707350176, 0.402604855023938,
-0.659219851493464, "Cluster 3", 0.277664529455091, -0.177659982628153,
-0.00249147266452801, 0.115491991115137, -1.15888393847886,
-1.22789329816235, -0.793840815429072, -0.0966541933073729,
0.766622615430375, 0.831025064871381, -1.03787763111556, -1.09063080952508,
-0.389987330010673, "Cluster 4", 0.795030837821801, -1.01918778591077,
0.0595613112912381, -1.03072640112871, 0.239581146640469, -0.0264426995133515,
0.454908434690164, -0.76958415684055, -0.187907153438954, 0.633653969769103,
-0.292353113010822, -0.0851843527569232, -0.908317963003814,
"Cluster 5", 0.765086807112473, 0.530140371524552, 0.47744124800035,
1.95657926535688, -1.40168846358878, -1.1015268520218, -1.46759041083875,
0.196634357272983, 0.701028886969743, 0.475246926074739, -0.819863385236042,
-0.295092620065658, -0.382313118173636, "Cluster 6"))
})

test_that("Hierarchical Clustering table results match", {
test_that("Model Summary: Hierarchical Clustering table results match", {
table <- results[["results"]][["clusteringTable"]][["data"]]
jaspTools::expect_equal_tables(table,
list(0.19, 1234.14, 1482.32, 6, 0.53144565014931, 178))
list(0.18, 1232.51, 1480.69, 6, 0.532157149697841, 178))
})

# Median linkage
Expand Down
Loading