critFunC {blockmodeling}R Documentation

Functions for Generalized blockmodeling for valued networks

Description

Functions for implementation of Generalized blockmodeling for valued networks where the values of the ties are assumed to be measured on at least interval scale. critFunC calculates the criterion function, based on the network, partition and blockmodel/equivalece. optParC optimizes a partition based on the criterion function based on a local search algorithm.

Usage

critFunC(
  M,
  clu,
  approaches,
  blocks,
  isTwoMode = NULL,
  isSym = NULL,
  diag = 1,
  IM = NULL,
  EM = NULL,
  Earr = NULL,
  justChange = FALSE,
  rowCluChange = c(0, 0),
  colCluChange = c(0, 0),
  sameIM = FALSE,
  regFun = "max",
  homFun = "ss",
  usePreSpecM = NULL,
  preSpecM = NULL,
  save.initial.param = TRUE,
  relWeights = 1,
  posWeights = 1,
  blockTypeWeights = 1,
  combWeights = NULL,
  returnEnv = FALSE,
  mulReg = TRUE,
  addGroupLlErr = TRUE
)

optParC(
  M,
  clu,
  approaches,
  blocks,
  nMode = NULL,
  isSym = NULL,
  diag = 1,
  useMulti = FALSE,
  maxPar = 50,
  IM = NULL,
  EM = NULL,
  Earr = NULL,
  justChange = TRUE,
  sameIM = FALSE,
  regFun = "max",
  homFun = "ss",
  usePreSpecM = NULL,
  preSpecM = NULL,
  minUnitsRowCluster = 1,
  minUnitsColCluster = 1,
  maxUnitsRowCluster = 9999,
  maxUnitsColCluster = 9999,
  relWeights = 1,
  posWeights = 1,
  blockTypeWeights = 1,
  combWeights = NULL,
  exchageClusters = "all",
  fixClusters = NULL,
  save.initial.param = TRUE,
  mulReg = TRUE,
  addGroupLlErr = TRUE
)

Arguments

M

A matrix representing the (usually valued) network. For multi-relational networks, this should be an array with the third dimension representing the relation. The network can have one or more modes (diferent kinds of units with no ties among themselves). If the network is not two-mode, the matrix must be square.

clu

A partition. Each unique value represents one cluster. If the nework is one-mode, than this should be a vector, else a list of vectors, one for each mode. Similarly, if units are comprised of several sets, clu should be the list containing one vector for each set.

approaches

One of the approaches (for each relation in multi-relational netowrks in a vector) described in Žiberna (2007). Possible values are:
"bin" - binary blockmodeling,
"val" - valued blockmodeling,
"hom" - homogeneity blockmodeling,
"ss" - sum of squares homogeneity blockmodeling, and
"ad" - absolute deviations homogeneity blockmodeling.

The last two options are "shorthand" for specifying approaches="hom" and homFun to either "ss" or "ad".

blocks

A vector, a list of vectors or an array with names of allowed blocy types.

Only listing of allowed block types (blockmodel is not pre-specified).
A vector with names of allowed block types. For multi-relational networks, it can be a list of such vectors. For approaches = "bin" or approaches = "val", at least two should be selected. Possible values are:
"nul" - null or empty block
"com" - complete block
"rdo", "cdo" - row and column-dominant blocks (binary and valued approach only)
"reg" - (f-)regular block
"rre", "cre" - row and column-(f-)regular blocks
"rfn", "cfn" - row and column-dominant blocks (binary, valued only)
"den" - density block (binary approach only)
"avg" - average block (valued approach only)
"dnc" - do not care block - the error is always zero
The ordering is important, since if several block types have identical error, the first on the list is selected.

A pre-specified blockmodel.
An array with four dimensions (see example below). The third and the fourth represent the clusters (for rows and columns). The first is as long as the maximum number of allows block types for a given block. If some block has less possible block types, the empty slots should have values NA. The second dimension is the number of relations (1 for single-relational networks). The values in the array should be the ones from above. The array can have only three dimensions in case of one-relational networks or if the same pre-specified blockmodel is assumed for all relations. Further, it can have only two dimensions, if in addition only one block type is allowed per block.

isTwoMode

1 for one-mode networks and 2 for two-mode networks. The default value is set to NULL.

isSym

Specifying if the matrix (for each relation) is symmetric.

diag

Should the special status of diagonal be acknowledged. A single number or a vector equal to the number of relation. The default value is set to 1. Codes:
0 - diagonal is treated in the same way as other values
1 - diagonal is treated separately, or
2 - diagonal values are ignored.

