Description Usage Arguments Value Methods (by generic) Notes on model specification References See Also Examples
ergm
is used to fit exponentialfamily random graph
models (ERGMs), in which
the probability of a given network, y, on a set of nodes is
h(y) \exp\{η(θ) \cdot
g(y)\}/c(θ), where
h(y) is the reference measure (usually h(y)=1),
g(y) is a vector of network statistics for y,
η(θ) is a natural parameter vector of the same
length (with η(θ)=θ for most terms), and c(θ) is the
normalizing constant for the distribution.
ergm
can return a maximum pseudolikelihood
estimate, an approximate maximum likelihood estimate based on a Monte
Carlo scheme, or an approximate contrastive divergence estimate based
on a similar scheme.
(For an overview of the package, see ergmpackage
.)
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  ergm(
formula,
response = NULL,
reference = ~Bernoulli,
constraints = ~.,
offset.coef = NULL,
target.stats = NULL,
eval.loglik = getOption("ergm.eval.loglik"),
estimate = c("MLE", "MPLE", "CD"),
control = control.ergm(),
verbose = FALSE,
...,
basis = ergm.getnetwork(formula)
)
is.ergm(object)
## S3 method for class 'ergm'
nobs(object, ...)
## S3 method for class 'ergm'
print(x, digits = max(3, getOption("digits")  3), ...)
## S3 method for class 'ergm'
coef(object, ...)
## S3 method for class 'ergm'
coefficients(object, ...)
## S3 method for class 'ergm'
vcov(object, sources = c("all", "model", "estimation"), ...)

formula 
An R 
response 
Name of the edge attribute whose value is to be
modeled in the valued ERGM framework. Defaults to 
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 formula specifying one or more constraints
on the support of the distribution of the networks being modeled,
using syntax similar to the It is also possible to specify a proposal function directly
either by passing a string with the function's name (in which case,
arguments to the proposal should be specified through the
The default is See the ERGM constraints documentation for the constraints implemented in the ergm package. Other packages may add their own constraints. Note that not all possible combinations of constraints and reference measures are supported. However, for relatively simple constraints (i.e., those that simply permit or forbid specific dyads or sets of dyads from changing), arbitrary combinations should be possible. 
offset.coef 
A vector of coefficients for the offset terms. 
target.stats 
vector of "observed network statistics,"
if these statistics are for some reason different than the
actual statistics of the network on the lefthand side of

