Learn R Programming

SBMSplitMerge

SBMSplitMerge is an R package for performing inference on the number of blocks and the edge-state parameters in a Generalised Stochastic Block Model using a split-merge sampler. This allows for inference in non-conjugate edge-state models in a Bayesian framework.

This package accompanies the paper ArXiV https://arxiv.org/abs/1909.09421.

The git repository stores this package as well as the examples and data examples available on github:

Getting the package

install.packages("SBMSplitMerge")

Model for the package

Suppose that you have network data in the form of counts of interaction between a set of $N$ animals. You think the animals may display group like behaviour, via their interactions such that individuals in the same group have a higher change of interacting. You also are unsure of the number of groups in the network.

Classic network modelling techniques are based on graphs where the interactions are binary. This is a major restriction. Some methods allow the practitioner to specify a distribution for the interactions, so long as it has a conjugate prior. A flexible model would allow the practitioner to place any distribution on the interaction process.

The number of groups or blocks in the network is a key parameter. Some models in the literature set a joint prior on the number of blocks and assignment of individuals to blocks. This can lead to too many smaller blocks and inconsistent posterior behaviour c.f. Miller and Harrison

The GSBM allows an explicit prior on the number of groups and an arbitrary distribution for the interaction process.

Using the package

Consider the example at the start of this section. Suppose the interactions are in a $N$ by $N$ matrix in R called \code{interacts}. First, you must specify the parts of the model:

  • the interaction process in a edgemod object
  • the prior for the parameters of the edge-model in a parammod object
  • the prior for the number of blocks in a blockmod object

The general method is to specify each of these objects in a list (named, say, model), then call

posterior <- sampler(interacts, model, 10000, "rj")

to run 10000 iterations of the split-merge sampler. The returned list, posterior, contains the trace for the number of blocks, parameter values, block memberships.

The output can be evaluated by some posterior diagnostic plots by calling

print(eval_plots(posterior))

this will plot the traces of the above variables and a posterior probability that two individuals belong to the same block.

For details on setting the model up see the accompanying vignette for a negative binomial model:

vignette("Weibull-edges")

Copy Link

Version

Install

install.packages('SBMSplitMerge')

Monthly Downloads

127

Version

1.1.1

License

MIT + file LICENSE

Maintainer

Matthew Ludkin

Last Published

June 4th, 2020

Functions in SBMSplitMerge (1.1.1)

dedges.numeric

likelihood of edges
delblock

Delete a block move
edges_norm

Normal edge model
edges_nbin

Negative-Binomial edge model
eval_plots

get a set of evaluation plots from MCMC samples
edges_pois

Poisson edge model
blocks

Blocks object
Enron

The Enron data set as extracted from igraph using the script in data-raw
blockmod

Block Model
edges

Class for edge data
edges_bern

Bernoulli edge model
blocktrace

plot a trace of the blocks from MCMC samples
dma

Dirichlet Multinomial Allocation
mergeparams

merge parameters
ddirichlet

Dirichlet distribution
mergeparams.default

Merge step: parameters
param_norm

Parameter model for Normal Model
parammat

Parameter Matrix
is.sbm

is.sbm
mergeparams.numeric

Merge step - parameter merging
marglike_bern

Marginal likelihood model for Bernoulli distributed edges
modeblocks

modal block assignments from MCMC samples
crp

Chinese Restaurant Process
parammat.params

Parameter Matrix
plot.edges

Plot
edgemod

Class for edge models
drawparams

Metropolis updates by drawing parameters
mergeavg

Merge blocks
plot.blocks

Plot blocks
paramtrace

plot a trace of parameter values from MCMC samples
rcat

Draw draw Categorical distribution
plot.sbm

sampler.rj

reversible jump Markov chain Monte Carlo split-merge sampler
rdirichlet

Dirichlet distribution
updateblock

Update the block assignment of a node
sbm

Class sbm
updateblock.blocks

Update the block assignment of a node
numblockstrace

plot a trace of the number of blocks from MCMC samples
drawblocks.dp

Draw block memberships
dedges

Density of edges
drawblocks.gibbs

Gibbs-like reassignment of nodes to the current set of blocks
mergeblocks

merge move block merging
drawblock.dp

Draw block membership
dedges.sbm

Density of edges
param_beta

Beta parameter model
sampler.conj

Conjugate model sampler
sampler

top level sampler function
marglike_norm

Marginal likelihood model for Normal distributed edges
drawblock.gibbs

Gibbs-like reassignment of nodes to the current set of blocks
marglike_pois

Marginal likelihood model for Poisson distributed edges
multinom

Multinomial block assignment
parammat.sbm

Parameter Matrix
param_nbin

Parameter model for Negative Binomial
parammod

Parameter Model
parammat.blocks

Parameter Matrix
nodelike

Likelihood of node assignment
param_gamma

Gamma parameter model
parammat.matrix

Parameter Matrix
rw

Random Walk
redges

Simulate edges
sbmmod

Stochastic block model object
sampler.dp

Dirichlet process sampler
splitavg

split move using average to merge parameters
params

params S3 object
plotpostpairs

helper function for trace plots
sampler.gibbs

Gibbs sampling for node assignments
splitblocks

split move: blocks
splitparams

split move: parameters
updateblock.sbm

Update the block assignment of a node
vmeasure

V-measure
splitparams.numeric

split move: params
splitparams.params

split move: params
postpairs

mean proportion of times two nodes were in the same block under MCMC samples
blockmat

Block matrix
blockmat.blocks

Block matrix
accept

accept propsbm with the acceptance probability alpha
blockmat.numeric

Block matrix
blockmat.sbm

Block matrix
ARI

Adjusted Rand Index
addblock

Add a block move
Macaque

The Macaque data set as extracted from igraph using the script in data-raw
StackOverflow

The Stack-Overflow data set as extracted from igraph using the script in data-raw Extracted on 27/8/2019 from Kaggle (login required) using: library(rvest) read_html("https://www.kaggle.com/stackoverflow/stack-overflow-tag-network/downloads/stack_network_links.csv/1")