IM

The obtained image for objects. For debugging purposes only.

EM

Block errors by blocks. For debugging purposes only.

Earr

The array of errors for all allowed block types by next dimensions: allowed block types, relations, row clusters and column clusters. The dimensions should match the dimensions of the block argument if specified as an array. For debugging purposes only.

justChange

Value specifying if only the errors for changed clusters should be computed. Used only for debugging purposes by developers.

rowCluChange

An array holding the two row clusters where the change occured. Used only for debugging purposes by developers.

colCluChange

An array holding the col row clusters where the change occured. Used only for debugging purposes by developers.

sameIM

Should we demand the same blockmodel image for all relations. The default value is set to FALSE.

regFun

Function f used in row-f-regular, column-f-regular, and f-regular blocks. Not used in binary approach. For multi-relational networks, it can be a vector of such character strings. The default value is set to "max".

homFun

In case of homogeneity blockmodeling two variability criteria can be used: "ss" - sum of squares (set by default), "ad" - absolute deviations and "bll" - - (minus) binary log-likelihood.

usePreSpecM

Specifying weather a pre-specified value should be used when computing inconsistency.

preSpecM

Sufficient value for individual cells for valued approach. Can be a number or a character string giving the name of a function. Set to "max" for implicit approach. For multi-relational networks, it can be a vector of such values. In case ob binary blockmodeling this argument is a threshold used for binerizing the network. Therefore all values with values lower than preSpecM are recoded into 0s, all other into 1s. For multi-relational networks, it can be a vector of such values. In case of pre-specified blockmodeling, it can have the same dimensions as blocks.

save.initial.param

Should the inital parameters (approaches, ...) be saved. The default value is TRUE.

relWeights

Weights for all type of relations in a blockmodel. The default value is set to 1.

posWeights

Weigths for positions in the blockmodel (the dimensions must be the same as the error matrix (rows, columns)). For now this is a matix (two-dimensional) even for multi-relational networks.

blockTypeWeights

Weights for each type of block used, if they are to be different across block types (see blocks above). It must be suplied in form of a named vector, where the names are one or all allowed block types from blocks. If only some block types are specified, the other have a default weight of 1. The default value is set to 1.

combWeights

Weights for all type of block used, The default value is set to NULL.The dimension must be the same as blocks, if blocks would be specified in array format (which is usual in pre-specified case).

returnEnv

Should the function also return the environment after its completion.

mulReg

Should the errors that apply to rows/columns (and not to cells) should be multiplied by number of rows/columns. Defaults to TRUE.

addGroupLlErr

Used only when stochastic generalized blockmodeling is used. Should the total error included the part based on sizes of groups. Defaults to TRUE. Will return wrong results for two-mode networks if critFunC is called directly (should be fine if called via optParC function).

nMode

Number of nodes. If NULL, then determined from clu.

useMulti

Which version of local search should be used. The default value is set to FALSE. If FALSE, first possible all moves in random order and then all possible exchanges in random order are tired. When a move with lower value of criterion function is found, the algorithm moves to this new partition. If TRUE the version of local search where all possible moves and exchanges are tired first and then the one with the lowest error is selected and used. In this case, several optimal partitions are found. maxPar best partitions are returned.

maxPar

The number of partitions with optimal criterion fuction to be returned. Only used If useMulti is TRUE.

minUnitsRowCluster

Minimum number of units in row cluster.

minUnitsColCluster

Minimum number of units in col cluster.

maxUnitsRowCluster

Maximum number of units in row cluster.

maxUnitsColCluster

Maximum number of units in col cluster.

exchageClusters

A matrix of dimensions "number of clusters" x "number of clusters" indicating to which clusters can units from a specific cluster be moved. Useful for multilevel blockmodeling or/in some other cases where some units cannot mix.

fixClusters

Clusters to be fixed. Used only if exchageClusters = "all". A vector of integers that specify clusters to be fixed, where clusters are numbered from 1 to the total (in all modes or sets) number of clusters.

Value

critFunC returns a list containing:

M

The matrix of the network analyzed.

err

The error or inconsistency emplirical network with the ideal network for a given blockmodel (model, approach,...) and paritition.

clu

The analyzed partition.

EM

Block errors by blocks.

IM

The obtained image for objects.

BM

Block means by block - only for Homogeneity blockmodeling.

Earr

The array of errors for all allowed block types by next dimensions: allowed block types, relations, row clusters and column clusters. The dimensions should match the dimensions of the block argument if specified as an array.


