Title: | Using Network Evolution Models to Generate Networks with Selected Blockmodel Type |
---|---|
Description: | To study network evolution models and different blockmodeling approaches. Various functions enable generating (temporal) networks with a selected blockmodel type, taking into account selected local network mechanisms. The development of this package is financially supported the Slovenian Research Agency (www.arrs.gov.si) within the research program P5<96>0168 and the research project J5-2557 (Comparison and evaluation of different approaches to blockmodeling dynamic networks by simulations with application to Slovenian co-authorship networks). |
Authors: | Marjan Cugmas [aut, cre], Aleš Žiberna [aut] |
Maintainer: | Marjan Cugmas <[email protected]> |
License: | GPL-2 |
Version: | 1.00.01 |
Built: | 2024-11-22 03:51:04 UTC |
Source: | https://github.com/cran/nemBM |
Calculate the normalized network statistic according to the assortativity mechanism.
assortativity(X, actor)
assortativity(X, actor)
X |
Binary network; of class |
actor |
A unit (actor; row/column number), which have an opportunity to change a link. |
The function returns the value 1 when actor (i.e. ego) and alter do not differ in the number of incoming ties. Otherwise, lower values indicate higher difference in the number of incoming ties between the actor and alter.
A vector with the assortativity mechanism, cacluated between the actor and other units.
Marjan Cugmas and Aleš Žiberna
Cugmas, M., & Žiberna, A. (2022). Approaches to blockmodeling dynamic networks: a Monte Carlo simulation study. Social Networks, in print
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) mutuality(X, actor = 2)
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) mutuality(X, actor = 2)
The actor choose the block (i.e., column in an image matrix) in which he will change a link, based on the difference between the density of his out-degrees by blocks and the ideal block density.
chooseBlockRow(X, actor, partition, M, loops, randomBlock = FALSE)
chooseBlockRow(X, actor, partition, M, loops, randomBlock = FALSE)
X |
Binary network; of class |
actor |
A unit (actor; row/column number), which have an opportunity to change a link. |
partition |
A partition in a vector format. Each unique value (positive integers) represents one cluster. |
M |
Image matrix with block densities. |
loops |
Wheter loops are allowed or not. |
randomBlock |
How to select a block; the one with the highest difference ( |
A vector with two elements: block
(selected block number) and sign
(wheter the selected block is too sparse (-1) or too dense (+1)).
Marjan Cugmas
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) diag(X) <- 0 M <- matrix(c(0.1, 0.4, 0.5, 0.3), nrow = 2) partition <- c(1, 2, 2, 1, 1, 2, 2, 2, 1) chooseBlockRow(X = X, actor = 3, partition = partition, M = M, loops = FALSE, randomBlock = "square")
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) diag(X) <- 0 M <- matrix(c(0.1, 0.4, 0.5, 0.3), nrow = 2) partition <- c(1, 2, 2, 1, 1, 2, 2, 2, 1) chooseBlockRow(X = X, actor = 3, partition = partition, M = M, loops = FALSE, randomBlock = "square")
Generate network with a selected blockmodel and level or errors. See details section.
genNetworkLE(BM = BM, LE = 0.4, size = NULL, symmetric = FALSE)
genNetworkLE(BM = BM, LE = 0.4, size = NULL, symmetric = FALSE)
BM |
An image matrix of a blockmodel; of class |
LE |
Desired level of errors. |
size |
A vector with the values specifying clusters' sizes. The number of elements of this vector must be the same as the number of clusters specified by an image matrix. |
symmetric |
Wheter a symmetric network should be generated. |
The level of errors (LE) is used to simulate the extent of inconsistencies in blockmodels. It is defined on a scale between 0 and 1, where 0 corresponds to an ideal blockmodel, and 1 corresponds to a totally randomised network with the same density as in the ideal blockmodel.
A binary network (of class matrix
) with selected blockmodel type and level of errors.
Marjan Cugmas
Cugmas, M., Žiberna, A., & Ferligoj, A. (2021). The Relative Fit measure for evaluating a blockmodel. Statistical Methods & Applications, 30(5), 1315-1335.
cohesiveBM <- rbind(c("com", "nul"), c("nul", "com")) network <- genNetworkLE(BM = cohesiveBM, LE = 0.5, size = c(5, 3))
cohesiveBM <- rbind(c("com", "nul"), c("nul", "com")) network <- genNetworkLE(BM = cohesiveBM, LE = 0.5, size = c(5, 3))
Based on an image matrix and a partition it calculate the density of a whole network.
globalDensity(M, partition)
globalDensity(M, partition)
M |
Image matrix with block densities. |
partition |
A partition in a vector format. Each unique value (positive integers) represents one cluster. |
Density of a whole network (a single value).
Marjan Cugmas
M <- matrix(c(0.1, 0.4, 0.5, 0.3), nrow = 2) partition <- c(1, 2, 2, 1, 1, 2, 2, 2, 1) globalDensity(M = M, partition = partition)
M <- matrix(c(0.1, 0.4, 0.5, 0.3), nrow = 2) partition <- c(1, 2, 2, 1, 1, 2, 2, 2, 1) globalDensity(M = M, partition = partition)
Calculate the normalized network statistic according to the mutuality mechanism.
mutuality(X, actor)
mutuality(X, actor)
X |
Binary network; of class |
actor |
A unit (actor; row/column number), which have an opportunity to change a link. |
A vector with the normalized mutuality mechanism, cacluated between the actor and other units.
Marjan Cugmas and Aleš Žiberna
Cugmas, M., Žiberna, A., & Ferligoj, A. (2019). Mechanisms generating asymmetric core-cohesive blockmodels. Advances in Methodology and Statistics, 16(1), 17-41.
Cugmas, M., & Žiberna, A. (2022). Approaches to blockmodeling dynamic networks: a Monte Carlo simulation study. Social Networks, in print.
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) mutuality(X, actor = 2)
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) mutuality(X, actor = 2)
It generates random network considering the selected local network mechanisms.
nem(X, formula, theta, k = 5000, q, b = 0.25)
nem(X, formula, theta, k = 5000, q, b = 0.25)
X |
Initial network; of class |
formula |
The list of local netork mechanisms to be considered. |
theta |
A vector with the mechanisms' weights/strengths. |
k |
The number of iterations. |
q |
The probability of establishing a link. |
b |
The share of alters among which an actor (i.e., ego) chooses to create or break a tie. |
The list with the following elements:
initialNetwork
- Initial network; of class matrix
.
finalNetwork
- Final (generated) network; of class matrix
.
formula
- The list of functions that define mechanisms used.
theta
- A vector with the mechanisms' weights/strengths used.
k
- The number of iterations.
q
- The probability of establishing a link.
b
- The share of alters among which an actor (i.e., ego) chooses to create or break a tie.
Marjan Cugmas and Aleš Žiberna
Cugmas, M., Žiberna, A., & Ferligoj, A. (2019). Mechanisms generating asymmetric core-cohesive blockmodels. Advances in Methodology and Statistics, 16(1), 17-41.
formula <- list(mutuality, popularity, assortativity) X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) nem(X = X, formula = formula, theta = c(1, 1, 1), k = 100, q = 0.25)
formula <- list(mutuality, popularity, assortativity) X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) nem(X = X, formula = formula, theta = c(1, 1, 1), k = 100, q = 0.25)
Generates an asymmetric network with a selected blockmodel type and partition. Considers local network mechanisms when creating links within blocks. Does not enable considering incomers and outgoers.
nemBM(X = X, partition, M, formula, theta, k = 10000, loops = FALSE)
nemBM(X = X, partition, M, formula, theta, k = 10000, loops = FALSE)
X |
Initial binary network; of class |
partition |
A desired partition in a vector format. Each unique value (positive integers) represents one cluster. |
M |
Desired image matrix with block densities. |
formula |
The list of local netork mechanisms to be considered. |
theta |
A vector with the mechanisms' weights/strengths. |
k |
The number of iterations. |
loops |
Wheter loops are allowed or not (default |
The list with the following elements:
initialNetwork
- Initial network; of class matrix
.
finalNetwork
- Final (generated) network; of class matrix
.
formula
- The list of functions that define mechanisms used.
theta
- A vector with the mechanisms' weights/strengths used.
ERR
- Sum of squared differences between the desired and empirical densities across blocks; for each iteration.
iterations
- The number of iterations.
loops
- Wheter loops were allowed.
M
- The desired (specified) image matrix.
partition
- The partition.
density
- Network density at each iteration.
timeElapsed
- Running time.
Marjan Cugmas and Aleš Žiberna
Cugmas, M., & Žiberna, A. (2022). Approaches to blockmodeling dynamic networks: a Monte Carlo simulation study. Social Networks, in print.
formula <- list(mutuality, popularity, OTPtransitivity) X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) diag(X) <- 0 M <- matrix(c(0.1, 0.8, 0.1, 0.5), nrow = 2) partition <- c(1, 2, 2, 1, 1, 2, 2, 2, 1) res <- nemBM(X = X, partition = partition, formula = formula, theta = c(1, 1, 1), M = M, k = 100, loops = FALSE)
formula <- list(mutuality, popularity, OTPtransitivity) X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) diag(X) <- 0 M <- matrix(c(0.1, 0.8, 0.1, 0.5), nrow = 2) partition <- c(1, 2, 2, 1, 1, 2, 2, 2, 1) res <- nemBM(X = X, partition = partition, formula = formula, theta = c(1, 1, 1), M = M, k = 100, loops = FALSE)
It generates random network considering the selected local network mechanisms.
nemSym(X, formula, theta, k = 5000, q)
nemSym(X, formula, theta, k = 5000, q)
X |
Initial network; of class |
formula |
The list of local netork mechanisms to be considered. |
theta |
A vector with the mechanisms' weights/strengths. |
k |
The number of iterations. |
q |
The probability of establishing a link (i.e. expected/desired density). |
The list with the following elements:
initialNetwork
- Initial network; of class matrix
.
finalNetwork
- Final (generated) network; of class matrix
.
formula
- The list of functions that define mechanisms used.
theta
- A vector with the mechanisms' weights/strengths used.
k
- The number of iterations.
q
- The probability of establishing a link.
Marjan Cugmas and Aleš Žiberna
Cugmas, M., DeLay, D., Žiberna, A., & Ferligoj, A. (2020). Symmetric core-cohesive blockmodel in preschool children’s interaction networks. PloS one, 15(1), e0226801.
formula <- list(popularity, assortativity) X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) diag(X) <- 0 nemSym(X = X, formula = formula, theta = c(1, 1), k = 100, q = 0.25)
formula <- list(popularity, assortativity) X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) diag(X) <- 0 nemSym(X = X, formula = formula, theta = c(1, 1), k = 100, q = 0.25)
Generate a symmetric network with a selected blockmodel type and partition with a specified number of incomers and outgoers. Considers local network mechanisms when creating links within blocks.
nemSymBMinout( X = X, partition = partition, M = M, formula = NULL, theta = NULL, nin = 5, nout = 20, minClusterSize = 5, k = 1000, loops = FALSE, randomizeP = 0, randomSD = 0.02 )
nemSymBMinout( X = X, partition = partition, M = M, formula = NULL, theta = NULL, nin = 5, nout = 20, minClusterSize = 5, k = 1000, loops = FALSE, randomizeP = 0, randomSD = 0.02 )
X |
Initial binary network; of class |
partition |
A desired partition in a vector format. Each unique value (positive integers) represents one cluster. |
M |
Desired image matrix with block densities. |
formula |
The list of local netork mechanisms to be considered. |
theta |
A vector with the mechanisms' weights/strengths. |
nin |
Number of incomers. |
nout |
Number of outgoers. |
minClusterSize |
Minimum cluster size. |
k |
Number of iterations. |
loops |
Wheter loops are allowed or not (default |
randomizeP |
The share of units to be randomly relocated between clusters. |
randomSD |
The srandard deviation of a normal distribution form which the random part of weighed network statistics is sampled. |
The list with the following elements:
initialNetwork
- Initial network; of class matrix
.
finalNetwork
- Final (generated) network; of class matrix
.
initialPartition
- Initial partition.
finalPartition
- Final partition (i.e., partition after randomization and after incomers and outgoers).
M
- The desired (specified) image matrix.
k
- The number of iterations.
combinedPartitions
- Data frame with initial and final partition.
whenIncomers
- A vector of which elements tells us at which iterations the incomers were added.
whenOutgoers
- A vector of which elements tells us at which iterations the outgoers were removed.
ERR
- Sum of squared differences between the desired and empirical densities across blocks; for each iteration.
linkERR
- The difference in the number of links between the generated number of links and desired number of links; for each iteration.
Marjan Cugmas and Aleš Žiberna
formula <- list(mutuality, popularity, OTPtransitivity) X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) diag(X) <- 0 M <- matrix(c(0.1, 0.8, 0.8, 0.1), nrow = 2) partition <- c(1, 2, 2, 1, 1, 2, 2, 2, 1) nemSymBMinout(X = X, partition = partition, formula = formula, theta = c(1, 1, 1), M = M, k = 100, minClusterSize = 2, nin = 10, nout = 5, loops = FALSE)
formula <- list(mutuality, popularity, OTPtransitivity) X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) diag(X) <- 0 M <- matrix(c(0.1, 0.8, 0.8, 0.1), nrow = 2) partition <- c(1, 2, 2, 1, 1, 2, 2, 2, 1) nemSymBMinout(X = X, partition = partition, formula = formula, theta = c(1, 1, 1), M = M, k = 100, minClusterSize = 2, nin = 10, nout = 5, loops = FALSE)
Normalizes values of a vector such that the sum of squared elements equal to .
normalizeRsphere(x, r = 1)
normalizeRsphere(x, r = 1)
x |
A vector or a matrix with values to be normalized. |
r |
The diameter of a sphere, default 1. |
It returns a data frame with normalized values.
Marjan Cugmas
normalizeRsphere(x = c(1, 0.5, 0.4))
normalizeRsphere(x = c(1, 0.5, 0.4))
Calculates the network statistic according to the outgoing shared partners mechanism.
OSPtransitivity(X, actor)
OSPtransitivity(X, actor)
X |
Binary network; of class |
actor |
A unit (actor; row/column number), which have an opportunity to change a link. |
A vector with the number of paths of length two between the actor and other units.
Marjan Cugmas and Aleš Žiberna
Cugmas, M., & Žiberna, A. (2022). Approaches to blockmodeling dynamic networks: a Monte Carlo simulation study. Social Networks, in review.
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) OSPtransitivity(X, actor = 2)
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) OSPtransitivity(X, actor = 2)
Calculates the network statistic according to the outgoing two path mechanism.
OTPtransitivity(X, actor)
OTPtransitivity(X, actor)
X |
Binary network; of class |
actor |
A unit (actor; row/column number), which have an opportunity to change a link. |
A vector with the number of paths of length two between the actor and other units.
Marjan Cugmas and Aleš Žiberna
Cugmas, M., & Žiberna, A. (2022). Approaches to blockmodeling dynamic networks: a Monte Carlo simulation study. Social Networks, in print.
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) OTPtransitivity(X, actor = 2)
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) OTPtransitivity(X, actor = 2)
Calculate the normalized network statistic according to the popularity mechanism.
popularity(X, actor = NULL)
popularity(X, actor = NULL)
X |
Binary network; of class |
actor |
Not used by the function, set to |
A vector with the normalized popularity mechanism, cacluated for each unit.
Marjan Cugmas and Aleš Žiberna
Cugmas, M., & Žiberna, A. (2022). Approaches to blockmodeling dynamic networks: a Monte Carlo simulation study. Social Networks, in print.
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) popularity(X)
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) popularity(X)
It randomizes a partition by randomly relocating a given share of units between the clusters. The group sizes are preserved.
randomizePartition(partition, p, checkSelected = FALSE)
randomizePartition(partition, p, checkSelected = FALSE)
partition |
Initial partition in a vector format. Each unique value (positive integers) represents one cluster. |
p |
The share of relocated units. |
checkSelected |
If |
A partition (in a vector format).
Marjan Cugmas and Aleš Žiberna
randomizePartition(partition = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3), p = 0.3)
randomizePartition(partition = c(1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3), p = 0.3)
It generates random network considering the selected types of triads.
RL(ideal.net, initial.net, triads = "forb", k = 100, custom.triads = NULL)
RL(ideal.net, initial.net, triads = "forb", k = 100, custom.triads = NULL)
ideal.net |
Network with a desired blockmodel without inconsistencies; of class |
initial.net |
Initial network; of class |
triads |
What types of triads has to be considered (allowed |
k |
Number of iterations. |
custom.triads |
A list with names of a subset of triads to be considered. The same names must be used as in ERGM package. Only if |
A list contiainig: new.network
which is the generated network (of class matrix
); and CR
which is
a vector of CR values (calculated after each iteration).
Marjan Cugmas and Aleš Žiberna
Cugmas M, Ferligoj A, Žiberna A (2018) Generating global network structures by triad types. PLoS ONE 13(5): e0197514. https://doi.org/10.1371/journal.pone.0197514
# generate initial and ideal network cohesiveBM <- rbind(c("com", "nul"), c("nul", "com")) ideal <- genNetworkLE(BM = cohesiveBM, LE = 0, size = c(4, 4)) random <- genNetworkLE(BM = cohesiveBM, LE = 1, size = c(4, 4)) # generate network with the RL algorithm generatedNetwork <- RL(ideal.net = ideal, initial.net = random, triads = "all", k = 10)
# generate initial and ideal network cohesiveBM <- rbind(c("com", "nul"), c("nul", "com")) ideal <- genNetworkLE(BM = cohesiveBM, LE = 0, size = c(4, 4)) random <- genNetworkLE(BM = cohesiveBM, LE = 1, size = c(4, 4)) # generate network with the RL algorithm generatedNetwork <- RL(ideal.net = ideal, initial.net = random, triads = "all", k = 10)
It calculates the sum of square differences between the desired (specified by an image matrix M) denstities and empirical densities.
SSEblock(X, M, partition, loops)
SSEblock(X, M, partition, loops)
X |
Initial binary network; of class |
M |
Image matrix with block densities. |
partition |
A partition in a vector format. Each unique value (positive integers) represents one cluster. |
loops |
Wheter loops are allowed or not. |
Sum of squared error (a single value).
Marjan Cugmas
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) diag(X) <- 0 M <- matrix(c(0.1, 0.4, 0.5, 0.3), nrow = 2) partition <- c(1, 2, 2, 1, 1, 2, 2, 2, 1) SSEblock(X = X, M = M, partition = partition, loops = TRUE)
X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) diag(X) <- 0 M <- matrix(c(0.1, 0.4, 0.5, 0.3), nrow = 2) partition <- c(1, 2, 2, 1, 1, 2, 2, 2, 1) SSEblock(X = X, M = M, partition = partition, loops = TRUE)
It calculates the weighted network statistics, considering the selected local network mecahnisms and their weights.
WeightedNetworkStatistics(X, formula, theta, actor, randomSD = 0)
WeightedNetworkStatistics(X, formula, theta, actor, randomSD = 0)
X |
Binary network; of class |
formula |
The list of local netork mechanisms to be considered. |
theta |
A vector with the mechanisms' weights/strengths. |
actor |
A unit (actor; row/column number), which have an opportunity to change a link. |
randomSD |
The srandard deviation of a normal distribution form which the random part of weighed network statistics is sampled. |
The data frame with one column and the number of rows equal to the number of units.
Marjan Cugmas and Aleš Žiberna
formula <- list(mutuality, popularity, OTPtransitivity) X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) WeightedNetworkStatistics(X = X, formula = formula, theta = c(1, 1, 1), actor = 1)
formula <- list(mutuality, popularity, OTPtransitivity) X <- matrix(sample(c(0,1), size = 9**2, replace = TRUE), nrow = 9) WeightedNetworkStatistics(X = X, formula = formula, theta = c(1, 1, 1), actor = 1)