minIncBlocks {nem}R Documentation

Minimal number of inconsistent blocks

Description

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.

Usage

minIncBlocks(res, compIM, mustBeConnected = FALSE)

Arguments

res

the object returned by the function optRandPar in package blockmodeling

compIM

the image matrix to be compared with, i.e., the ideal image matrix, in matrix form

mustBeConnected

wheter only one component must be present in the blockmodel or not

Details

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.

Value

It return the list:

error

the number of inconsistent blocks

order

the order of clusters

Author(s)

Marjan Cugmas

Examples

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)]]))
  }
}


[Package nem version 0.12.33 Index]