Skip to contents

The 'dcsbm' packages provides methods for estimating a two-way degree corrected stochastic block model for directed, weighted graphs. Depends on the 'igraph' library https://igraph.org for graph handling. See Peixoto (2014) <10.1103/PhysRevE.89.012804> for details on the inference algorithm.

Estimate a stochastic block model with or without degree correction. Works for directed multigraphs with self-loops.

Usage

dcsbm(
  graph,
  degree_correction = FALSE,
  n.blocks = c(1, Inf),
  n.moves = 10,
  n.sweeps = 0,
  verbose = TRUE,
  control = list(sigma = 1.5, eps = 0.1, beta = 1, start_partition = NULL)
)

Arguments

graph

An igraph graph.

degree_correction

Whether to use degree correction.

n.blocks

The maximum and minimum number of blocks to consider in the estimation.

n.moves

Number of merge trials per block (see collapse_step).

n.sweeps

Number of sweeps after block merge (see collapse_step).

verbose

Wether to print verbose output during estimation.

control

List of parameters for the inference algorithm.

Value

A list object including the estimated SBM parameters such as block transmission probabilities and degree correction parameters Entries:

B_opt

Optimal number of blocks

minimum_description_length

Description length of the best partition

block_transmission_probs

A B x B matrix of block transmission probabilities

degree_parameters

A list with one or two degree parameters per node depending on whether the graph is undirected or directed

best_partition

The optimal estimated partition

iterations

information about each collapse iteration

Details

Estimate a degree corrected stochastic block model: dcsbm

Sample a (weighted) graph from the planted partition model: sample_ppm Sample a (weighted) graph from a degree variable planted partition model: sample_dcppm

Examples

g <- sample_ppm(60, 0.9, 10, 3)
model <- dcsbm(g)
#> 
#> GRAPH: Undirected - Multi graph - Without loops (N = 60, E = 597)
#> 
#> Estimating a traditional SBM via agglomerative merging.
#> 
#> Using a random starting partition with 60 blocks.
#> 
#> Merging from 60 to 1 block(s)...
#> 
  |                                                     
  |                                               |   0%  [ 60 -> 40 blocks ]
  |                                                     
  |=                                              |   2%
  |                                                     
  |==                                             |   3%
  |                                                     
  |==                                             |   5%
  |                                                     
  |===                                            |   7%
  |                                                     
  |====                                           |   8%
  |                                                     
  |=====                                          |  10%
  |                                                     
  |=====                                          |  12%
  |                                                     
  |======                                         |  13%
  |                                                     
  |=======                                        |  15%
  |                                                     
  |========                                       |  17%
  |                                                     
  |=========                                      |  18%
  |                                                     
  |=========                                      |  20%
  |                                                     
  |==========                                     |  22%
  |                                                     
  |===========                                    |  23%
  |                                                     
  |============                                   |  25%
  |                                                     
  |=============                                  |  27%
  |                                                     
  |=============                                  |  28%
  |                                                     
  |==============                                 |  30%
  |                                                     
  |===============                                |  32%
  |                                                     
  |================                               |  33%
  |                                                     
  |================                               |  35%
  |                                                     
  |=================                              |  37%
  |                                                     
  |==================                             |  38%
  |                                                     
  |===================                            |  40%
  |                                                     
  |====================                           |  42%
  |                                                     
  |====================                           |  43%
  |                                                     
  |=====================                          |  45%
  |                                                     
  |======================                         |  47%
  |                                                     
  |=======================                        |  48%
  |                                                     
  |========================                       |  50%
  |                                                     
  |========================                       |  52%
  |                                                     
  |=========================                      |  53%
  |                                                     
  |==========================                     |  55%
  |                                                     
  |===========================                    |  57%
  |                                                     
  |===========================                    |  58%
  |                                                     
  |============================                   |  60%
  |                                                     
  |=============================                  |  62%
  |                                                     
  |==============================                 |  63%
  |                                                     
  |===============================                |  65%
  |                                                     
  |===============================                |  67%
  |                                                     
  |================================               |  68%
  |                                                     
  |=================================              |  70%
  |                                                     
  |==================================             |  72%
  |                                                     
  |==================================             |  73%
  |                                                     
  |===================================            |  75%
  |                                                     
  |====================================           |  77%
  |                                                     
  |=====================================          |  78%
  |                                                     
  |======================================         |  80%
  |                                                     
  |======================================         |  82%
  |                                                     
  |=======================================        |  83%
  |                                                     
  |========================================       |  85%
  |                                                     
  |=========================================      |  87%
  |                                                     
  |==========================================     |  88%
  |                                                     
  |==========================================     |  90%
  |                                                     
  |===========================================    |  92%
  |                                                     
  |============================================   |  93%
  |                                                     
  |=============================================  |  95%
  |                                                     
  |=============================================  |  97%
  |                                                     
  |============================================== |  98%
  |                                                     
  |===============================================| 100%
