simulate_lbm: Simulate a bipartite interaction network using block model

View source: R/simulate_bm.R

simulate_lbmR Documentation

Simulate a bipartite interaction network using block model

Description

Simulate a bipartite interaction network using block model

Usage

simulate_lbm(con, pi, rho, nr, nc, method = "gnp")

Arguments

con

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.

pi

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.

rho

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.

nr

The number of row Species

nc

The number of column Species

method

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.

Value

A list of 3 elements:

  • A The incident matrix of size nrxnc

  • 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

Examples

# 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")

# 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")

robber documentation built on May 29, 2024, 5:48 a.m.