RNGkind(sample.kind = "Rounding")
set.seed(1729)
# We model a network with 3 even classes
n1 <- 2
n2 <- 2
n3 <- 2
# Generating block assignments for each of the nodes
n <- n1 + n2 + n3
class <- rep(c(1, 2, 3), c(n1, n2, n3))
# Generating the adjacency matrix of the network
# Generate the matrix of connection probabilities
cmat <- matrix(
c(
0.80, 0.50, 0.50,
0.50, 0.80, 0.50,
0.50, 0.50, 0.80
),
ncol = 3,
byrow = TRUE
)
pmat <- cmat / n
# Creating the n x n adjacency matrix
adj <- matrix(0, n, n)
for (i in 2:n) {
for (j in 1:(i - 1)) {
p <- pmat[class[i], class[j]] # We find the probability of connection with the weights
adj[i, j] <- rbinom(1, 1, p) # We include the edge with probability p
}
}
adjsymm <- adj + t(adj)
# graph from the adjacency matrix
G <- igraph::graph_from_adjacency_matrix(adjsymm, mode = "undirected", weighted = NULL)
# mle of the edge probabilities
get_mle_BetaSBM(G, class)
Run the code above in your browser using DataLab