Bergm.ws

Bayesian multi-layer dissolution ERGMs for weighted and signed weighted networks.

A weighted network is cut into nested binary layers x0 ⊇ x1 ⊇ … ⊇ xK by thresholding its edge weights. Each transition xk−1 → xk is modelled by an exponential random graph model whose statistics are computed on layer k, conditionally on the observed lower layers. The layer-specific parameters are partially pooled by a Normal–inverse-Wishart hierarchical prior, and the posterior is sampled with an adaptive approximate exchange algorithm.

network function layers in the formula
multi-layer, non-signed weights bergm_w() x_1, …, x_K
multi-layer, signed weights and signs of the edges of x0 bergm_ws() x_1, …, x_K and the signs z

Models are written as ergm.multi formulas, either layer by layer or once as a template with x_k, which is repeated for every layer.

The examples use a small simulated network (toy_ws, 40 nodes, three modules and a minority faction); no real data are included.

Installation

install.packages("Bergm.ws_0.1.0.tar.gz", repos = NULL, type = "source")

It needs ergm (≥ 4.6), ergm.multi, network and coda.

Quick start

library(Bergm.ws)
data(toy_ws)

## signed weighted network
dat <- ws_data(toy_ws$weights, toy_ws$thresholds, toy_ws$signs, toy_ws$attributes)
dat                                        # layers, edges, signs, triangles

f <- ~ L(~edges, ~(z & x_k)) + L(~nodematch("pathway"), ~(z & x_k)) + L(~edges, ~(!z & x_k)) +
  gwespL(0.5, fixed = TRUE, L.base = ~(z & x_k), Ls.path = list(~(z & x_k), ~(z & x_k))) +
  gwespL(0.5, fixed = TRUE, L.base = ~(!z & x_k), Ls.path = list(~(z & x_k), ~(z & x_k)))

mod <- ws_model(dat, f, scale = "gwesp")   # check the formula, see the statistics
mod

fit <- bergm_ws(mod, n_iter = 10000, burnin = 2500, thin = 2, n_chains = 4, cores = 2)

summary(fit)                     

coef(fit)                                  # posterior means by layer

draws <- as.mcmc.list(fit)                 # draws as a coda object

pp <- ws_predictive(fit, nsim = 200)
pp                                         # observed vs simulated statistics, mid-p
ws_aux_check(fit)

## the same weights without signs
dat_2 <- ws_data(toy_ws$weights, toy_ws$thresholds, attributes = toy_ws$attributes)

fit_2 <- bergm_w(dat_2, ~ L(~edges, ~x_k) + L(~triangle, ~x_k),
                 n_iter = 6000, burnin = 1500, n_chains = 4, cores = 2)

summary(fit_2)

In signed data (z & x_k) selects the positive edges of layer k and (!z & x_k) its negative edges. A formula may also name the layers explicitly (x_1, x_2, …); the statistics must then be grouped by layer, with the same terms in every layer, because the hierarchical prior pools the j-th statistic of all layers. scale = "gwesp" multiplies every GWESP statistic by e−α, so that its coefficient is on the same scale in every layer.

demo("toy_example", package = "Bergm.ws") runs both workflows.

Vignette

vignette("Bergm.ws", package = "Bergm.ws")

One Quarto vignette covers the model and its notation, a complete analysis of a signed network with bergm_ws(), the same weights without signs with bergm_w(), and the adaptive exchange algorithm with a comparison of its parts. The code uses the names of the notation (w, t_k, z, y, s, phi, mu, post, y_rep, …). The comparison of the samplers is stored with the package; the script that computed it is system.file("scripts", "precompute_vignettes.R", package = "Bergm.ws").

What is in the package

Data and model

The adaptive exchange algorithm (bergm_w(), bergm_ws())

None of the following changes the posterior; each one makes the sampler cheaper or more robust.

On the toy example (15 layer parameters, 4 chains × 20,000 iterations, 11 minutes on 2 cores) all Rhat values are below 1.02 and the smallest effective sample size is 281.

Predictive checks (ws_predictive())

Prior and posterior predictive simulation, compared with the observed network on the model statistics and on statistics that are not in the model, in every layer: signed triangle counts (+++, -++, +--, ---) and the spread of the positive degrees for signed networks; triangles, spread and maximum of the degrees otherwise. print() gives the observed value, the mean and the central 95% of the simulated values and the mid-p value of every statistic; the simulated statistics are returned for further analysis.

The package has no plotting functions: draws are available as coda objects (as.mcmc.list(fit)) and the layers as network objects (dat$x), so any plotting tool can be used.

The model in one formula

p(z, x1:K | x̃0:K−1, φ) ∝ exp{Σk φkᵀ s(z, xk)} · Πk 1{xk ⊆ x̃k−1}, with φk | μ, Σ ~ N(μ, Σ), μ ~ N(μ0, Σ0), Σ ~ IW(ν0, S0),

where x̃k−1 is the observed layer k−1 and z the signs (bergm_ws()); without signs (bergm_w()) the statistics are s(xk) and z is dropped. Simulated networks are conditional on the observed lower layers and need not be nested.

References

Caimo, A. and Gollini, I. (2020). A multi-layer exponential random graph modelling approach for weighted networks. Computational Statistics & Data Analysis, 142, 106825.

Caimo, A. and Friel, N. (2011). Bayesian inference for exponential random graph models. Social Networks, 33, 41–55.

Christen, J. A. and Fox, C. (2005). Markov chain Monte Carlo using an approximation. Journal of Computational and Graphical Statistics, 14, 795–810.

Haario, H., Saksman, E. and Tamminen, J. (2001). An adaptive Metropolis algorithm. Bernoulli, 7, 223–242.

Krivitsky, P. N., Koehly, L. M. and Marcum, C. S. (2020). Exponential-family random graph models for multi-layer networks. Psychometrika, 85, 630–659.

Murray, I., Ghahramani, Z. and MacKay, D. (2006). MCMC for doubly-intractable distributions. Proceedings of the 22nd Conference on Uncertainty in Artificial Intelligence, 359–366.

van Dyk, D. A. and Park, T. (2008). Partially collapsed Gibbs samplers: theory and methods. Journal of the American Statistical Association, 103, 790–796.

mirror server hosted at Truenetwork, Russian Federation.