optParC returns a list containing:

M

The matrix of the network analyzed.

err

The error or inconsistency emplirical network with the ideal network for a given blockmodel (model, approach,...) and paritition.

clu

The analyzed partition.

EM

Block errors by blocks.

IM

The obtained image for objects.

BM

Block means by block - only for Homogeneity blockmodeling.

Earr

The array of errors for all allowed block types by next dimensions: allowed block types, relations, row clusters and column clusters. The dimensions should match the dimensions of the block argument if specified as an array.

useMulti

The value of the input paramter useMulti.

bestRowParMatrix

(If useMulti = TRUE) Matrix, where there are different solutions for columns, where rows represent units.

sameErr

The number of partitions with the minimum value of the criterion function.

Author(s)

Aleš, Žiberna

References

Doreian, P., Batagelj, V., & Ferligoj, A. (2005). Generalized blockmodeling, (Structural analysis in the social sciences, 25). Cambridge [etc.]: Cambridge University Press.

Žiberna, A. (2007). Generalized Blockmodeling of Valued Networks. Social Networks, 29(1), 105-126. doi: 10.1016/j.socnet.2006.04.002

Žiberna, A. (2008). Direct and indirect approaches to blockmodeling of valued networks in terms of regular equivalence. Journal of Mathematical Sociology, 32(1), 57-84. doi: 10.1080/00222500701790207

Žiberna, A. (2014). Blockmodeling of multilevel networks. Social Networks, 39(1), 46-61. doi: 10.1016/j.socnet.2014.04.002

See Also

optRandomParC, IM, clu, err, plot.critFun

Examples

# Generating a simple network corresponding to the simple Sum of squares
# Structural equivalence with blockmodel:
# nul com
# nul nul
n <- 20
net <- matrix(NA, ncol = n, nrow = n)
clu <- rep(1:2, times = c(5, 15))
tclu <- table(clu)
net[clu == 1, clu == 1] <- rnorm(n = tclu[1] * tclu[1], mean = 0, sd = 1)
net[clu == 1, clu == 2] <- rnorm(n = tclu[1] * tclu[2], mean = 4, sd = 1)
net[clu == 2, clu == 1] <- rnorm(n = tclu[2] * tclu[1], mean = 0, sd = 1)
net[clu == 2, clu == 2] <- rnorm(n = tclu[2] * tclu[2], mean = 0, sd = 1)

# Computation of criterion function with the correct partition
res <- critFunC(M = net, clu = clu, approaches = "hom", homFun = "ss", blocks = "com")
res$err # The error is relatively small
plot(res)

# Computation of criterion function with the correct partition and correct pre-specified blockmodel
# Prespecified blockmodel used
# nul com
# nul nul
B <- array(NA, dim = c(1, 1, 2, 2))
B[1, 1, , ] <- "nul"
B[1, 1, 1, 2] <- "com"
B[1, 1, , ]
res <- critFunC(M = net, clu = clu, approaches = "hom", homFun = "ss", blocks = B)
res$err # The error is relatively small
res$IM
plot(res)

# Computation of criterion function with the correct partition
# and pre-specified blockmodel with some alternatives
# Prespecified blockmodel used
# nul nul|com
# nul nul
B <- array(NA, dim = c(2, 2, 2))
B[1, , ] <- "nul"
B[2, 1, 2] <- "com"
res <- critFunC(M = net, clu = clu, approaches = "hom", homFun = "ss", blocks = B)
res$err # The error is relatively small
res$IM
plot(res)

# Computation of criterion function with random partition
set.seed(1)
clu.rnd <- sample(1:2, size = n, replace = TRUE)
res.rnd <- critFunC(M = net, clu = clu.rnd, approaches = "hom",
homFun = "ss", blocks = "com")
res.rnd$err # The error is larger
plot(res.rnd)

# Adapt network for Valued blockmodeling with the same model
net[net > 4] <- 4
net[net < 0] <- 0

# Computation of criterion function with the correct partition
res <- critFunC(M = net, clu = clu, approaches = "val",
blocks = c("nul", "com"), preSpecM = 4)
res$err # The error is relatively small
res$IM
# The image corresponds to the one used for generation of
# The network
plot(res)

# Optimizing one partition
res <- optParC(M = net, clu = clu.rnd,
   approaches = "hom", homFun = "ss", blocks = "com")
plot(res) # Hopefully we get the original partition


[Package blockmodeling version 1.1.5 Index]