| Title: | Bayesian Separable Temporal Exponential Random Graph Models |
|---|---|
| Description: | Bayesian inference for separable temporal exponential random graph models (STERGMs) of dynamic binary networks and for the separable two-layer STERGMs of dynamic signed networks (Caimo and Gollini, 2026). Each transition is decomposed into the formation and persistence of ties (and, for signed networks, of their signs); the resulting doubly-intractable posteriors are sampled with approximate exchange algorithms based on adaptive Metropolis-Hastings or adaptive direction sampling. Posterior predictive goodness of fit, diagnostics of the auxiliary simulations, simulation and forecasting tools are provided. |
| Authors: | Alberto Caimo [aut, cre], Isabella Gollini [aut] |
| Maintainer: | Alberto Caimo <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.1.0 |
| Built: | 2026-11-26 03:11:42 UTC |
| Source: | https://github.com/cran/Bstergm |
Sample space constraint for signed networks built with
as_signed_network(): only the active dyads (network attribute
.active) may change, and only between positive and negative. This is
the sample space of the sign process of a separable signed ERGM, where
the interaction layer is held fixed.
# active_signs# active_signs
Shortcuts for bstergm_sign() with method = "amh" and method = "ads".
They also accept the arguments of version 0.1 of the package (then called
B2Lstergm), i.e. y_t, ergm_sim_iters, mu.prior_F,
Sigma.prior_F, mu.prior_P, Sigma.prior_P, init_s_F, init_s_P,
adapt_start, adapt_interval, gamma_F, gamma_P, sigma.prop_F and
sigma.prop_P; the networks L.x_F, L.x_P, L.z_F, L.z_P and the
statistics sy are no longer needed, as they are computed from y_t.
aea_amh(formula, data = NULL, ...) aea_ads(formula, data = NULL, ...)aea_amh(formula, data = NULL, ...) aea_ads(formula, data = NULL, ...)
formula, data
|
see |
... |
further arguments passed to |
A bstergm_sign() fit. As in version 0.1, its elements theta_F and
theta_P are arrays of posterior draws (iterations x parameters x
chains).
data(senators70_am) senate <- signed_series(senators70_am[1:3]) fit <- aea_amh(~ edges + gwesf_pos(0.6) + gwese_pos(0.6), senate, iters = 100, burn.in = 50, aux.iters = 1000, seed = 1, verbose = FALSE) dim(fit$theta_F)data(senators70_am) senate <- signed_series(senators70_am[1:3]) fit <- aea_amh(~ edges + gwesf_pos(0.6) + gwese_pos(0.6), senate, iters = 100, burn.in = 50, aux.iters = 1000, seed = 1, verbose = FALSE) dim(fit$theta_F)
Converts a signed network to the representation used by the signed-network
ergm terms of this package: a network whose ties are
the positive ties, with the active (interacting) dyads stored as a
two-column edge list in the network attribute .active. Negative ties are
the active dyads that are not ties.
as_signed_network(y, vertex.attr = NULL, sign.attr = "sign", ...)as_signed_network(y, vertex.attr = NULL, sign.attr = "sign", ...)
y |
a signed network: a square symmetric matrix with entries in
{-1, 0, 1}; an undirected network whose edges carry
the edge attribute |
vertex.attr |
optional data frame (or named list) of vertex attributes with one row per node. |
sign.attr |
name of the edge attribute holding the signs when |
... |
unused. |
An undirected network of positive ties with network attribute
.active.
signed_adjacency(), signed_triad_census(),
gwese_pos
data(senators70_am) y <- senators70_am$S99 nw <- as_signed_network(y, vertex.attr = attr(y, "senators")) nw summary(nw ~ edges + gwesf_pos(0.6) + gwese_pos(0.6) + gwese_neg(0.6) + triangle_signed())data(senators70_am) y <- senators70_am$S99 nw <- as_signed_network(y, vertex.attr = attr(y, "senators")) nw summary(nw ~ edges + gwesf_pos(0.6) + gwese_pos(0.6) + gwese_neg(0.6) + triangle_signed())
Convert bstergm draws to coda objects
## S3 method for class 'bstergm' as.mcmc.list( x, components = x$components, prefix = length(components) > 1, ... ) ## S3 method for class 'bstergm' as.mcmc(x, components = x$components, prefix = length(components) > 1, ...)## S3 method for class 'bstergm' as.mcmc.list( x, components = x$components, prefix = length(components) > 1, ... ) ## S3 method for class 'bstergm' as.mcmc(x, components = x$components, prefix = length(components) > 1, ...)
x |
a |
components |
components to include; with both, the parameter names
are prefixed by |
prefix |
whether to prefix the parameter names with the component. |
... |
unused. |
An coda::mcmc.list() with one chain per sampler chain, or, for
as.mcmc(), an coda::mcmc() object with the chains stacked.
The approximate exchange algorithm assumes that every auxiliary network,
simulated by Metropolis-Hastings starting at the observed network, is a
draw from the model. If the simulations are too short, the sampled
posterior is closer to a contrastive-divergence approximation than to the
posterior of the model. This function runs much longer simulations from the
observed networks, at the posterior mean or at posterior draws, and records
the trajectories of the model statistics. The trajectories should settle
within the number of steps used for fitting (the dotted vertical line in
the plot). Large drifts, or chains that move towards and freeze at extreme
configurations, indicate that aux.iters (or aux.visits) should be
increased, or that the model is near-degenerate at these parameter values.
aux_diagnostics( object, components = object$components, transitions = 1, visits = 50, nsamples = 100, ndraws = 1, seed = NULL ) ## S3 method for class 'aux_diagnostics_bstergm' print(x, ...) ## S3 method for class 'aux_diagnostics_bstergm' plot(x, ...)aux_diagnostics( object, components = object$components, transitions = 1, visits = 50, nsamples = 100, ndraws = 1, seed = NULL ) ## S3 method for class 'aux_diagnostics_bstergm' print(x, ...) ## S3 method for class 'aux_diagnostics_bstergm' plot(x, ...)
object |
a |
components |
components to check. |
transitions |
indices of the transitions to check. |
visits |
length of the simulations, in proposals per free dyad. |
nsamples |
number of recorded states along each simulation. |
ndraws |
number of parameter values: |
seed |
random seed. |
x |
an |
... |
unused. |
An object of class aux_diagnostics_bstergm: for each component a
list over transitions and parameter values of trajectories of the
statistics, with the observed statistics and the number of visits per
free dyad used for fitting.
data(senators70_am) senate <- signed_series(senators70_am[1:3]) fit <- bstergm_sign(~ edges + gwesf_pos(0.6) + gwese_neg(0.6), senate, iters = 100, burn.in = 50, aux.iters = 1000, seed = 1, verbose = FALSE) dg <- aux_diagnostics(fit, visits = 10, nsamples = 20, seed = 1) dg plot(dg)data(senators70_am) senate <- signed_series(senators70_am[1:3]) fit <- bstergm_sign(~ edges + gwesf_pos(0.6) + gwese_neg(0.6), senate, iters = 100, burn.in = 50, aux.iters = 1000, seed = 1, verbose = FALSE) dg <- aux_diagnostics(fit, visits = 10, nsamples = 20, seed = 1) dg plot(dg)
Simulates, for posterior draws of the parameters, the formation and
persistence networks of every transition (starting from the observed
networks, as in the auxiliary step of the sampler) and compares their
statistics with the observed ones. Following Caimo and Gollini, the
centred cumulative differences
of the model statistics should
be centred around zero for a well-fitting model. Additional statistics not
in the model (e.g. degree distributions or the signed triangle census) can
be checked with monitor.
bgof( object, nsim = 100, monitor = NULL, aux.iters = NULL, components = object$components, cores = getOption("Bstergm.cores", 1L), seed = NULL, verbose = TRUE ) ## S3 method for class 'bgof_bstergm' print(x, ...) ## S3 method for class 'bgof_bstergm' summary(object, ...)bgof( object, nsim = 100, monitor = NULL, aux.iters = NULL, components = object$components, cores = getOption("Bstergm.cores", 1L), seed = NULL, verbose = TRUE ) ## S3 method for class 'bgof_bstergm' print(x, ...) ## S3 method for class 'bgof_bstergm' summary(object, ...)
object |
a |
nsim |
number of posterior predictive simulations. |
monitor |
optional one-sided formula of additional statistics, e.g.
|
aux.iters |
number of steps of each simulation; by default five times the number used for fitting. |
components |
components to check. |
cores |
number of processes. Each simulation has its own random number stream, so results do not depend on the number of cores. |
seed |
random seed. |
verbose |
print progress messages. |
x |
a |
... |
unused. |
An object of class bgof_bstergm with, for each component, an
array sim (simulations x statistics x transitions) of simulated
statistics, the matrix obs of observed statistics and the matrix
diff of centred cumulative differences.
summary() returns, for each component, a table with the observed
statistics summed over transitions, the mean and 95% interval of the
simulated ones and a two-sided posterior predictive p-value.
plot.bgof_bstergm(), bstergm()
data(senators70_am) senate <- signed_series(senators70_am[1:3], vertex.attr = attr(senators70_am$S99, "senators")) fit <- bstergm_sign(~ edges + nodematch("Party") + gwesf_pos(0.6) + gwese_pos(0.6), data = senate, iters = 100, burn.in = 50, aux.iters = 1000, seed = 1, verbose = FALSE) gf <- bgof(fit, nsim = 10, monitor = ~ triangle_signed(), seed = 2, verbose = FALSE) gf plot(gf)data(senators70_am) senate <- signed_series(senators70_am[1:3], vertex.attr = attr(senators70_am$S99, "senators")) fit <- bstergm_sign(~ edges + nodematch("Party") + gwesf_pos(0.6) + gwese_pos(0.6), data = senate, iters = 100, burn.in = 50, aux.iters = 1000, seed = 1, verbose = FALSE) gf <- bgof(fit, nsim = 10, monitor = ~ triangle_signed(), seed = 2, verbose = FALSE) gf plot(gf)
bstergm() samples the posterior distribution of the formation and
persistence parameters of a separable temporal ERGM (STERGM) for a sequence
of binary networks. bstergm_sign() does the same for the sign process of
the separable two-layer STERGM of a sequence of signed networks. Both use
the approximate exchange algorithm with adaptive Metropolis-Hastings
(method = "amh") or adaptive direction sampling (method = "ads").
bstergm( formula, data, method = c("amh", "ads"), components = c("F", "P"), iters = 30000, burn.in = 10000, thin = 1, n_chains = NULL, aux.iters = NULL, prior.mean = 0, prior.sigma = 10, init = "mple", offset.coef = NULL, cores = getOption("Bstergm.cores", 1L), seed = NULL, control = control.bstergm(), verbose = TRUE ) bstergm_sign( formula, data, method = c("amh", "ads"), components = c("F", "P"), iters = 30000, burn.in = 10000, thin = 1, n_chains = NULL, aux.iters = NULL, prior.mean = 0, prior.sigma = 10, init = "mple", offset.coef = NULL, cores = getOption("Bstergm.cores", 1L), seed = NULL, control = control.bstergm(), verbose = TRUE )bstergm( formula, data, method = c("amh", "ads"), components = c("F", "P"), iters = 30000, burn.in = 10000, thin = 1, n_chains = NULL, aux.iters = NULL, prior.mean = 0, prior.sigma = 10, init = "mple", offset.coef = NULL, cores = getOption("Bstergm.cores", 1L), seed = NULL, control = control.bstergm(), verbose = TRUE ) bstergm_sign( formula, data, method = c("amh", "ads"), components = c("F", "P"), iters = 30000, burn.in = 10000, thin = 1, n_chains = NULL, aux.iters = NULL, prior.mean = 0, prior.sigma = 10, init = "mple", offset.coef = NULL, cores = getOption("Bstergm.cores", 1L), seed = NULL, control = control.bstergm(), verbose = TRUE )
formula |
a one-sided ergm formula, or a list of such formulas (one
per transition, for time-varying covariates) with identical terms. For
|
data |
for |
method |
|
components |
which components to fit: |
iters |
total number of iterations of each chain, including burn-in. |
burn.in |
number of initial iterations discarded. |
thin |
thinning interval of the stored draws. |
n_chains |
number of chains: independent chains for |
aux.iters |
number of steps of each auxiliary network simulation; see
|
prior.mean, prior.sigma
|
mean and covariance of the multivariate
normal prior of each component: scalars, vectors (diagonal covariance),
matrices, or lists with elements |
init |
starting values: |
offset.coef |
values of the parameters of |
cores |
number of processes (default |
seed |
random seed, for reproducible results. |
control |
a list of tuning parameters, see |
verbose |
print progress messages. |
Binary networks. For each transition the
formation network and the persistence
network are modelled by ERGMs with
parameters on and
on , as in the separable
temporal ERGM of Krivitsky and Handcock (2014).
Signed networks. A signed network is decomposed into an
interaction layer and a sign layer (see
signed_series()), and the formation and persistence networks are formed
for both layers. bstergm_sign() models
() by an ERGM with parameter on the sample space
in which the sign of every interacting dyad of may vary and the
interactions are fixed. The interaction layer follows a binary STERGM and
is fitted by bstergm() on the same signed_series(). Under independent
priors the posterior factorises over the components, which are sampled
independently (and in parallel).
Algorithm. The likelihood is intractable, so the posterior is
sampled with the approximate exchange algorithm (Caimo and Friel, 2011):
at each iteration a parameter is proposed, an auxiliary
network is simulated from the model at for every transition,
starting at the observed network, and is accepted with
probability
With method = "amh" proposals are Gaussian random walks whose covariance
is adapted to the chain history (Haario et al., 2001); with method = "ads" each chain of a population moves along the difference of two other
chains (Caimo and Friel, 2011). Caimo and Gollini use adaptive direction
sampling only to find starting values during burn-in and then adaptive
Metropolis-Hastings; this scheme is obtained with method = "amh" and
init = "ads".
Computation. The ergm model, proposal and constraints of every
transition are initialised once, and only the C sampler of ergm is
called during the iterations; with the signed-network terms of this
package the model statistics are also computed in C. Statistics that are
constant on the sample space (such as L(~edges, ~active) of the
multilayer formulation) are detected and dropped.
Length of the auxiliary simulations. The approximate exchange
algorithm treats the end of each auxiliary simulation as an exact draw from
the model. Simulations that are too short return networks close to the
observed ones, and the sampled distribution then resembles a
contrastive-divergence approximation more than the posterior. This matters
most for near-degenerate models. Check the auxiliary simulations with
aux_diagnostics() and the fit with bgof(). If needed, increase
aux.iters or control.bstergm(aux.visits =); the cost per iteration
grows linearly.
Lagged covariates. The networks of each transition carry the
previous time point as network attributes, so that lagged dyadic
covariates can be used as edgecov("lag.active") (any tie at time
) and, for signed data, edgecov("lag.pos") and
edgecov("lag.neg").
An object of class bstergm, a list including
theta |
a list with, for each fitted component, an array of posterior draws (iterations x parameters x chains); |
theta_F, theta_P
|
the same arrays (for compatibility with version 0.1); |
acceptance |
acceptance rates of each chain; |
mple |
the pseudo-likelihood estimates used for initialisation; |
init.ads |
with |
obs.stats |
the observed statistics of each transition; |
process |
|
prior, control, formula, data, time
|
inputs and timings. |
Use summary.bstergm(), plot.bstergm(), bgof() and
as.mcmc.list.bstergm() to analyse it.
Caimo, A. and Gollini, I. (2025). Separable models for dynamic signed networks. arXiv:2505.07669.
Caimo, A. and Friel, N. (2011). Bayesian inference for exponential random graph models. Social Networks, 33(1), 41-55.
Haario, H., Saksman, E. and Tamminen, J. (2001). An adaptive Metropolis algorithm. Bernoulli, 7(2), 223-242.
Krivitsky, P. N. and Handcock, M. S. (2014). A separable model for dynamic networks. Journal of the Royal Statistical Society B, 76(1), 29-46.
network_series(), signed_series(), summary.bstergm(),
bgof(), aux_diagnostics(), control.bstergm(), predict.bstergm()
data(senators70_am) senate <- signed_series(senators70_am[1:3], vertex.attr = attr(senators70_am$S99, "senators")) # Very short runs for illustration; in practice use many more iterations # (e.g. iters = 30000, burn.in = 10000) and the default auxiliary length. # Binary STERGM of the interactions (ties of either sign) fit_x <- bstergm(~ edges + nodematch("Party"), data = senate, iters = 100, burn.in = 50, aux.iters = 1000, seed = 1, verbose = FALSE) summary(fit_x) # Sign process given the interactions fit_z <- bstergm_sign(~ edges + nodematch("Party") + gwesf_pos(0.6) + gwese_pos(0.6), data = senate, iters = 100, burn.in = 50, aux.iters = 1000, seed = 1, verbose = FALSE) summary(fit_z)data(senators70_am) senate <- signed_series(senators70_am[1:3], vertex.attr = attr(senators70_am$S99, "senators")) # Very short runs for illustration; in practice use many more iterations # (e.g. iters = 30000, burn.in = 10000) and the default auxiliary length. # Binary STERGM of the interactions (ties of either sign) fit_x <- bstergm(~ edges + nodematch("Party"), data = senate, iters = 100, burn.in = 50, aux.iters = 1000, seed = 1, verbose = FALSE) summary(fit_x) # Sign process given the interactions fit_z <- bstergm_sign(~ edges + nodematch("Party") + gwesf_pos(0.6) + gwese_pos(0.6), data = senate, iters = 100, burn.in = 50, aux.iters = 1000, seed = 1, verbose = FALSE) summary(fit_z)
Posterior means of a bstergm fit
## S3 method for class 'bstergm' coef(object, ...)## S3 method for class 'bstergm' coef(object, ...)
object |
a |
... |
unused. |
A list of named vectors of posterior means, one per component.
Tuning parameters for bstergm
control.bstergm( aux.iters = NULL, aux.visits = 3, aux.min = 500, MCMC.prop = ~., MCMC.prop.weights = "default", MCMC.prop.args = list(), translate = TRUE, adapt.start = 100, adapt.interval = 50, adapt.stop = Inf, adapt.scale = NULL, adapt.eps = 1e-06, proposal.sd = NULL, ads.gamma = 0.5, ads.var = 0.025, init.jitter = 0.5, ads.init.iters = 1000, ads.init.chains = NULL, print.every = 1000 )control.bstergm( aux.iters = NULL, aux.visits = 3, aux.min = 500, MCMC.prop = ~., MCMC.prop.weights = "default", MCMC.prop.args = list(), translate = TRUE, adapt.start = 100, adapt.interval = 50, adapt.stop = Inf, adapt.scale = NULL, adapt.eps = 1e-06, proposal.sd = NULL, ads.gamma = 0.5, ads.var = 0.025, init.jitter = 0.5, ads.init.iters = 1000, ads.init.chains = NULL, print.every = 1000 )
aux.iters |
number of Metropolis-Hastings steps of each auxiliary
network simulation. If |
aux.visits, aux.min
|
see |
MCMC.prop, MCMC.prop.weights, MCMC.prop.args
|
proposal of the auxiliary
simulations, passed to |
translate |
if |
adapt.start, adapt.interval, adapt.stop
|
adaptive Metropolis-Hastings:
the proposal covariance is updated every |
adapt.scale |
scaling of the empirical covariance; |
adapt.eps |
small constant added to the diagonal of the empirical covariance. |
proposal.sd |
initial proposal standard deviation(s) of adaptive
Metropolis-Hastings. If |
ads.gamma |
move factor of adaptive direction sampling. |
ads.var |
variance of the Gaussian noise added to adaptive direction sampling proposals. |
init.jitter |
scale of the random perturbation of the starting values:
chains start at the pseudo-likelihood estimate plus |
ads.init.iters, ads.init.chains
|
length and population size (default
|
print.every |
report progress every so many iterations when |
A list of class control.bstergm.
For each value in d, the number of nodes with exactly that
many negative ties.
# binary: degree_neg(d)# binary: degree_neg(d)
d |
a vector of non-negative integers. |
For each value in d, the number of dyads of sign base that
have exactly that many shared partners whose legs match path. Useful
mainly for goodness-of-fit checks.
# binary: esp_signed(d, base = "+", path = "++")# binary: esp_signed(d, base = "+", path = "++")
d |
a vector of non-negative integers. |
base, path
|
as in gwesp_signed. |
The geometrically weighted degree statistic computed on the
negative ties (active dyads that are not positive),
, where
is the number of negative ties of node . For the
positive ties use the ordinary gwdegree(decay, fixed = TRUE).
# binary: gwdegree_neg(decay)# binary: gwdegree_neg(decay)
decay |
the decay parameter (required). |
degree_neg, as_signed_network()
: negative ties weighted by their number of
shared enemies (both legs negative), i.e. the triad, which
is balanced under weak balance theory. Equivalent to
gwesp_signed(decay, base = "-", path = "--").
# binary: gwese_neg(decay)# binary: gwese_neg(decay)
decay |
the decay parameter (required). |
gwesp_signed, as_signed_network()
: positive ties weighted by their number of
shared enemies (both legs negative), i.e. the balanced
triad viewed from its positive tie. Equivalent to
gwesp_signed(decay, base = "+", path = "--") and
to gwespL(decay, fixed = TRUE, L.base = ~positive, Ls.path = list(~active & !positive, ~active & !positive)) in the
multilayer representation.
# binary: gwese_pos(decay)# binary: gwese_pos(decay)
decay |
the decay parameter (required). |
gwesp_signed, as_signed_network()
: negative ties weighted by their number of
shared friends (both legs positive), i.e. the unbalanced
triad viewed from its negative tie. Equivalent to
gwesp_signed(decay, base = "-", path = "++").
# binary: gwesf_neg(decay)# binary: gwesf_neg(decay)
decay |
the decay parameter (required). |
gwesp_signed, as_signed_network()
: positive ties weighted by their number of
shared friends (both legs positive). This is the balanced
triad viewed from a positive tie, and equals
gwesp(decay, fixed = TRUE) on the positive ties. Equivalent to
gwesp_signed(decay, base = "+", path = "++").
# binary: gwesf_pos(decay)# binary: gwesf_pos(decay)
decay |
the decay parameter (required). |
gwesp_signed, as_signed_network()
Geometrically weighted edgewise shared partner statistic of a
signed network, in which the base dyads have sign base and only shared
partners whose two legs have the signs given by path are counted.
For a base dyad let be the number of nodes
such that the signs of and match
path. The statistic is
It is evaluated on a signed network built by as_signed_network(): the
ties of the network are the positive ties and the network attribute
.active holds the interacting dyads, so that negative ties are active
dyads that are not ties. The terms are implemented in C and are much
faster than the equivalent multilayer
gwespL terms of ergm.multi.
# binary: gwesp_signed(decay, base = "+", path = "++")# binary: gwesp_signed(decay, base = "+", path = "++")
decay |
the decay parameter |
base |
sign of the base dyads, |
path |
signs of the two legs of a shared partner path: |
The special cases used by Caimo and Gollini are available as
gwesf_pos (),
gwesf_neg (),
gwese_pos () and
gwese_neg ().
The statistic gwesp_signed(decay, "+", "++") is identical to the
ordinary gwesp(decay, fixed = TRUE) on the positive ties.
as_signed_network(), esp_signed,
triangle_signed
data(senators70_am) nw <- as_signed_network(senators70_am$S99) # The four balance-related statistics of Caimo and Gollini, and a mixed one summary(nw ~ gwesf_pos(0.6) + gwese_pos(0.6) + gwesf_neg(0.6) + gwese_neg(0.6) + gwesp_signed(0.6, base = "+", path = "+-")) # Simulate signs on the observed interactions sim <- simulate(nw ~ edges + gwesf_pos(0.6) + gwese_neg(0.6), coef = c(-1, 0.3, -0.1), constraints = ~active_signs, seed = 1) table(signed_adjacency(sim)[upper.tri(diag(70))])data(senators70_am) nw <- as_signed_network(senators70_am$S99) # The four balance-related statistics of Caimo and Gollini, and a mixed one summary(nw ~ gwesf_pos(0.6) + gwese_pos(0.6) + gwesf_neg(0.6) + gwese_neg(0.6) + gwesp_signed(0.6, base = "+", path = "+-")) # Simulate signs on the observed interactions sim <- simulate(nw ~ edges + gwesf_pos(0.6) + gwese_neg(0.6), coef = c(-1, 0.3, -0.1), constraints = ~active_signs, seed = 1) table(signed_adjacency(sim)[upper.tri(diag(70))])
Creates the data object used by bstergm(): a sequence of undirected
binary networks observed on the same set of nodes.
network_series(nets, vertex.attr = NULL)network_series(nets, vertex.attr = NULL)
nets |
a list of at least two undirected binary networks, given as
adjacency matrices or |
vertex.attr |
optional data frame (or named list) of vertex attributes,
one row per node; by default taken from the first network if it is a
|
An object of class c("network_series", "signed_series") with
all ties coded as 1.
data(senators70_am) # Interactions (ties of either sign) of the Senate data as binary networks nets <- lapply(senators70_am[1:3], function(m) abs(m)) network_series(nets, vertex.attr = attr(senators70_am$S99, "senators"))data(senators70_am) # Interactions (ties of either sign) of the Senate data as binary networks nets <- lapply(senators70_am[1:3], function(m) abs(m)) network_series(nets, vertex.attr = attr(senators70_am$S99, "senators"))
type = "model" shows, for each component, boxplots of the centred
cumulative differences of the model
statistics (standardised by their simulated standard deviation when
standardize = TRUE), which should be centred on the dashed zero line.
type = "monitor" shows the simulated monitored statistics summed over
transitions, with the observed values as black points.
## S3 method for class 'bgof_bstergm' plot( x, type = c("model", "monitor"), components = x$components, standardize = TRUE, ... )## S3 method for class 'bgof_bstergm' plot( x, type = c("model", "monitor"), components = x$components, standardize = TRUE, ... )
x |
a |
type |
|
components |
components to plot. |
standardize |
standardise the centred differences of the model statistics, so that they share one axis. |
... |
further graphical parameters passed to |
x, invisibly.
For each parameter, shows the posterior density, the trace of every chain and the autocorrelation function.
## S3 method for class 'bstergm' plot( x, components = x$components, which = c("density", "trace", "acf"), lag.max = 50, ask = length(components) > 1 && interactive(), ... )## S3 method for class 'bstergm' plot( x, components = x$components, which = c("density", "trace", "acf"), lag.max = 50, ask = length(components) > 1 && interactive(), ... )
x |
a |
components |
components to plot. |
which |
any of |
lag.max |
maximum lag of the autocorrelation plots. |
ask |
whether to ask before each new page (one page per component). |
... |
further graphical parameters passed to |
x, invisibly.
Simulates future networks from the posterior
predictive distribution of a fitted separable model. For binary networks
(a bstergm() fit) each step simulates the formation and persistence
networks and assembles .
For signed networks, a bstergm() fit of the interactions and a
bstergm_sign() fit of the signs are both needed: the interactions are
simulated first, then the signs of their formation and persistence
networks, and the next network is assembled as
where are the positive ties; all other interactions are negative.
## S3 method for class 'bstergm' predict( object, interaction = NULL, horizon = 1, nsim = 100, start = NULL, visits = 10, posterior = TRUE, seed = NULL, cores = getOption("Bstergm.cores", 1L), verbose = TRUE, ... ) ## S3 method for class 'bstergm_forecast' summary(object, probs = c(0.025, 0.975), ...)## S3 method for class 'bstergm' predict( object, interaction = NULL, horizon = 1, nsim = 100, start = NULL, visits = 10, posterior = TRUE, seed = NULL, cores = getOption("Bstergm.cores", 1L), verbose = TRUE, ... ) ## S3 method for class 'bstergm_forecast' summary(object, probs = c(0.025, 0.975), ...)
object |
a |
interaction |
for signed networks, the other fit: the two fits may be
given in either order. |
horizon |
number of future time points. |
nsim |
number of simulated trajectories. |
start |
the network to start from (a signed or binary adjacency
matrix, or anything accepted by |
visits |
length of each network simulation, in proposals per free dyad. |
posterior |
if |
seed |
random seed. |
cores |
number of processes. Each simulation has its own random number stream, so results do not depend on the number of cores. |
verbose |
print progress messages. |
... |
unused. |
probs |
quantiles reported by |
Unlike the auxiliary simulations of the sampler, which start at observed
networks, these simulations start at the previous network (new
interactions starting as negative), so they need to be longer; see
visits.
If the fits use a list of formulas (time-varying covariates), the
formula of the last transition is used for all forecasts. Lagged
covariates (edgecov("lag.active"), ...) refer to the previous simulated
network.
An object of class bstergm_forecast, a list with
sims |
a list of |
start |
the starting network; |
signed, horizon, nsim, times
|
the type of network, the settings and the labels of the forecast time points. |
summary() gives, for each forecast time point, the mean and 95% interval
of the numbers of ties (by sign) and of triangles (by sign composition).
simulate.bstergm() for posterior predictive replicates of the
observed transitions.
data(senators70_am) senate <- signed_series(senators70_am[1:3], vertex.attr = attr(senators70_am$S99, "senators")) # Very short runs for illustration only fx <- bstergm(~ edges + nodematch("Party"), senate, iters = 30, burn.in = 15, aux.iters = 500, seed = 1, verbose = FALSE) summary(predict(fx, horizon = 1, nsim = 2, visits = 3, seed = 2, verbose = FALSE)) fz <- bstergm_sign(~ edges + gwesf_pos(0.6) + gwese_neg(0.6), senate, iters = 30, burn.in = 15, aux.iters = 500, seed = 1, verbose = FALSE) fc <- predict(fz, fx, horizon = 1, nsim = 2, visits = 3, seed = 2, verbose = FALSE) summary(fc)data(senators70_am) senate <- signed_series(senators70_am[1:3], vertex.attr = attr(senators70_am$S99, "senators")) # Very short runs for illustration only fx <- bstergm(~ edges + nodematch("Party"), senate, iters = 30, burn.in = 15, aux.iters = 500, seed = 1, verbose = FALSE) summary(predict(fx, horizon = 1, nsim = 2, visits = 3, seed = 2, verbose = FALSE)) fz <- bstergm_sign(~ edges + gwesf_pos(0.6) + gwese_neg(0.6), senate, iters = 30, burn.in = 15, aux.iters = 500, seed = 1, verbose = FALSE) fc <- predict(fz, fx, horizon = 1, nsim = 2, visits = 3, seed = 2, verbose = FALSE) summary(fc)
Signed networks among the 70 senators who served continuously in the 99th (1985-1987), 100th (1987-1989), 101st (1989-1991) and 102nd (1991-1993) U.S. Congresses. Positive and negative ties were extracted from bill co-sponsorship with the stochastic degree sequence model backbone of Neal (2014, 2020): a positive tie means that two senators co-sponsored significantly more bills than expected, a negative tie significantly fewer.
senators70_amsenators70_am
A list of 4 signed adjacency matrices (S99, S100, S101,
S102), each 70 x 70 and symmetric with entries -1, 0 and 1. Each matrix
carries the attribute senators, a data frame with columns ID,
Senator (name), State and Party ("D" or "R"), which can be
passed as the vertex.attr argument of signed_series().
Neal, Z. P. (2020). A sign of the times? Weak and strong polarization in the U.S. Congress, 1973-2016. Social Networks, 60, 103-112. Data: https://figshare.com/articles/dataset/A_Sign_of_the_Times/8096429?file=20758701
Neal, Z. P. (2014). The backbone of bipartite projections: Inferring relationships from co-authorship, co-sponsorship, co-attendance and other co-behaviors. Social Networks, 39, 84-97.
data(senators70_am) sapply(senators70_am, function(m) c(positive = sum(m > 0) / 2, negative = sum(m < 0) / 2)) table(attr(senators70_am$S99, "senators")$Party)data(senators70_am) sapply(senators70_am, function(m) c(positive = sum(m > 0) / 2, negative = sum(m < 0) / 2)) table(attr(senators70_am$S99, "senators")$Party)
Returns the signed adjacency matrix (entries -1, 0, 1) of a signed network
in any of the forms accepted by as_signed_network().
signed_adjacency(y, sign.attr = "sign")signed_adjacency(y, sign.attr = "sign")
y |
a signed network: a square symmetric matrix with entries in
{-1, 0, 1}; an undirected network whose edges carry
the edge attribute |
sign.attr |
name of the edge attribute holding the signs when |
A square symmetric integer matrix.
Creates the data object used by bstergm_sign() (and bstergm()): a sequence of undirected
signed networks observed on the same set of nodes.
signed_series(nets, vertex.attr = NULL, sign.attr = "sign") ## S3 method for class 'signed_series' print(x, ...) ## S3 method for class 'signed_series' summary(object, ...) ## S3 method for class 'signed_series' plot( x, layout = NULL, vertex.col = NULL, edge.col = c(positive = "grey15", negative = "grey60"), ... )signed_series(nets, vertex.attr = NULL, sign.attr = "sign") ## S3 method for class 'signed_series' print(x, ...) ## S3 method for class 'signed_series' summary(object, ...) ## S3 method for class 'signed_series' plot( x, layout = NULL, vertex.col = NULL, edge.col = c(positive = "grey15", negative = "grey60"), ... )
nets |
a list of at least two signed networks, each given as a signed
adjacency matrix (entries -1, 0, 1), a |
vertex.attr |
optional data frame (or named list) of vertex attributes,
one row per node, made available to the model terms (e.g.
|
sign.attr |
name of the edge attribute holding the signs when the
networks are |
x |
a |
... |
unused. |
object |
a |
layout |
optional matrix of node coordinates; by default a common layout of the union of all interactions is used. |
vertex.col |
vertex colours, or the name of a vertex attribute to colour by (levels in alphabetical order get grey shades from dark to light). |
edge.col |
grey levels of positive (solid) and negative (dotted) ties. |
Each transition is decomposed, for both the
interaction layer () and the sign layer
( if ), into
, ;
, .
These networks are returned by transition_networks().
An object of class signed_series: a list with the signed
adjacency matrices y, the number of nodes n, the time labels times
and the vertex attributes vertex.attr.
summary() returns a list with tables of tie counts by time point,
tie counts of the formation and persistence networks of each transition,
and the signed triad census by time point.
bstergm_sign(), bstergm(), transition_networks()
data(senators70_am) senate <- signed_series(senators70_am[1:3], vertex.attr = attr(senators70_am$S99, "senators")) senate summary(senate)data(senators70_am) senate <- signed_series(senators70_am[1:3], vertex.attr = attr(senators70_am$S99, "senators")) senate summary(senate)
Counts the triangles of a signed network by their number of positive ties. Under structural balance theory, triangles with three or one positive ties are balanced; under weak balance, all-negative triangles are balanced too.
signed_triad_census(y, sign.attr = "sign")signed_triad_census(y, sign.attr = "sign")
y |
a signed network: a square symmetric matrix with entries in
{-1, 0, 1}; an undirected network whose edges carry
the edge attribute |
sign.attr |
name of the edge attribute holding the signs when |
A named integer vector with the counts of "+++", "++-",
"+--" and "---" triangles.
data(senators70_am) sapply(senators70_am, signed_triad_census)data(senators70_am) sapply(senators70_am, signed_triad_census)
Simulates the formation and persistence networks of every transition of a sequence of signed networks for given parameter values and returns their statistics. Each simulation starts at the observed formation or persistence network.
simulate_stats( formula, data, coef_F = NULL, coef_P = NULL, process = c("sign", "interaction"), nsim = 1, aux.iters = NULL, control = control.bstergm(), seed = NULL, ... )simulate_stats( formula, data, coef_F = NULL, coef_P = NULL, process = c("sign", "interaction"), nsim = 1, aux.iters = NULL, control = control.bstergm(), seed = NULL, ... )
formula |
a one-sided ergm formula (see |
data |
a |
coef_F, coef_P
|
parameters of the formation and persistence models
(excluding statistics that are constant on the sample space, such as the
|
process |
|
nsim |
number of simulations. |
aux.iters |
number of Metropolis-Hastings steps of each simulation (see
|
control |
a |
seed |
random seed. |
... |
arguments of version 0.1 of this function: |
A list with elements sz._F and sz._P: matrices (statistics x
transitions) for nsim = 1, or arrays (simulations x statistics x
transitions) otherwise. Constant statistics are included.
data(senators70_am) senate <- signed_series(senators70_am[1:3]) simulate_stats(~ edges + gwesf_pos(0.6) + gwese_pos(0.6), senate, coef_F = c(-2, 0.5, -0.2), coef_P = c(-2, 0.5, -0.2), seed = 1)data(senators70_am) senate <- signed_series(senators70_am[1:3]) simulate_stats(~ edges + gwesf_pos(0.6) + gwese_pos(0.6), senate, coef_F = c(-2, 0.5, -0.2), coef_P = c(-2, 0.5, -0.2), seed = 1)
Posterior predictive simulation of the formation and persistence networks
of every observed transition, given the observed interactions (sign
process) or the observed previous networks (interaction process), together
with the implied networks at each time point,
.
## S3 method for class 'bstergm' simulate( object, nsim = 1, seed = NULL, coef = NULL, output = c("networks", "stats"), aux.iters = NULL, cores = getOption("Bstergm.cores", 1L), ... )## S3 method for class 'bstergm' simulate( object, nsim = 1, seed = NULL, coef = NULL, output = c("networks", "stats"), aux.iters = NULL, cores = getOption("Bstergm.cores", 1L), ... )
object |
a |
nsim |
number of simulations. |
seed |
random seed. |
coef |
optional parameter values (free parameters, as in
|
output |
|
aux.iters |
number of Metropolis-Hastings steps of each simulation; by default five times the number used for fitting. |
cores |
number of processes. Each simulation has its own random number stream, so results do not depend on the number of cores. |
... |
unused. |
For the sign process, the simulated positive ties at time are
, and all
other interactions of are negative.
For output = "stats", a list with, for each component, an array
of statistics (simulations x statistics x transitions). For output = "networks", a list of nsim simulations, each a list with the simulated
formation (F) and persistence (P) networks of every transition and,
when both components were fitted, the implied networks y at times
.
data(senators70_am) senate <- signed_series(senators70_am[1:3], vertex.attr = attr(senators70_am$S99, "senators")) fit <- bstergm_sign(~ edges + nodematch("Party") + gwesf_pos(0.6) + gwese_pos(0.6), data = senate, iters = 100, burn.in = 50, aux.iters = 1000, seed = 1, verbose = FALSE) sims <- simulate(fit, nsim = 2, seed = 3) sapply(sims[[1]]$y, signed_triad_census)data(senators70_am) senate <- signed_series(senators70_am[1:3], vertex.attr = attr(senators70_am$S99, "senators")) fit <- bstergm_sign(~ edges + nodematch("Party") + gwesf_pos(0.6) + gwese_pos(0.6), data = senate, iters = 100, burn.in = 50, aux.iters = 1000, seed = 1, verbose = FALSE) sims <- simulate(fit, nsim = 2, seed = 3) sapply(sims[[1]]$y, signed_triad_census)
Posterior summaries of each fitted component: mean, standard deviation, naive and time-series standard errors of the mean, quantiles, effective sample size and, with several chains, the potential scale reduction factor of Gelman and Rubin.
## S3 method for class 'bstergm' summary(object, probs = c(0.025, 0.5, 0.975), ...)## S3 method for class 'bstergm' summary(object, probs = c(0.025, 0.5, 0.975), ...)
object |
a |
probs |
quantiles to report. |
... |
unused. |
An object of class summary.bstergm: a list with one table per
component plus the acceptance rates.
Formation and persistence networks of each transition
transition_networks(data)transition_networks(data)
data |
a |
A list with components F and P, each a list of signed adjacency
matrices (one per transition), and prev, the signed adjacency matrices
of the previous time points.
Number of triangles (three mutually active dyads) by sign
composition. Under structural balance theory "+++" and "+--" are
balanced, "++-" is unbalanced and "---" is balanced only under weak
balance. Because the active dyads are fixed, the four counts sum to a
constant, so at most three of them can enter a model together.
# binary: triangle_signed(type = c("+++", "++-", "+--", "---"))# binary: triangle_signed(type = c("+++", "++-", "+--", "---"))
type |
a character vector of sign patterns; the order of the signs within a pattern is irrelevant. |
gwesp_signed, signed_triad_census()