minIncBlocks {nem} | R Documentation |
Calculate the number of inconsistent blocks between the empirical and ideal blockmodel and also provide the order of groups which is the closest to the ideal one.
minIncBlocks(res, compIM, mustBeConnected = FALSE)
res |
the object returned by the function |
compIM |
the image matrix to be compared with, i.e., the ideal image matrix, in |
mustBeConnected |
wheter only one component must be present in the blockmodel or not |
It compare all possile permutations of rows and columns orders of the empirical and ideal image matrices. For each comparison it calculats the minimal number of inconsistent blocks. It returns the minimal number of inconsistent blocks.
Three possible block types can be specified in compIM
: com, nul, any.
When mustBeConnected
is set to TRUE
, the function returns the value of error
which is equal to the number of blocks that are not of type any
.
It return the list:
error |
the number of inconsistent blocks |
order |
the order of clusters |
Marjan Cugmas
minIncBlocks <- function(res, compIM, mustBeConnected = FALSE){ IM <- IM(res)[,,] k <- nrow(IM) all.perms <- permn(1:k) diags <- sapply(1:length(all.perms), function(x) {sum((IM[all.perms[[x]], all.perms[[x]]] != compIM) * ifelse(compIM=="any", yes = 0, no = 1))}) if (mustBeConnected == TRUE) { n.comp <- components(graph_from_adjacency_matrix(ifelse(IM=="com", yes = 1, no = 0)))$no if (n.comp > 1) return(list("error" = sum(compIM != "any"), "order" = all.perms[[which.min(diags)]])) if (n.comp == 1) return(list("error" = min(diags), "order" = all.perms[[which.min(diags)]])) } if (mustBeConnected == FALSE) { return(list("error" = min(diags), "order" = all.perms[[which.min(diags)]])) } }