View source: R/simulate_sbm_plus_srm_network.R
simulate_sbm_plus_srm_network | R Documentation |
This is a function to simulate single layer network data with a stochastic block structure, sender-receiver effects, and dyadic reciprocity. This function is essentially the union of a social relations model and a stochastic block model.
simulate_sbm_plus_srm_network(
N_id = 99,
B = NULL,
V = 3,
groups = NULL,
sr_mu = c(0, 0),
sr_sigma = c(0.3, 1.5),
sr_rho = 0.6,
dr_mu = c(0, 0),
dr_sigma = 1,
dr_rho = 0.7,
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. |
sr_mu |
Mean A vector for sender and receivier random effects. In most cases, this should be c(0,0). |
sr_sigma |
A standard deviation vector for sender and receivier random effects. The first element controls node-level variation in out-degree, the second in in-degree. |
sr_rho |
Correlation of sender-receiver effects (i.e., generalized reciprocity). |
dr_mu |
Mean A vector for dyadic random effects. In most cases, this should be c(0,0). |
dr_sigma |
Standard deviation for dyadic random effects. |
dr_rho |
Correlation of dyad effects (i.e., dyadic reciprocity). |
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(-8, nrow=G, ncol=G)
diag(B) = -4.5 # Block matrix
B[1,3] = -5.9
B[3,2] = -6.9
A = simulate_sbm_plus_srm_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),
sr_sigma = c(1.4, 0.8), sr_rho = 0.5,
dr_sigma = 1.2, dr_rho = 0.8,
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.