Simulate a bipartite interaction network using block model
simulate_lbm(con, pi, rho, nr, nc, method = "gnp")
A matrix, the connectivity between blocks. If
method = "gnp"
then each entry is the probability of interactions
given 2 blocks. If method = "gnm"
then each entry is the number of
interactions between 2 blocks.
A vector of the same length as nrow(con)
,
the block mixture for the row species. If method = "gnp"
, then
pi
is a probability vector, if method = "gnm"
, then
pi
is the number of species per block, must sum to nr
.
A vector of the same length as ncol(con)
,
the block mixture for the column species. If method = "gnm"
, then
rho
is a probability vector, if method = "gnm"
, then
rho
is the number of species per block, must sum to nc
.
The number of row Species
The number of column Species
One of "gnp"
(the default) where the blocks size and
number of interactions is random and "gnm"
where the blocks size and
number of interactions are fixed.
A list of 3 elements:
A
The incident matrix of size nr
xnc
Z
A vector of length nr
, the block assignment of the row
species
W
A vector of length nc
, the block assignment of the column
species
# For a random number of interactions and blocks sizes
con <- matrix(c(.5,.3,.3,.1), 2, 2)
pi <- c(.25,.75)
rho <- c(1/3, 2/3)
nr <- 50
nc <- 30
simulate_lbm(con, pi, rho, nr, nc, method = "gnp")
#> $A
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#> [1,] 0 0 0 0 0 0 0 1 1 0 0 0 1
#> [2,] 1 0 0 0 0 0 1 0 1 0 0 0 0
#> [3,] 0 0 1 0 0 0 0 0 0 0 0 0 0
#> [4,] 1 0 0 0 0 0 1 0 0 0 0 1 0
#> [5,] 0 0 0 0 0 0 0 0 0 0 0 1 0
#> [6,] 0 0 0 0 0 0 0 0 0 0 0 0 0
#> [7,] 1 1 1 0 0 0 1 0 1 0 1 1 0
#> [8,] 0 0 0 0 0 0 1 0 1 0 0 0 0
#> [9,] 0 0 0 0 0 0 0 0 0 0 0 0 0
#> [10,] 0 0 0 0 0 1 1 0 1 0 0 0 1
#> [11,] 0 0 0 0 0 0 0 0 0 0 0 1 0
#> [12,] 1 0 0 0 0 0 0 0 0 0 0 0 0
#> [13,] 0 0 0 0 0 0 0 0 0 0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
#> [14,] 0 0 0 0 1
#> [15,] 0 0 1 0 1
#> [16,] 1 0 1 0 0
#> [17,] 1 0 1 0 1
#> [18,] 0 0 1 0 0
#> [19,] 0 0 0 0 1
#> [20,] 0 0 1 0 0
#> [21,] 0 0 0 0 1
#> [22,] 0 0 0 0 0
#> [23,] 0 0 0 0 1
#> [24,] 0 0 0 0 0
#> [25,] 0 0 1 1 1
#> [26,] 1 0 1 1 1
#> [27,] 1 0 1 0 0
#> [28,] 0 0 0 0 0
#> [29,] 0 0 0 1 0
#> [30,] 1 0 1 0 0
#> [31,] 0 0 1 0 0
#> [32,] 0 0 1 1 0
#> [33,] 0 0 0 0 0
#> [34,] 1 1 1 1 1
#> [35,] 1 0 1 0 0
#> [36,] 1 1 1 0 0
#> [37,] 1 0 0 0 1
#> [38,] 0 0 0 1 0
#> [39,] 0 1 0 0 0
#> [40,] 1 0 0 0 0
#> [41,] 0 0 1 0 0
#> [42,] 0 0 0 1 0
#> [43,] 0 0 0 0 1
#> [44,] 0 0 0 0 0
#> [45,] 0 0 0 0 1
#> [46,] 0 0 1 0 0
#> [47,] 1 0 1 0 1
#> [48,] 0 0 0 1 0
#> [49,] 0 0 1 1 0
#> [50,] 1 0 1 0 1
#>
#> $W
#> [1] 1 2 2 2 2 2 1 2 1 2 2 1 2 2 1 1 2 2 2 1 2 2 2 2 1 1 2 1 2 1
#>
#> $Z
#> [1] 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 1 2 2 1 2 1 2 1 2 2
#> [39] 2 2 2 2 2 2 2 2 1 2 1 2
#>
# For a fixed number of ineractions and blocks sizes
con <- matrix(c(50, 120, 60, 80), 2, 2)
pi <- c(10, 40)
rho <- c(10, 20)
nr <- 50
nc <- 30
simulate_lbm(con, pi, rho, nr, nc, method = "gnm")
#> $A
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#> [1,] 0 1 1 0 1 1 0 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 0
#> [46,] 0 0 0 0 1 0 0 0 1 0 0 0
#> [47,] 0 0 0 1 0 1 0 0 0 0 0 0
#> [48,] 0 0 0 0 0 0 0 0 0 0 0 0
#> [49,] 1 0 0 1 1 0 1 0 0 0 0 0
#> [50,] 1 0 0 0 0 0 0 0 0 0 0 0
#> [,26] [,27] [,28] [,29] [,30]
#> [1,] 0 0 0 1 0
#> [2,] 1 1 0 1 0
#> [3,] 0 1 1 0 1
#> [4,] 0 1 0 0 0
#> [5,] 1 0 0 1 0
#> [6,] 0 0 0 1 1
#> [7,] 0 0 1 0 1
#> [8,] 1 1 0 0 0
#> [9,] 0 0 0 0 0
#> [10,] 0 0 0 1 1
#> [11,] 0 0 0 0 0
#> [12,] 0 1 0 0 0
#> [13,] 0 0 0 0 0
#> [14,] 0 0 0 1 0
#> [15,] 0 0 0 0 1
#> [16,] 0 0 0 0 0
#> [17,] 0 0 0 0 0
#> [18,] 1 1 0 0 0
#> [19,] 0 0 0 0 0
#> [20,] 0 0 0 0 0
#> [21,] 0 0 0 0 0
#> [22,] 0 0 0 0 0
#> [23,] 0 0 0 0 0
#> [24,] 0 0 0 0 1
#> [25,] 0 0 0 0 0
#> [26,] 0 0 1 0 0
#> [27,] 0 0 0 0 0
#> [28,] 0 0 1 0 0
#> [29,] 1 0 0 0 1
#> [30,] 0 0 1 0 0
#> [31,] 0 0 0 0 0
#> [32,] 0 0 0 0 0
#> [33,] 0 0 0 0 0
#> [34,] 0 0 1 0 0
#> [35,] 0 0 0 0 1
#> [36,] 0 0 0 0 0
#> [37,] 0 1 0 0 0
#> [38,] 0 0 0 0 0
#> [39,] 0 0 0 0 0
#> [40,] 0 0 0 0 0
#> [41,] 0 0 0 0 0
#> [42,] 0 0 0 0 0
#> [43,] 0 1 0 0 0
#> [44,] 0 0 0 0 0
#> [45,] 0 1 0 0 0
#> [46,] 0 0 0 0 0
#> [47,] 0 0 0 0 0
#> [48,] 0 0 1 0 0
#> [49,] 0 0 1 0 0
#> [50,] 0 0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