Closed mattpaletta closed 6 years ago
I'm not sure what the issue is, did you come across an error using the current diceR:::ivi_table()
?
library(diceR)
library(magrittr)
# Consensus clustering for multiple algorithms
set.seed(911)
data <- matrix(rnorm(500), ncol = 10)
CC <- consensus_cluster(data, nk = 3:4, reps = 10, algorithms = c("ap", "km"),
progress = FALSE)
E <- abind::abind(list(CC), along = 3)
cl.mat <- consensus_combine(E, element = "class") %>%
purrr::map(as.data.frame)
# Internal indices
ii <- cl.mat %>% purrr::map(diceR:::ivi_table, data = data)
ii
#> $`3`
#> Algorithms calinski_harabasz dunn pbm tau gamma
#> 1 KM_Euclidean 6.045309 0.3600191 1.3893937 0.3577857 0.5190154
#> 2 AP 5.696644 0.3457346 0.8813185 0.2159109 0.3268007
#> c_index davies_bouldin mcclain_rao sd_dis ray_turi g_plus
#> 1 0.2266867 2.228815 0.8216877 0.7217225 1.304566 0.1141910
#> 2 0.3184778 2.494521 0.8770018 0.6898195 1.560352 0.1468054
#> silhouette s_dbw Compactness Connectivity
#> 1 0.07426715 NaN 4.004848 52.72937
#> 2 0.09232744 NaN 3.997723 48.54167
#>
#> $`4`
#> Algorithms calinski_harabasz dunn pbm tau gamma
#> 1 KM_Euclidean 6.357976 0.3471004 1.2763344 0.3269021 0.5134915
#> 2 AP 5.037927 0.3240620 0.8629581 0.2023128 0.3197935
#> c_index davies_bouldin mcclain_rao sd_dis ray_turi g_plus
#> 1 0.2274210 1.903901 0.8153465 0.6498983 0.9936387 0.09850874
#> 2 0.3280725 2.082346 0.8817180 0.6522639 1.2652438 0.13600773
#> silhouette s_dbw Compactness Connectivity
#> 1 0.09587392 NaN 3.796956 47.43214
#> 2 0.09311465 NaN 3.869159 56.45198
ivi_table2 <- function(cl.df, data) {
ndata <- apply(data, 2, function(x) as.numeric(as.character(x)))
data.frame(
Algorithms = colnames(cl.df),
cl.df %>% purrr::map_df(
clusterCrit::intCriteria,
traj = ndata,
crit = c("Calinski_Harabasz", "Dunn", "PBM", "Tau", "Gamma", "C_index",
"Davies_Bouldin", "McClain_Rao", "SD_Dis", "Ray_Turi", "G_plus",
"Silhouette", "S_Dbw")) %>% as.data.frame %>% t(.),
Compactness = cl.df %>% purrr::map_dbl(compactness, data = data),
Connectivity = cl.df %>% purrr::map_dbl(
~ clValid::connectivity(Data = ndata, clusters = .))
) %>%
dplyr::mutate_all(dplyr::funs(structure(., names = colnames(cl.df))))
}
# Modified version
ii2 <- cl.mat %>% purrr::map(ivi_table2, data = data)
#> Error in data.frame(Algorithms = colnames(cl.df), cl.df %>% purrr::map_df(clusterCrit::intCriteria, : arguments imply differing number of rows: 2, 13
Created on 2018-05-23 by the reprex package (v0.2.0).
This code fixes the issue (as.dataframe + transpose), change as you see fit in diceR.