88# ' @param M Number of binary regressors (default: 5).
99# ' @param k Number of clusters (default: 40).
1010# ' @param p N x 1 vector, Probability to be assigned to the active individual
11- # ' intervention (default: rep(0.2,2000 ))
11+ # ' intervention (default: rep(0.2, N ))
1212# ' @param het TRUE if the treatment effects 1000 and 1101 are heterogeneous with
1313# ' respect to the first regressor (h with X1=0, -taui with X0=0), FALSE if
1414# ' constant (-h) (default: TRUE).
1515# ' @param h Absolute value of the treatment effects 1000 and 1101
1616# ' (default: 2).
17- # ' @param method_networks Method to generate the m networks:
18- # ' "ergm" (Exponential Random Graph Models), "er" (Erdos Renyi), "sf"
19- # ' (Barabasi-Albert model) (default: "er").
20- # ' Note: in this function, clusters have the same size, so N should be a multiple of m
17+ # ' @param method_networks Method to generate the k within-cluster networks
18+ # ' (block-diagonal subgraphs): "ergm" (Exponential Random Graph Models),
19+ # ' "er" (Erdos Renyi), "sf" (Barabasi-Albert model) (default: "er").
20+ # ' Note: in this function, clusters have the same size, so N should be a multiple of k
2121# ' @param param_er Probability of the "er" model, if used (default: 0.2).
2222# ' @param coef_ergm Coefficients of the "ergm" model, if used (default: NULL).
2323# ' @param var_homophily_ergm Variable to account for homophily in the "ergm"
2424# ' model (default: NULL).
2525# ' @param remove_isolates Logical; remove isolated nodes? (default TRUE)
2626# '
2727# ' @return A list of synthetic data containing:
28- # ' - NxM covariates matrix (`X`).
29- # ' - Nx1 outcome vector (`Y`),
30- # ' - Nx1 individual intervention vector (`W`),
31- # ' - NxN adjacency matrix (`A`),
32- # ' - Nx1 neighborhood intervention vector (`G`),
33- # ' - Nx1 group membership vector (`K`),
34- # ' - Nx1 probability to be assigned to the active individual intervention vector
35- # ' (`p`),
28+ # ' - NxM covariates matrix (`X`)
29+ # ' - Nx1 outcome vector (`Y`)
30+ # ' - Nx1 individual intervention vector (`W`)
31+ # ' - NxN adjacency matrix (`A`)
32+ # ' - Nx1 neighborhood intervention vector (`G`)
33+ # ' - Nx1 group membership vector (`K`)
34+ # ' - Nx1 probability to be assigned to the active individual intervention vector (`p`)
3635# '
3736# ' @importFrom igraph graph_from_data_frame V E make_empty_graph layout_as_tree "E<-" "V<-"
3837# '
4140data_generator = function (N = 2000 ,
4241 M = 5 ,
4342 k = 40 ,
44- p = rep(0.2 ,2000 ),
43+ p = rep(0.2 , N ),
4544 het = TRUE ,
4645 h = 2 ,
4746 method_networks = " er" ,
48- param_er = 0.1 ,
47+ param_er = 0.2 ,
4948 coef_ergm = NULL ,
5049 var_homophily_ergm = NULL ,
5150 remove_isolates = TRUE ){
5251
5352 if (length(p ) != N ) {
5453 stop(' The length of vector describing individual probabilities to be assigned to the intervention MUST be equal to N' )
5554 }
55+
56+ if (N %% k != 0 ) {
57+ stop(" N must be an exact multiple of k to form equal-sized clusters when constructing the network (before optional isolate removal)." )
58+ }
5659
5760 X <- NULL
5861 for (m in 1 : M ) {
@@ -69,12 +72,9 @@ data_generator = function(N = 2000,
6972 var_homophily_ergm = var_homophily_ergm ,
7073 X = X )
7174
72- net <- igraph :: graph_from_adjacency_matrix(A )
73-
7475 cluster_size <- N / k
7576 K <- c(rep(1 : k , cluster_size ))
7677 K <- sort(K )
77- levels(K ) <- c(1 : k )
7878
7979 W <- rbinom(N , 1 , prob = p )
8080
0 commit comments