eval.loglik 
Logical: For dyaddependent models, if TRUE, use bridge
sampling to evaluate the loglikelihoood associated with the
fit. Has no effect for dyadindependent models.
Since bridge sampling takes additional time, setting to FALSE may
speed performance if likelihood values (and likelihoodbased
values like AIC and BIC) are not needed. Can be set globally via 
estimate 
If "MPLE," then the maximum pseudolikelihood estimator
is returned. If "MLE" (the default), then an approximate maximum likelihood
estimator is returned. For certain models, the MPLE and MLE are equivalent,
in which case this argument is ignored. (To force MCMCbased approximate
likelihood calculation even when the MLE and MPLE are the same, see the

control 
A list of control parameters for algorithm
tuning. Constructed using 
verbose 
A 
... 
Additional arguments, to be passed to lowerlevel functions. 
basis 
a value (usually a 
object 
an 
x, digits 
See Automatically called when an object of class 
sources 
For the 
ergm
returns an object of class ergm
that is a list
consisting of the following elements:
coef 
The Monte Carlo maximum likelihood estimate of θ, the vector of coefficients for the model parameters. 
sample 
The n\times p matrix of network statistics,
where n is the
sample size and p is the number of network statistics specified in the
model, generated by the last iteration of the MCMCbased likelihood maximization routine. These statistics are centered with respect to the observed statistics or 
sample.obs 
As 
iterations 
The number of NewtonRaphson iterations required before convergence. 
MCMCtheta 
The value of θ used to produce the Markov chain
Monte Carlo sample. As long as the Markov chain mixes sufficiently
well, 
loglikelihood 
The approximate change in loglikelihood in the last iteration. The value is only approximate because it is estimated based on the MCMC random sample. 
gradient 
The value of the gradient vector of the approximated loglikelihood function, evaluated at the maximizer. This vector should be very close to zero. 
covar 
Approximate covariance matrix for the MLE, based on the inverse Hessian of the approximated loglikelihood evaluated at the maximizer. 
failure 
Logical: Did the MCMC estimation fail? 
network 
Network passed on the lefthand side of 
newnetworks 
A list of the final networks at the end of the MCMC simulation, one for each thread. 
newnetwork 
The first (possibly only) element of 
coef.init 
The initial value of θ. 
est.cov 
The covariance matrix of the model statistics in the final MCMC sample. 
coef.hist, steplen.hist, stats.hist, stats.obs.hist 
For the MCMLE method, the history of coefficients, Hummel step lengths, and average model statistics for each iteration.. 
control 
The control list passed to the call. 
etamap 
The set of functions mapping the true parameter theta to the canonical parameter eta (irrelevant except in a curved exponential family model) 
formula 
The original 
target.stats 
The target.stats used during estimation (passed through from the Arguments) 
target.esteq 
Used for curved models to preserve the target mean values of the curved terms. It is identical to target.stats for noncurved models. 
constrained 
The list of constraints implied by the constraints used by original 
constraints 
Constraints used during estimation (passed through from the Arguments) 
reference 
The reference measure used during estimation (passed through from the Arguments) 
estimate 
The estimation method used (passed through from the Arguments). 
offset 
vector of logical telling which model parameters are to be set at a fixed value (i.e., not estimated). 
drop 
If

estimable 
A logical vector indicating which terms could not be
estimated due to a 
null.lik 
Loglikelihood of the null model. Valid only for unconstrained models. 
mle.lik 
The approximate loglikelihood for the MLE. The value is only approximate because it is estimated based on the MCMC random sample. 
nobs
: Return the number of informative dyads of a model fit.
print
:
coef
: extracts estimated model coefficients.
coefficients
: An alias for
ergm
.
vcov
: extracts the variancecovariance matrix of
parameter estimates.
Although each of the statistics in a given model is a summary statistic for the entire network, it is rarely necessary to calculate statistics for an entire network in a proposed MetropolisHastings step. Thus, for example, if the triangle term is included in the model, a census of all triangles in the observed network is never taken; instead, only the change in the number of triangles is recorded for each edge toggle.
In the implementation of ergm
, the model is initialized
in R, then all the model information is passed to a C program
that generates the sample of network statistics using MCMC.
This sample is then returned to R, which implements a
simple NewtonRaphson algorithm to approximate the MLE.
An alternative style of maximum likelihood estimation is to use a stochastic
approximation algorithm. This can be chosen with the
control.ergm(style="RobbinsMonro")
option.
The mechanism for proposing new networks for the MCMC sampling
scheme, which is a MetropolisHastings algorithm, depends on
two things: The constraints
, which define the set of possible
networks that could be proposed in a particular Markov chain step,
and the weights placed on these possible steps by the
proposal distribution. The former may be controlled using the
constraints
argument described above. The latter may
be controlled using the prop.weights
argument to the
control.ergm
function.
The package is designed so that the user could conceivably add additional proposal types.
Admiraal R, Handcock MS (2007). networksis: Simulate bipartite graphs with fixed marginals through sequential importance sampling. Statnet Project, Seattle, WA. Version 1. https://statnet.org.
BenderdeMoll S, Morris M, Moody J (2008). Prototype Packages for Managing and Animating Longitudinal Network Data: dynamicnetwork and rSoNIA. Journal of Statistical Software, 24(7). https://www.jstatsoft.org/v24/i07/.
Butts CT (2007). sna: Tools for Social Network Analysis. R package version 2.32. https://cran.rproject.org/package=sna.
Butts CT (2008). network: A Package for Managing Relational Data in R. Journal of Statistical Software, 24(2). https://www.jstatsoft.org/v24/i02/.
Butts C (2015). network: The Statnet Project (https://statnet.org). R package version 1.12.0, https://cran.rproject.org/package=network.
Goodreau SM, Handcock MS, Hunter DR, Butts CT, Morris M (2008a). A statnet Tutorial. Journal of Statistical Software, 24(8). https://www.jstatsoft.org/v24/i08/.
Goodreau SM, Kitts J, Morris M (2008b). Birds of a Feather, or Friend of a Friend? Using Exponential Random Graph Models to Investigate Adolescent Social Networks. Demography, 45, in press.
Handcock, M. S. (2003) Assessing Degeneracy in Statistical Models of Social Networks, Working Paper \#39, Center for Statistics and the Social Sciences, University of Washington. https://www.csss.washington.edu/research/workingpapers/assessingdegeneracystatisticalmodelssocialnetworks
Handcock MS (2003b). degreenet: Models for Skewed Count Distributions Relevant to Networks. Statnet Project, Seattle, WA. Version 1.0, https://statnet.org.
Handcock MS and Gile KJ (2010). Modeling Social Networks from Sampled Data. Annals of Applied Statistics, 4(1), 525. doi: 10.1214/08AOAS221
Handcock MS, Hunter DR, Butts CT, Goodreau SM, Morris M (2003a). ergm: A Package to Fit, Simulate and Diagnose ExponentialFamily Models for Networks. Statnet Project, Seattle, WA. Version 2, https://statnet.org.
Handcock MS, Hunter DR, Butts CT, Goodreau SM, Morris M (2003b). statnet: Software Tools for the Statistical Modeling of Network Data. Statnet Project, Seattle, WA. Version 2, https://statnet.org.
Hunter, D. R. and Handcock, M. S. (2006) Inference in curved exponential family models for networks, Journal of Computational and Graphical Statistics.
Hunter DR, Handcock MS, Butts CT, Goodreau SM, Morris M (2008b). ergm: A Package to Fit, Simulate and Diagnose ExponentialFamily Models for Networks. Journal of Statistical Software, 24(3). https://www.jstatsoft.org/v24/i03/.
Krivitsky PN (2012). ExponentialFamily Random Graph Models for Valued Networks. Electronic Journal of Statistics, 2012, 6, 11001128. doi: 10.1214/12EJS696
Morris M, Handcock MS, Hunter DR (2008). Specification of ExponentialFamily Random Graph Models: Terms and Computational Aspects. Journal of Statistical Software, 24(4). https://www.jstatsoft.org/v24/i04/.
Snijders, T.A.B. (2002), Markov Chain Monte Carlo Estimation of Exponential Random Graph Models. Journal of Social Structure. Available from https://www.cmu.edu/joss/content/articles/volume3/Snijders.pdf.
network
, %v%
, %n%
, ergmterms, ergmMPLE
,
summary.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  #
# load the Florentine marriage data matrix
#
data(flo)
#
# attach the sociomatrix for the Florentine marriage data
# This is not yet a network object.
#
flo
#
# Create a network object out of the adjacency matrix
#
flomarriage < network(flo,directed=FALSE)
flomarriage
#
# print out the sociomatrix for the Florentine marriage data
#
flomarriage[,]
#
# create a vector indicating the wealth of each family (in thousands of lira)
# and add it as a covariate to the network object
#
flomarriage %v% "wealth" < c(10,36,27,146,55,44,20,8,42,103,48,49,10,48,32,3)
flomarriage
#
# create a plot of the social network
#
plot(flomarriage)
#
# now make the vertex size proportional to their wealth
#
plot(flomarriage, vertex.cex=flomarriage %v% "wealth" / 20, main="Marriage Ties")
#
# Use 'data(package = "ergm")' to list the data sets in a
#
data(package="ergm")
#
# Load a network object of the Florentine data
#
data(florentine)
#
# Fit a model where the propensity to form ties between
# families depends on the absolute difference in wealth
#
gest < ergm(flomarriage ~ edges + absdiff("wealth"))
summary(gest)
#
# add terms for the propensity to form 2stars and triangles
# of families
#
gest < ergm(flomarriage ~ kstar(1:2) + absdiff("wealth") + triangle)
summary(gest)
# import synthetic network that looks like a molecule
data(molecule)
# Add a attribute to it to mimic the atomic type
molecule %v% "atomic type" < c(1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,3)
#
# create a plot of the social network
# colored by atomic type
#
plot(molecule, vertex.col="atomic type",vertex.cex=3)
# measure tendency to match within each atomic type
gest < ergm(molecule ~ edges + kstar(2) + triangle + nodematch("atomic type"),
control=control.ergm(MCMC.samplesize=10000))
summary(gest)
# compare it to differential homophily by atomic type
gest < ergm(molecule ~ edges + kstar(2) + triangle
+ nodematch("atomic type",diff=TRUE),
control=control.ergm(MCMC.samplesize=10000))
summary(gest)
# Extract parameter estimates as a numeric vector:
coef(gest)
# Sources of variation in parameter estimates:
vcov(gest, sources="model")
vcov(gest, sources="estimation")
vcov(gest, sources="all") # the default

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