#> 
  |                                                     
  |                                               |   0%  [ 40 -> 27 blocks ]
  |                                                     
  |=                                              |   2%
  |                                                     
  |==                                             |   5%
  |                                                     
  |====                                           |   8%
  |                                                     
  |=====                                          |  10%
  |                                                     
  |======                                         |  12%
  |                                                     
  |=======                                        |  15%
  |                                                     
  |========                                       |  18%
  |                                                     
  |=========                                      |  20%
  |                                                     
  |===========                                    |  22%
  |                                                     
  |============                                   |  25%
  |                                                     
  |=============                                  |  28%
  |                                                     
  |==============                                 |  30%
  |                                                     
  |===============                                |  32%
  |                                                     
  |================                               |  35%
  |                                                     
  |==================                             |  38%
  |                                                     
  |===================                            |  40%
  |                                                     
  |====================                           |  42%
  |                                                     
  |=====================                          |  45%
  |                                                     
  |======================                         |  48%
  |                                                     
  |========================                       |  50%
  |                                                     
  |=========================                      |  52%
  |                                                     
  |==========================                     |  55%
  |                                                     
  |===========================                    |  58%
  |                                                     
  |============================                   |  60%
  |                                                     
  |=============================                  |  62%
  |                                                     
  |===============================                |  65%
  |                                                     
  |================================               |  68%
  |                                                     
  |=================================              |  70%
  |                                                     
  |==================================             |  72%
  |                                                     
  |===================================            |  75%
  |                                                     
  |====================================           |  78%
  |                                                     
  |======================================         |  80%
  |                                                     
  |=======================================        |  82%
  |                                                     
  |========================================       |  85%
  |                                                     
  |=========================================      |  88%
  |                                                     
  |==========================================     |  90%
  |                                                     
  |===========================================    |  92%
  |                                                     
  |=============================================  |  95%
  |                                                     
  |============================================== |  98%
  |                                                     
  |===============================================| 100%
#> 
  |                                                     
  |                                               |   0%  [ 27 -> 18 blocks ]
  |                                                     
  |==                                             |   4%
  |                                                     
  |===                                            |   7%
  |                                                     
  |=====                                          |  11%
  |                                                     
  |=======                                        |  15%
  |                                                     
  |=========                                      |  19%
  |                                                     
  |==========                                     |  22%
  |                                                     
  |============                                   |  26%
  |                                                     
  |==============                                 |  30%
  |                                                     
  |================                               |  33%
  |                                                     
  |=================                              |  37%
  |                                                     
  |===================                            |  41%
  |                                                     
  |=====================                          |  44%
  |                                                     
  |=======================                        |  48%
  |                                                     
  |========================                       |  52%
  |                                                     
  |==========================                     |  56%
  |                                                     
  |============================                   |  59%
  |                                                     
  |==============================                 |  63%
  |                                                     
  |===============================                |  67%
  |                                                     
  |=================================              |  70%
  |                                                     
  |===================================            |  74%
  |                                                     
  |=====================================          |  78%
  |                                                     
  |======================================         |  81%
  |                                                     
  |========================================       |  85%
  |                                                     
  |==========================================     |  89%
  |                                                     
  |============================================   |  93%
  |                                                     
  |=============================================  |  96%
  |                                                     
  |===============================================| 100%
