Skip to contents

Generates network replicates at fitted periods from aligned posterior trajectories. A fit that did not save them, and the trajectory scenarios of start_from and an extended n_time, use the conditional approximation by asking for it with type = "approximate"; see Details.

Usage

# S3 method for class 'lame'
simulate(
  object,
  nsim = 100,
  seed = NULL,
  newdata = NULL,
  n_time = NULL,
  burn_in = 0,
  thin = 1,
  return_latent = FALSE,
  start_from = "posterior",
  type = c("posterior", "approximate"),
  ...
)

Arguments

object

fitted model object of class "lame"

nsim

number of network trajectories to simulate (default: 100)

seed

Optional random seed. An explicit seed is local to this call: the caller's RNG state is restored on return or error. With NULL, the caller's current RNG stream advances normally.

newdata

optional list containing new covariate data:

Xdyad

list of T dyadic covariate arrays (n x n x p or nA x nB x p)

Xrow

list of T row/sender covariate matrices (n x p or nA x p)

Xcol

list of T column/receiver covariate matrices (n x p or nB x p)

If NULL, uses covariates from original model fit

n_time

number of time periods to simulate. If NULL, uses same as original data

burn_in

number of initial MCMC samples to discard (default: 0)

thin

thinning interval for MCMC samples (default: 1, use every sample)

return_latent

logical: return latent Z matrices in addition to Y? (default: FALSE)

start_from

character: how to initialize the simulation

"posterior"

use saved trajectories for joint replication; posterior summaries for the approximation (default)

"random"

random initialization

"data"

use first time point from original data

type

simulation route: "posterior" (default) replicates the network from aligned saved posterior trajectories; "approximate" is the conditional approximation. See Details.

...

additional arguments (not currently used)

Value

A list with components:

Y

list of nsim simulated longitudinal network trajectories, each element is a list of T networks

method

joint posterior or conditional approximation

draw_index

sampled coefficient-row indices for joint replication

Z

if return_latent=TRUE, list of nsim latent Z trajectories

family

the family of the model (binary, normal, etc.)

mode

network mode (unipartite or bipartite)

n_time

number of time periods

Details

With type = "posterior", every replicate uses the same saved MCMC iteration for coefficients, actor effects, positions, coupling and observation variance and period-specific reciprocity. Saved blocks may be thinned differently when their iteration indices are available; only shared iterations are sampled. Missing joint storage is an error (class lame_simulate_draws) that names type = "approximate". Store effects and positions with posterior_options(save_ab = TRUE, save_UV = TRUE, thin_ab = 1, thin_UV = 1) when fitting.

type = "approximate" is the conditional approximation: it substitutes posterior summaries for the latent trajectories and does not propagate their joint posterior uncertainty. It runs only when requested. The returned method identifies the route.

Joint longitudinal replication uses saved trajectories at fitted periods; it does not evolve the final state through the historical covariates. Use predict(fit, h = ...) for future periods. The start_from and extended n_time options apply to the conditional approximation only; with type = "posterior" they are an error (class lame_simulate_periods). The approximation extends n_time past the fitted periods only for static coefficients; a dynamic_beta fit has coefficients for its fitted periods alone, so a longer n_time is the same error. In the approximation, newdata$Xdyad must be a list with one array per period; any other shape is an error (class lame_simulate_xlist). Ordinal fits with explicit cutpoints use the corresponding saved cutpoint draw. Data-induced ordinal fits match the observed category frequencies, so these replications assess dependence conditional on those frequencies.

Author

Shahryar Minhas

Examples

# \donttest{
# Create simple longitudinal network data
set.seed(1)
n <- 10
nms <- paste0("n", 1:n)
Y_list <- list(
  matrix(rnorm(n * n), n, n, dimnames = list(nms, nms)),
  matrix(rnorm(n * n), n, n, dimnames = list(nms, nms))
)
diag(Y_list[[1]]) <- diag(Y_list[[2]]) <- NA
# chains = 1 keeps the example short; the default runs two chains and compares them
fit <- lame(Y_list, family = "normal", R = 1,
            nscan = 50, burn = 10, odens = 1, verbose = FALSE, plot = FALSE,
            posterior_opts = posterior_options(save_ab = TRUE, save_UV = TRUE), chains = 1)

# Simulate 10 network trajectories from posterior
sims <- simulate(fit, nsim = 10)
# }