View source: R/simulate_sbm_network.R
simulate_sbm_network | R Documentation |
This is a function to simulate single layer network data with a stochastic block structure.
simulate_sbm_network(
N_id = 100,
B = NULL,
V = 3,
groups = NULL,
mode = "bernoulli",
individual_predictors = NULL,
dyadic_predictors = NULL,
individual_effects = NULL,
dyadic_effects = NULL
)
N_id |
Number of individuals. |
B |
List of matrices that hold intercept and offset terms. Log-odds. The first matrix should be 1 x 1 with the value being the intercept term. |
V |
Number of blocking variables in B. |
groups |
Dataframe of the block IDs of each individual for each variable in B. |
mode |
Outcome mode: can be "bernoulli", "poisson", or "binomial". |
individual_predictors |
An N_id by N_individual_parameters matrix of covariates. |
dyadic_predictors |
An N_id by N_id by N_dyadic_parameters array of covariates. |
individual_effects |
A 2 by N_individual_parameters matrix of slopes. The first row gives effects of focal characteristics (on out-degree). The second row gives effects of target characteristics (on in-degree). |
dyadic_effects |
An N_dyadic_parameters vector of slopes. |
A list of objects including: network (an adjacency matrix of binary outcomes), tie_strength (an adjacency matrix with probability weights), group_ids (a vector of length N_id, giving the group of each individual), individual_predictors (the supplied covariate data is saved along with the network data), and dyadic_predictors (the supplied covariate data is saved along with the network data).
## Not run:
library(igraph)
V = 1 # One blocking variable
G = 3 # Three categories in this variable
N_id = 100 # Number of people
clique = sample(1:3, N_id, replace=TRUE)
B = matrix(-6, nrow=G, ncol=G)
diag(B) = -1.5 # Block matrix
B[1,3] = -5
B[3,2] = -4
A = simulate_sbm_network(N_id = N_id, B=list(B=B), V=V, groups = data.frame(clique=factor(clique)),
individual_predictor=matrix(rnorm(N_id, 0, 1), nrow=N_id, ncol=1),
individual_effects=matrix(c(1.7, 0.3),ncol=1, nrow=2),
mode="bernoulli"
)
Net = graph_from_adjacency_matrix(A$network, mode = c("directed"))
V(Net)$color = c("turquoise4","gray13", "goldenrod3")[A$group_ids$clique]
plot(Net, edge.arrow.size =0.1, edge.curved = 0.3, vertex.label=NA, vertex.size = 5)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.