Description Usage Arguments Details Value Functions Note See Also Examples
simulate
is used to draw from exponential
family random network models. See ergm
for more
information on these models.
The method for ergm
objects inherits the model,
the coefficients, the response attribute, the reference, the
constraints, and most simulation parameters from the model fit,
unless overridden by passing them explicitly. Unless overridden,
the simulation is initialized with a random draw from the fitted
model, saved by ergm()
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112  ## S3 method for class 'formula_lhs_network'
simulate(object, nsim = 1, seed = NULL, ...)
simulate_formula(object, ..., basis = eval_lhs.formula(object))
## S3 method for class 'network'
simulate_formula(
object,
nsim = 1,
seed = NULL,
coef,
response = NULL,
reference = ~Bernoulli,
constraints = ~.,
observational = FALSE,
monitor = NULL,
statsonly = FALSE,
esteq = FALSE,
output = c("network", "stats", "edgelist", "ergm_state"),
simplify = TRUE,
sequential = TRUE,
control = control.simulate.formula(),
verbose = FALSE,
...,
basis = ergm.getnetwork(object),
do.sim = TRUE,
return.args = NULL
)
## S3 method for class 'ergm_state'
simulate_formula(
object,
nsim = 1,
seed = NULL,
coef,
response = NULL,
reference = ~Bernoulli,
constraints = ~.,
observational = FALSE,
monitor = NULL,
statsonly = FALSE,
esteq = FALSE,
output = c("network", "stats", "edgelist", "ergm_state"),
simplify = TRUE,
sequential = TRUE,
control = control.simulate.formula(),
verbose = FALSE,
...,
basis = ergm.getnetwork(object),
do.sim = TRUE,
return.args = NULL
)
## S3 method for class 'ergm_model'
simulate(
object,
nsim = 1,
seed = NULL,
coef,
reference = if (is(constraints, "ergm_proposal")) NULL else trim_env(~Bernoulli),
constraints = trim_env(~.),
observational = FALSE,
monitor = NULL,
basis = NULL,
esteq = FALSE,
output = c("network", "stats", "edgelist", "ergm_state"),
simplify = TRUE,
sequential = TRUE,
control = control.simulate.formula(),
verbose = FALSE,
...,
do.sim = TRUE,
return.args = NULL
)
## S3 method for class 'ergm_state_full'
simulate(
object,
nsim = 1,
seed = NULL,
coef,
esteq = FALSE,
output = c("network", "stats", "edgelist", "ergm_state"),
simplify = TRUE,
sequential = TRUE,
control = control.simulate.formula(),
verbose = FALSE,
...,
return.args = NULL
)
## S3 method for class 'ergm'
simulate(
object,
nsim = 1,
seed = NULL,
coef = coefficients(object),
response = object$network %ergmlhs% "response",
reference = object$reference,
constraints = list(object$constraints, object$obs.constraints),
observational = FALSE,
monitor = NULL,
basis = object$newnetwork,
statsonly = FALSE,
esteq = FALSE,
output = c("network", "stats", "edgelist", "ergm_state"),
simplify = TRUE,
sequential = TRUE,
control = control.simulate.ergm(),
verbose = FALSE,
...
)

object 
Either a 
nsim 
Number of networks to be randomly drawn from the given distribution on the set of all networks, returned by the MetropolisHastings algorithm. 
seed 
Seed value (integer) for the random number generator. See

