add.blocks {incidentally}R Documentation

Adds a block structure to an incidence matrix

Description

add.blocks shuffles an incidence matrix to have a block structure or planted partition while preserving the row and column sums

Usage

add.blocks(
  I,
  rowblock = sample(1:2, replace = T, nrow(I)),
  colblock = sample(1:2, replace = T, ncol(I)),
  density = 0.5,
  sorted = FALSE
)

Arguments

I

An incidence matrix or igraph bipartite graph

rowblock

numeric: vector indicating each row node's block membership

colblock

numeric: vector indicating each column node's block membership

density

numeric: desired within-block density

sorted

boolean: if TRUE, return incidence matrix permuted by block

Details

Stochastic block and planted partition models generate graphs in which the probability that two nodes are connected depends on whether they are members of the same or different blocks/partitions. Functions such as sample_sbm can randomly sample from stochastic block models with given probabilities. In contrast add.blocks adds a block structure to an existing incidence matrix while preserving the row and column sums. Row nodes' and column nodes' block memberships are supplied in separate vectors. If block membership vectors are not provided, then nodes are randomly assigned to two groups.

Value

An incidence matrix or igraph bipartite graph with a block structure

References

Neal, Z. P., Domagalski, R., and Sagan, B. 2021. Comparing alternatives to the fixed degree sequence model for extracting the backbone of bipartite projections. Scientific Reports, 11, 23929. doi: 10.1038/s41598-021-03238-3

Neal, Z. P. 2022. incidentally: An R package to generate incidence matrices and bipartite graphs. OSF Preprints doi: 10.31219/osf.io/ectms

Examples

I <- incidence.from.probability(R = 100, C = 100, P = .1)
blocked <- add.blocks(I, density = .7)
all(rowSums(I)==rowSums(blocked))
all(colSums(I)==colSums(blocked))

B <- igraph::sample_bipartite(100, 100, p=.1)
blocked <- add.blocks(B, density = .7)
all(igraph::degree(B)==igraph::degree(blocked))

[Package incidentally version 1.0.2 Index]