stochBlockORP {StochBlock} | R Documentation |
A function for optimizing multiple random partitions using stochastic one-mode and linked blockmodeling. Similar to optRandomParC, but calling stochBlock for optimizing individual partitions.
Description
A function for optimizing multiple random partitions using stochastic one-mode and linked blockmodeling. Similar to optRandomParC, but calling stochBlock for optimizing individual partitions.
Usage
stochBlockORP(
M,
k,
rep,
save.initial.param = TRUE,
deleteMs = TRUE,
max.iden = 10,
return.all = FALSE,
return.err = TRUE,
seed = NULL,
parGenFun = blockmodeling::genRandomPar,
mingr = NULL,
maxgr = NULL,
addParam = list(genPajekPar = TRUE, probGenMech = NULL),
maxTriesToFindNewPar = rep * 10,
skip.par = NULL,
printRep = ifelse(rep <= 10, 1, round(rep/10)),
n = NULL,
nCores = 1,
useParLapply = FALSE,
cl = NULL,
stopcl = is.null(cl),
...
)
Arguments
M |
A square matrix giving the adjaciency relationg between the network's nodes (aka vertexes) |
k |
The number of clusters used in the generation of partitions. |
rep |
The number of repetitions/different starting partitions to check. |
save.initial.param |
Should the inital parameters( |
deleteMs |
Delete networks/matrices from the results of to save space. Defaults to |
max.iden |
Maximum number of results that should be saved (in case there are more than |
return.all |
If |
return.err |
Should the error for each optimized partition be returned. Defaults to |
seed |
Optional. The seed for random generation of partitions. |
parGenFun |
The function (object) that will generate random partitions. The default function is |
mingr |
Minimal allowed group size. |
maxgr |
Maximal allowed group size. |
addParam |
A list of additional parameters for function specified above. In the usage section they are specified for the default function |
maxTriesToFindNewPar |
The maximum number of partition try when trying to find a new partition to optimize that was not yet checked before - the default value is |
skip.par |
The partitions that are not allowed or were already checked and should therefore be skipped. |
printRep |
Should some information about each optimization be printed. |
n |
The number of units by "modes". It is used only for generating random partitions. It has to be set only if there are more than two modes or if there are two modes, but the matrix representing the network is one mode (both modes are in rows and columns). |
nCores |
Number of cores to be used. Value |
useParLapply |
Should |
cl |
The cluster to use (if formed beforehand). Defaults to |
stopcl |
Should the cluster be stopped after the function finishes. Defaults to |
... |
Arguments passed to other functions, see |
Value
A list of class "opt.more.par" containing:
M |
The one- or multi-mode matrix of the network analyzed |
res |
If |
best |
A list of results from |
err |
If |
ICL |
Integrated classification likelihood for the best partition. |
checked.par |
If selected - A list of checked partitions. If |
call |
The call to this function. |
initial.param |
If selected - The initial parameters are used. |
Random.seed |
.Random.seed at the end of the function. |
cl |
Cluster used for parallel computations if supplied as an input parameter. |
Warning
It should be noted that the time needed to optimise the partition depends on the number of units (aka nodes) in the networks as well as the number of clusters due to the underlying algorithm. Hence, partitioning networks with 100 units and large number of blocks (e.g., >5) can take a long time (from 20 minutes to a few hours or even days).
Author(s)
Aleš, Žiberna
References
Škulj, D., & Žiberna, A. (2022). Stochastic blockmodeling of linked networks. Social Networks, 70, 240-252.
Examples
# Simple one-mode network
library(blockmodeling)
k<-2
blockSizes<-rep(20,k)
IM<-matrix(c(0.8,.4,0.2,0.8), nrow=2)
if(any(dim(IM)!=c(k,k))) stop("invalid dimensions")
set.seed(2021)
clu<-rep(1:k, times=blockSizes)
n<-length(clu)
M<-matrix(rbinom(n*n,1,IM[clu,clu]),ncol=n, nrow=n)
diag(M)<-0
plotMat(M)
resORP<-stochBlockORP(M,k=2, rep=10, return.all = TRUE)
resORP$ICL
plot(resORP)
clu(resORP)
# Linked network
library(blockmodeling)
set.seed(2021)
IM<-matrix(c(0.8,.4,0.2,0.8), nrow=2)
clu<-rep(1:2, each=20)
n<-length(clu)
nClu<-length(unique(clu))
M1<-matrix(rbinom(n^2,1,IM[clu,clu]),ncol=n, nrow=n)
M2<-matrix(rbinom(n^2,1,IM[clu,clu]),ncol=n, nrow=n)
M12<-diag(n)
nn<-c(n,n)
k<-c(2,2)
Ml<-matrix(0, nrow=sum(nn),ncol=sum(nn))
Ml[1:n,1:n]<-M1
Ml[n+1:n,n+1:n]<-M2
Ml[n+1:n, 1:n]<-M12
plotMat(Ml)
resMl<-stochBlockORP(M=Ml, k=k, n=nn, rep=10)
resMl$ICL
plot(resMl)
clu(resMl)