| Title: | User-specified Terms for the statnet Suite of Packages |
|---|---|
| Description: | A non-CRAN template package to demonstrate the use of user-specified statistics for use in 'ergm' models as part of the Statnet suite of packages. |
| Authors: | Mark S. Handcock [aut], David R. Hunter [aut], Carter T. Butts [aut], Steven M. Goodreau [aut], Pavel N. Krivitsky [aut, cre] (ORCID: <https://orcid.org/0000-0002-9101-3362>), Martina Morris [aut] |
| Maintainer: | Pavel N. Krivitsky <[email protected]> |
| License: | GPL-3 + file LICENSE |
| Version: | 4.0.0 |
| Built: | 2026-05-21 10:54:25 UTC |
| Source: | https://github.com/statnet/ergm.userterms |
This non-CRAN package contains template code for user defined (change) statistics that can be used with the statnet suite of packages (and ergm in particular). To use this package the statnet packages ergm and network are required.
As background, statnet is a suite of software packages for statistical
network analysis. The packages implement recent advances in network modeling
based on exponential-family random graph models (ERGM). The components of
the package provide a comprehensive framework for ERGM-based network
modeling: tools for model estimation, for model evaluation, for model-based
network simulation, and for network visualization. This broad functionality
is powered by a central Markov chain Monte Carlo (MCMC) algorithm. The
coding is optimized for speed and robustness. For detailed information on
how to download and install the software, go to the ergm
website: statnet.org. A tutorial, support newsgroup, references and
links to further resources are provided there.
We have invested a lot of time and effort in creating the statnet
suite of packages for use by other researchers. Please cite it in all papers
where it is used.
For complete citation information, usecitation(package="ergm").
The statnet
suite of packages allows the user to explore a large number of potential
models for their network data. These can be seen by typing
?ergmTerm (once the package ergm has
been installed). For more information on the models and terms see Morris,
Handcock, and Hunter (2008).
The purpose of the package is to allow additional terms can be coded up by users (you!) and be used at native speeds with statnet. So the suite of packages can be extended with minimal work by the user. In addition the core packages are not altered and so the new packages benefit from improvements to the core suite.
The process of creating new terms is explained in depth by the document entitled by Hunter, Goodreau, and Handcock (2013) that is found in the ‘inst/doc’ directory of this package. While that article is still valid, API changes in ergm 4.0 have simplified the term implementations and added new capabilities; see the Terms API vignette in ergm.
In brief, to add a new term you need to (all file references are relative to the package directory):
Download the source version of this package, currently hosted at https://github.com/statnet/ergm.userterms, e.g., https://github.com/statnet/ergm.userterms/archive/refs/heads/master.zip.
Unpack the source into a directory.
Optionally, rename the package name from ergm.userterms to some
something more evocative of its use (e.g., myergm). This can be done
using a global change to the files in the directory. Optionally, edit the
‘DESCRIPTION’ file to reflect the use of the package.
Edit ‘R/InitErgmTerm.users.R’ to add R InitErgmTerm
functions for the new terms.
Edit ‘src/changestats.users.c’ to add C functions (like the
example already in that file) to compute the new change statistics.
Compile the package using the usual R tools (e.g., R CMD build
myergm and R CMD INSTALL myergm).
Run it! It depends on ergm and network, of course. See the example below.
Maintainer: Pavel N. Krivitsky [email protected] (ORCID)
Authors:
Mark S. Handcock [email protected]
David R. Hunter [email protected]
Carter T. Butts [email protected]
Steven M. Goodreau [email protected]
Martina Morris [email protected]
Hunter DR, Goodreau SM, Handcock MS (2013). ergm.userterms: A
Template Package for Extending statnet, Journal of Statistical
Software 52(2), 1-25, doi:10.18637/jss.v052.i02.
ergm-package, network-package, ergmTerm
Explanation and instructions for updating custom ERGM terms developed prior
to the release of ergm version 3.1 (including
3.0–999 preview release) to be used with versions 3.1 or later.
ergm.userterms — Statnet's mechanism enabling users to write their own ERGM terms — comes in a form of an R package containing files for the user to put their own statistics into (i.e., ‘changestats.user.h’, ‘changestats.user.c’, and ‘InitErgmTerm.user.R’), as well as some boilerplate to support them (e.g., ‘ergm_edgetree.h’, ‘edgetree.c’, ‘ergm_changestat.h’, ‘changestat.c’, etc.).
Although the ergm.userterms API is stable, recent developments in ergm have necessitated the boilerplate files in ergm.userterms to be updated. To reiterate, the user-written statistic source code (‘changestats.user.h’, ‘changestats.user.c’, and ‘InitErgmTerm.user.R’) can be used without modification, but other files that came with the package need to be changed.
To make things easier in the future, we have implemented a mechanism (using R's LinkingTo API, in case you are wondering) that will keep things in sync in releases after the upcoming one. However, for the upcoming release, we need to transition to this new mechanism.
The transition entails the following steps. They only need to be done once for a package. Future releases will keep up to date automatically.
Download the up-to-date ergm.userterms source https://github.com/statnet/ergm.userterms, e.g., https://github.com/statnet/ergm.userterms/archive/refs/heads/master.zip and unpack it.
Copy the R and C files defining the user-written terms (usually ‘changestats.user.h’, ‘changestats.user.c’, and ‘InitErgmTerm.user.R’) and only those files from the old ergm.userterms source code to the new. Do not copy the boilerplate files that you did not modify.
If you have customized the package ‘DESCRIPTION’ file (e.g., to change the package name) or ‘zzz.R’ (e.g., to change the startup message), modify them as needed in the updated ergm.userterms, but do not simply overwrite them with their old versions.
Make sure that your ergm installation is
up to date, and rebuild
ergm.userterms.
This term adds one network statistic to the model
being the number of nodes in the network of at least degree
mindeg. That is, the statistic equals the number of nodes
in the network with mindeg or more edges. This term can
only be used with undirected networks.
# binary: mindegree(mindeg, by=NULL)# binary: mindegree(mindeg, by=NULL)
mindeg |
an integer giving the |
by |
an optional argument specifying a vertex attribute (see
Specifying Vertex attributes and Levels ( |
This InitErgmTerm function is for the mindegree term
described by
Hunter DR, Goodreau SM, Handcock MS (2013). ergm.userterms: A
Template Package for Extending statnet, Journal of Statistical
Software 52(2), 1-25, doi:10.18637/jss.v052.i02.
It has been further updated to use the latest ergm APIs and conventions.
ergmTerm for index of model terms currently visible to the package.
None
These terms add one network statistic to the model, the square root of the number of triangles. They demonstrate the private and auxiliary storage mechanisms. The change statistic for the square root of the number of triangles depends on the initial number of triangles, so it is costly to compute – unless one can keep track of the number of triangles. These terms can only be used with undirected networks.
# binary: sqrt.triangle # binary: sqrt.triangle.aux# binary: sqrt.triangle # binary: sqrt.triangle.aux
ergmTerm for index of model terms currently visible to the package.
None
data(florentine) sqrt(summary(flomarriage~triangle)) summary(flomarriage~sqrt.triangle) stopifnot(sqrt(summary(flomarriage~triangle)) == summary(flomarriage~sqrt.triangle)) summary(flomarriage~sqrt.triangle.aux) stopifnot(sqrt(summary(flomarriage~triangle)) == summary(flomarriage~sqrt.triangle.aux))data(florentine) sqrt(summary(flomarriage~triangle)) summary(flomarriage~sqrt.triangle) stopifnot(sqrt(summary(flomarriage~triangle)) == summary(flomarriage~sqrt.triangle)) summary(flomarriage~sqrt.triangle.aux) stopifnot(sqrt(summary(flomarriage~triangle)) == summary(flomarriage~sqrt.triangle.aux))