#> 
  |                                                     
  |                                               |   0%  [ 18 -> 12 blocks ]
  |                                                     
  |===                                            |   6%
  |                                                     
  |=====                                          |  11%
  |                                                     
  |========                                       |  17%
  |                                                     
  |==========                                     |  22%
  |                                                     
  |=============                                  |  28%
  |                                                     
  |================                               |  33%
  |                                                     
  |==================                             |  39%
  |                                                     
  |=====================                          |  44%
  |                                                     
  |========================                       |  50%
  |                                                     
  |==========================                     |  56%
  |                                                     
  |=============================                  |  61%
  |                                                     
  |===============================                |  67%
  |                                                     
  |==================================             |  72%
  |                                                     
  |=====================================          |  78%
  |                                                     
  |=======================================        |  83%
  |                                                     
  |==========================================     |  89%
  |                                                     
  |============================================   |  94%
  |                                                     
  |===============================================| 100%
#> 
  |                                                      
  |                                                |   0%  [ 12 -> 8 blocks ]
  |                                                      
  |====                                            |   8%
  |                                                      
  |========                                        |  17%
  |                                                      
  |============                                    |  25%
  |                                                      
  |================                                |  33%
  |                                                      
  |====================                            |  42%
  |                                                      
  |========================                        |  50%
  |                                                      
  |============================                    |  58%
  |                                                      
  |================================                |  67%
  |                                                      
  |====================================            |  75%
  |                                                      
  |========================================        |  83%
  |                                                      
  |============================================    |  92%
  |                                                      
  |================================================| 100%
#> 
  |                                                       
  |                                                 |   0%  [ 8 -> 5 blocks ]
  |                                                       
  |======                                           |  12%
  |                                                       
  |============                                     |  25%
  |                                                       
  |==================                               |  38%
  |                                                       
  |========================                         |  50%
  |                                                       
  |===============================                  |  62%
  |                                                       
  |=====================================            |  75%
  |                                                       
  |===========================================      |  88%
  |                                                       
  |=================================================| 100%
#> 
  |                                                       
  |                                                 |   0%  [ 5 -> 3 blocks ]
  |                                                       
  |==========                                       |  20%
  |                                                       
  |====================                             |  40%
  |                                                       
  |=============================                    |  60%
  |                                                       
  |=======================================          |  80%
  |                                                       
  |=================================================| 100%
#> 
  |                                                       
  |                                                 |   0%  [ 3 -> 2 blocks ]
  |                                                       
  |================                                 |  33%
  |                                                       
  |=================================                |  67%
  |                                                       
  |=================================================| 100%
#> 
  |                                                       
  |                                                 |   0%  [ 2 -> 1 blocks ]
  |                                                       
  |========================                         |  50%
  |                                                       
  |=================================================| 100%
#> Minimal description length for 3 blocks (DL/E = 1.88).
#> 
#> Merging from 5 to 2 block(s)...
#> 
  |                                                       
  |                                                 |   0%  [ 5 -> 4 blocks ]
  |                                                       
  |==========                                       |  20%
  |                                                       
  |====================                             |  40%
  |                                                       
  |=============================                    |  60%
  |                                                       
  |=======================================          |  80%
  |                                                       
  |=================================================| 100%
#> 
  |                                                       
  |                                                 |   0%  [ 4 -> 3 blocks ]
  |                                                       
  |============                                     |  25%
  |                                                       
  |========================                         |  50%
  |                                                       
  |=====================================            |  75%
  |                                                       
  |=================================================| 100%
#> 
  |                                                       
  |                                                 |   0%  [ 3 -> 2 blocks ]
  |                                                       
  |================                                 |  33%
  |                                                       
  |=================================                |  67%
  |                                                       
  |=================================================| 100%
#> Minimal description length for 3 blocks (DL/E = 1.88).
#> 
#> Converged at 3 blocks (DL/E = 1.88).
#>