mpadge / spatialcluster

spatially-constrained clustering in R
https://mpadge.github.io/spatialcluster/
30 stars 6 forks source link

scl_redcap assigns same nodes to different clusters #16

Closed mpadge closed 6 years ago

mpadge commented 6 years ago

Nodes are assigned to different clusters, which they should not be. This function should return FALSE:

check_nodes <- function (scl)
{
    cl <- data.frame (node = c (scl$tree$from, scl$tree$to),
                      cl = scl$tree$clnum) %>%
        dplyr::filter (!is.na (cl)) %>%
        dplyr::distinct () %>%
        dplyr::arrange (node)
    any (duplicated (cl$node))
}

Then try some sample data using all three linkages

set.seed (3)
n <- 100
xy <- matrix (runif (2 * n), ncol = 2)
dmat <- matrix (runif (n ^ 2), ncol = n)
scl1 <- scl_redcap (xy, dmat, ncl = 16, linkage = "complete")
scl2 <- scl_redcap (xy, dmat, ncl = 16, linkage = "single")
scl3 <- scl_redcap (xy, dmat, ncl = 16, linkage = "average")
check_nodes (scl1); check_nodes (scl2); check_nodes (scl3)
# [1] TRUE
# [1] TRUE
# [1] TRUE

Nope, should be FALSE, FALSE, FALSE.

mpadge commented 6 years ago

and the problem has to lie in src/cuttree