Title: Efficient Estimation of Bayesian SBMs & MLSBMs
Version: 0.99.2
Description: Fit Bayesian stochastic block models (SBMs) and multi-level stochastic block models (MLSBMs) using efficient Gibbs sampling implemented in 'Rcpp'. The models assume symmetric, non-reflexive graphs (no self-loops) with unweighted, binary edges. Data are input as a symmetric binary adjacency matrix (SBMs), or list of such matrices (MLSBMs).
License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.1
LinkingTo: Rcpp, RcppArmadillo
Imports: Rcpp
Depends: R (≥ 2.10)
NeedsCompilation: yes
Packaged: 2021-02-01 21:22:53 UTC; carterallen
Author: Carter Allen ORCID iD [aut, cre], Dongjun Chung [aut]
Maintainer: Carter Allen <carter.allen12@gmail.com>
Repository: CRAN
Date/Publication: 2021-02-07 10:50:02 UTC

Simulated 3-layer network data

Description

A data set containing 3 layers of undirected, symmetric adjacency matrices simulated from an SBM with 3 true clusters

Usage

AL

Format

A list of length 3


The col_summarize function

Description

Function to quickly return credible intervals

Usage

col_summarize(MAT, dig = 2, level = 0.95)

Arguments

MAT

A matrix

dig

Number of digits to round estimates and CrIs to

level

Confidence level

Value

A character vector of posterior estimates and intervals

Examples

M <- matrix(rnorm(1000),ncol = 4)
col_summarize(M)

R/Rcpp function for fitting multilevel stochastic block model

Description

This function allows you to fit multilevel stochastic block models.

Usage

fit_mlsbm(
  A,
  K,
  a0 = 0.5,
  b10 = 0.5,
  b20 = 0.5,
  n_iter = 1000,
  burn = 100,
  verbose = TRUE
)

Arguments

A

An adjacency list of length L, the number of levels. Each level contains an n x n symmetric adjacency matrix.

K

The number of clusters specified a priori.

a0

Dirichlet prior parameter for cluster sizes for clusters 1,...,K.

b10

Beta distribution prior paramter for community connectivity.

b20

Beta distribution prior parameter for community connectivity.

n_iter

The number of total MCMC iterations to run.

burn

The number of burn-in MCMC iterations to discard. The number of saved iterations will be n_iter - burn.

verbose

Whether to print a progress bar to track MCMC progress. Defaults to true.

Value

A list of MCMC samples, including the MAP estimate of cluster indicators (z)

Examples

data(AL)
# increase n_iter in practice
fit <- fit_mlsbm(AL,3,n_iter = 100)

R/Rcpp function for fitting single level stochastic block model

Description

This function allows you to fit single level stochastic block models.

Usage

fit_sbm(
  A,
  K,
  a0 = 0.5,
  b10 = 0.5,
  b20 = 0.5,
  n_iter = 1000,
  burn = 100,
  verbose = TRUE
)

Arguments

A

An n x n symmetric adjacency matrix.

K

The number of clusters specified a priori.

a0

Dirichlet prior parameter for cluster sizes for clusters 1,...,K.

b10

Beta distribution prior paramter for community connectivity.

b20

Beta distribution prior parameter for community connectivity.

n_iter

The number of total MCMC iterations to run.

burn

The number of burn-in MCMC iterations to discard. The number of saved iterations will be n_iter - burn.

verbose

Whether to print a progress bar to track MCMC progress. Defaults to true.

Value

A list of MCMC samples, including the MAP estimate of cluster indicators (z)

Examples

data(AL)
fit <- fit_sbm(AL[[1]],3)

The mean_CRI function

Description

Simple function to return the mean (95% CrI) for a vector

Usage

mean_CRI(y, dig = 2)

Arguments

y

A numeric vector

dig

The number of digits to round to

Value

A string of mean and 95% quantile interval rounded to 'dig'

Examples

mean_CRI(rnorm(1000))

mypackage: A package for fitting single and multilevel SBMs.

Description

This package fits Bayesian stochastic block models (SBMs)

mlsbm functions

The mlsbm functions ...


R/Rcpp function for sampling from a multilevel stochastic block model

Description

This function allows you to sample a multilevel stochastic block model.

Usage

sample_mlsbm(z, P, L)

Arguments

z

An n x 1 vector of community labels for each node

P

A K x K symmetric matrix of community connectivity probabilities

L

The number of levels to sample

Value

A list of adjecency matrices – one for each level of the MLSBM

Examples

n = 100
K = 3
L = 2
pi = rep(1/K,K)
z = sample(1:K, size = n, replace = TRUE, prob = pi)
p_in = 0.50
p_out = 0.05
P = matrix(p_out, nrow = K, ncol = K)
diag(P) = p_in
AL = sample_mlsbm(z,P,L)

R/Rcpp function for sampling from a single level stochastic block model

Description

This function allows you to sample a single level stochastic block model.

Usage

sample_sbm(z, P)

Arguments

z

An n x 1 vector of community labels for each node

P

A K x K symmetric matrix of community connectivity probabilities

Value

An adjacency matrix

Examples

n = 100
K = 3
pi = rep(1/K,K)
z = sample(1:K, size = n, replace = TRUE, prob = pi)
p_in = 0.50
p_out = 0.05
P = matrix(p_out, nrow = K, ncol = K)
diag(P) = p_in
A = sample_sbm(z,P)