... 
Further arguments passed to or used by methods. 
basis 
a value (usually a 
coef 
Vector of parameter values for the model from which the
sample is to be drawn. If 
response 
Either a character string, a formula, or

reference 
A onesided formula specifying the reference measure (h(y)) to be used. See help for ERGM reference measures implemented in the ergm package. 
constraints 
A onesided formula specifying one or more
constraints on the support of the distribution of the networks
being simulated. See the documentation for a similar argument for

observational 
Inherit observational constraints rather than model constraints. 
monitor 
A onesided formula specifying one or more terms
whose value is to be monitored. These terms are appeneded to the
model, along with a coefficient of 0, so their statistics are
returned. An 
statsonly 
Logical: If TRUE, return only the network statistics, not
the network(s) themselves. Deprecated in favor of 
esteq 
Logical: If TRUE, compute the sample estimating equations of an ERGM: if the model is noncurved, all nonoffset statistics are returned either way, but if the model is curved, the score estimating function values (3.1) by Hunter and Handcock (2006) are returned instead. 
output 
Normally character, one of Alternatively, a function with prototype

simplify 
Logical: If 
sequential 
Logical: If FALSE, each of the 
control 
A list of control parameters for algorithm tuning,
typically constructed with 
verbose 
A logical or an integer to control the amount of
progress and diagnostic information to be printed. 
do.sim 
Logical; a deprecated interface superseded by 
return.args 
Character; if not 
A sample of networks is randomly drawn from the specified model. The model
is specified by the first argument of the function. If the first argument
is a formula
then this defines the model. If the first
argument is the output of a call to ergm
then the model used
for that call is the one fit – and unless coef
is specified, the
sample is from the MLE of the parameters. If neither of those are given as
the first argument then a Bernoulli network is generated with the
probability of ties defined by prob
or coef
.
Note that the first network is sampled after burnin
steps,
and any subsequent networks are sampled each interval
steps
after the first.
More information can be found by looking at the documentation of
ergm
.
If output=="stats"
an mcmc
object containing the
simulated network statistics. If control$parallel>0
, an
mcmc.list
object. If simplify=TRUE
(the default), these
would then be "stacked" and converted to a standard matrix
. A
logical vector indicating whether or not the term had come from
the monitor=
formula is stored in attr()
style attribute
"monitored"
.
Otherwise, a representation of the simulated network is returned,
in the form specified by output
. In addition to a network
representation or a list thereof, they have the following
attr
style attributes:
formula
The formula
used to generate the
sample.
stats
An mcmc
or mcmc.list
object as above.
control
Control parameters used to generate the sample.
constraints
Constraints used to generate the sample.
reference
The reference measure for the sample.
monitor
The monitoring formula.
response
The edge attribute used as a response.
The following are the permitted network formats:
"network"
If nsim==1
, an object of class
network
. If nsim>1
, it returns an object of class
network.list
(a list of networks) with the
abovelisted additional attributes.
"edgelist"
An edgelist
representation of the network,
or a list thereof, depending on nsim
.
"ergm_state"
A semiinternal representation of
a network consisting of a network
object emptied of edges, with
an attached edgelist matrix, or a list thereof, depending on
nsim
.
If simplify==FALSE
, the networks are returned as a nested list,
with outer list being the parallel chain (including 1 for no
parallelism) and inner list being the samples within that chains
(including 1, if one network per chain). If TRUE
, they are
concatenated, and if a total of one network had been simulated, the
network itself will be returned.
simulate.ergm_state_full
: a lowlevel function to simulate from an ergm_state
object.
simulate.ergm_model()
is a lowerlevel interface, providing
a simulate()
method for ergm_model
class. The basis
argument is required; monitor
, if passed, must be an
ergm_model
as well; and constraints
can be an
ergm_proposal
object instead.
ergm
, network
,
ergm_MCMC_sample()
for a demonstration of return.args=
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59  #
# Let's draw from a Bernoulli model with 16 nodes
# and density 0.5 (i.e., coef = c(0,0))
#
g.sim < simulate(network(16) ~ edges + mutual, coef=c(0, 0))
#
# What are the statistics like?
#
summary(g.sim ~ edges + mutual)
#
# Now simulate a network with higher mutuality
#
g.sim < simulate(network(16) ~ edges + mutual, coef=c(0,2))
#
# How do the statistics look?
#
summary(g.sim ~ edges + mutual)
#
# Let's draw from a Bernoulli model with 16 nodes
# and tie probability 0.1
#
g.use < network(16,density=0.1,directed=FALSE)
#
# Starting from this network let's draw 3 realizations
# of a edges and 2star network
#
g.sim < simulate(~edges+kstar(2), nsim=3, coef=c(1.8,0.03),
basis=g.use, control=control.simulate(
MCMC.burnin=1000,
MCMC.interval=100))
g.sim
summary(g.sim)
#
# attach the Florentine Marriage data
#
data(florentine)
#
# fit an edges and 2star model using the ergm function
#
gest < ergm(flomarriage ~ edges + kstar(2))
summary(gest)
#
# Draw from the fitted model (statistics only), and observe the number
# of triangles as well.
#
g.sim < simulate(gest, nsim=10,
monitor=~triangles, output="stats",
control=control.simulate.ergm(MCMC.burnin=1000, MCMC.interval=100))
g.sim
# Custom output: store the edgecount (computed in R), iteration index, and chain index.
output.f < function(x, iter, chain, ...){
list(nedges = network.edgecount(as.network(x)),
chain = chain, iter = iter)
}
g.sim < simulate(gest, nsim=3,
output=output.f, simplify=FALSE,
control=control.simulate.ergm(MCMC.burnin=1000, MCMC.interval=100))
unclass(g.sim)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.