sampleBipartiteSBM: Sampling of Bipartite SBMs

Description Usage Arguments Value Examples

View source: R/sample.R

Description

This function samples a simple Stochastic Block Models, with various model for the distribution of the edges: Bernoulli, Poisson, or Gaussian models, and possibly with covariates

Usage

1
2
3
4
5
6
7
8
9
sampleBipartiteSBM(
  nbNodes,
  blockProp,
  connectParam,
  model = "bernoulli",
  dimLabels = c(row = "rowName", col = "colName"),
  covariates = list(),
  covariatesParam = numeric(0)
)

Arguments

nbNodes

number of nodes in the network

blockProp

parameters for block proportions: list of size two with row and column block proportions

connectParam

list of parameters for connectivity with a matrix of means 'mean' and an optional matrix of variances 'var', the sizes of which must match blockProp length (in row, respectively in column)

model

character describing the model for the relation between nodes ('bernoulli', 'poisson', 'gaussian', 'ZIgaussian'). Default is 'bernoulli'.

dimLabels

an optional list of labels for each dimension (in row, in column)

covariates

a list of matrices with same dimension as mat describing covariates at the edge level. No covariate per Default.

covariatesParam

optional vector of covariates effect. A zero length numeric vector by default.

Value

an object with class BipartiteSBM

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
### =======================================
### BIPARTITE BERNOULLI SBM
## Graph parameters
nbNodes <- c(100, 120)
blockProp <- list(c(.5, .5), c(1/3, 1/3, 1/3)) # group proportions
means <- matrix(runif(6), 2, 3)  # connectivity matrix
# In Bernoulli SBM, parameters is a list with
# a matrix of means 'mean' which are probabilities of connection
connectParam <- list(mean = means)

## Graph Sampling
dimLabels = c(row='Reader',col='Book')
mySampler <- sampleBipartiteSBM(nbNodes, blockProp, connectParam, model = 'bernoulli',dimLabels)
plot(mySampler)
plot(mySampler,type='meso',plotOptions = list(vertex.label.name=list(row='Reader',col='Book')))
plot(mySampler,type='meso',plotOptions = list(vertex.label.name=c('A','B'),vertex.size = 1.4))
mySampler$rMemberships() # sample new memberships
mySampler$rEdges()   # sample new edges
mySampler$rNetwork()   # sample a new networrk (blocks and edges)
### =======================================
### BIPARTITE POISSON SBM
## Graph parameters
nbNodes <- c(100, 120)
blockProp <- list(c(.5, .5), c(1/3, 1/3, 1/3)) # group proportions
means <- matrix(rbinom(6, 30, 0.25), 2, 3)  # connectivity matrix
# In Poisson SBM, parameters is a list with a matrix of
# means 'mean' which are a mean integer value taken by edges
connectParam <- list(mean = means)

## Graph Sampling
dimLabels = c(row = 'Ind', col = 'Service')
mySampler <- sampleBipartiteSBM(nbNodes, blockProp, connectParam, model = 'poisson', dimLabels)
plot(mySampler,type='expected')
plotOptions = list(vertex.label.name=c('U','V'),vertex.size = c(1.4,1.3))
plot(mySampler, type='meso', plotOptions = plotOptions)
hist(mySampler$networkData)

### =======================================
### BIPARTITE GAUSSIAN SBM
## Graph parameters
nbNodes <- c(100, 120)
blockProp <- list(c(.5, .5), c(1/3, 1/3, 1/3)) # group proportions
means <- 20 * matrix(runif(6), 2, 3)  # connectivity matrix
# In Gaussian SBM, parameters is a list with a matrix
# of means 'mean' and a matrix of variances 'var'
connectParam <- list(mean = means, var = 1)

## Graph Sampling
mySampler <- sampleBipartiteSBM(nbNodes, blockProp, connectParam, model = 'gaussian')
plot(mySampler)
hist(mySampler$networkData)

GrossSBM/sbm documentation built on April 8, 2021, 5:53 a.m.