Last updated: 2023-06-23

Network Movies!
Network Movies!

This tutorial is a joint product of the Statnet Development Team:

Pavel N. Krivitsky (University of New South Wales)
Martina Morris (University of Washington)
Mark S. Handcock (University of California, Los Angeles)
Carter T. Butts (University of California, Irvine)
David R. Hunter (Penn State University)
Steven M. Goodreau (University of Washington)
Chad Klumb (University of Washington)
Skye Bender de-Moll (Oakland, CA)
Michał Bojanowski (Kozminski University, Poland)

The temporal modeling software demonstrated in this tutorial is authored by Pavel Krivitsky (tergm) and Skye Bender de-Moll (networkdynamic, tsna and ndtv).


The statnet Project

All statnet packages are open-source, written for the R computing environment, and published on CRAN. The source repositories are hosted on GitHub. Our website is statnet.org

  • Need help? For general questions and comments, please email the statnet users group at statnet_help@uw.edu. You’ll need to join the listserv if you’re not already a member. You can do that here: statnet_help listserv.

  • Found a bug in our software? Please let us know by filing an issue in the appropriate package GitHub repository, with a reproducible example.

  • Want to request new functionality? We welcome suggestions – you can make a request by filing an issue on the appropriate package GitHub repository. The chances that this functionality will be developed are substantially improved if the requests are accompanied by some proposed code (we are happy to review pull requests).

  • For all other issues, please email us at contact@statnet.org.


Introduction

This workshop and tutorial provide an overview of statistical modeling of temporal network data using Statnet software. The tutorial is also designed for self-study, with example code and self-contained data.

The Statnet packages we will be demonstrating are:

  • networkDynamic – storage and manipulation of temporal network data
  • tsna – descriptive statistics and graphics for exploratory network analysis`
  • ndtv – utilities for plotting temporal networks (including network movies)
  • tergm – statistical tools for estimating TERGMs, model assessment, and dynamic network simulation.

If you are transitioning from the tergm 3.x package series, please note the user interface for model specification has changed as of tergm 4.0. At this time, the newest version in the tergm 4.x series is backwards compatible, so if you have scripts based on the 3.x syntax, they will continue to work. However, we will be deprecating some of the functionality in the future.


Prerequisites

This workshop assumes

Software Installation

Minimally, you will need to install the latest version of R (available here) and the Statnet packages listed above to run the code presented here.

The workshops are conducted using the free version of Rstudio (available here).

To install the packages for this tutorial, open an R session and type:

# statnet packages
install.packages('tergm')
install.packages('tsna')
install.packages('ndtv')

# other packages to enhance graphical output
install.packages('htmlwidgets')
install.packages('latticeExtra')

The two non-Statnet packages here (htmlwidgets and latticeExtra) provide some nice graphing utilities, and demonstrate one of the many benefits of working in the R software ecosystem—you’re not restricted to the features in any one package. Throughout this tutorial we will be exploiting this benefit, using functions from base R and other packages seamlessly with our Statnet software.

Make sure the packages are attached:

library(tergm)
library(tsna)
library(ndtv)
library(htmlwidgets)
library(latticeExtra)

Check package versions

sessionInfo()
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default


locale:
[1] LC_COLLATE=English_United States.utf8 
[2] LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

time zone: America/Los_Angeles
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] latticeExtra_0.6-30   lattice_0.21-8        htmlwidgets_1.6.2    
 [4] ndtv_0.13.3           sna_2.7-1             statnet.common_4.9.0 
 [7] animation_2.7         tsna_0.3.5            tergm_4.2.0          
[10] networkDynamic_0.11.3 ergm_4.5.0            network_1.18.1       
[13] knitr_1.43           

loaded via a namespace (and not attached):
 [1] sass_0.4.6              utf8_1.2.3              generics_0.1.3         
 [4] robustbase_0.99-0       jpeg_0.1-10             digest_0.6.31          
 [7] magrittr_2.0.3          RColorBrewer_1.1-3      evaluate_0.21          
[10] lpSolveAPI_5.5.2.0-17.9 grid_4.3.1              networkLite_1.0.5      
[13] fastmap_1.1.1           jsonlite_1.8.5          Matrix_1.5-4.1         
[16] rle_0.9.2               purrr_1.0.1             fansi_1.0.4            
[19] jquerylib_0.1.4         Rdpack_2.4              cli_3.6.1              
[22] rlang_1.1.1             rbibutils_2.2.13        cachem_1.0.8           
[25] yaml_2.3.7              tools_4.3.1             parallel_4.3.1         
[28] deldir_1.0-9            memoise_2.0.1           coda_0.19-4            
[31] dplyr_1.1.2             interp_1.1-4            base64_2.0.1           
[34] png_0.1-8               vctrs_0.6.3             R6_2.5.1               
[37] lifecycle_1.0.3         MASS_7.3-60             trust_0.1-8            
[40] pkgconfig_2.0.3         pillar_1.9.0            bslib_0.5.0            
[43] Rcpp_1.0.10             ergm.multi_0.2.0        glue_1.6.2             
[46] DEoptimR_1.0-14         xfun_0.39               tibble_3.2.1           
[49] tidyselect_1.2.0        rstudioapi_0.14         htmltools_0.5.5        
[52] nlme_3.1-162            rmarkdown_2.22          compiler_4.3.1         
[55] askpass_1.1             openssl_2.0.6          

Set seed for simulations – this is not necessary, but it ensures that we all get the same results (if we execute the same commands in the same order).

set.seed(1)

Temporal network data

Moving from static to dynamic networks leads to many different types of potential dynamics:

  • Tie dynamics–formation and dissolution (this is the minimum for our purposes)
  • Node dynamics–entry and exit (we won’t address this here, but can handle them)
  • Attribute dynamics–both node and tie attributes can change over time

All of this requires new data storage mechanisms, new methods for descriptive statistics, new tools for visualization, and a new framework for modeling. As a result, there are 4 software packages in Statnet that perform these new tasks. Comparing to the Statnet packages used for static network analysis:

Function Static Networks Dynamic Networks
Data Storage network networkDynamic
Descriptive Stats sna tsna
Visualization network (plot.network function) ndtv
Statistical Modeling ergm tergm

Types of temporal network data

Temporal network information can be collected in different ways, leading to several different types of data:

  • Discrete time network census panel data (with 2 or more panels)
  • Cross-sectional network data with information on tie duration (census or sampled)
  • Continuous time network event data

Each type typically requires different methods for analysis. TERGMs are models for discrete time dynamics, so they can be used for the first two, and both are covered in this tutorial.

Overview of modeling frameworks for temporal network data

There are three general modeling frameworks for temporal network data analysis in the social networks field.

  • Stochastic Actor Oriented Models (SAOM)–implemented in the RSiena package written by Tom A.B. Snijders and colleagues. SAOMs model the coevolution of nodal attributes and tie dynamics. They are formulated as continuous time models, but typically are estimated on discrete time data.

  • Relational Event Models–implemented in the Statnet package relevent written by Carter Butts and colleagues. These are continuous time models for node and tie dynamics, so they can assume dyad independence, and exploit the methodology of logistic regression.

  • Temporal Exponential-family Random Graph Models (TERGMS)–This is a large family of models that extend ERGMs to the analysis of dynamic networks. TERGMs represent tie dynamics only, and are typically formulated in discrete time.

This workshop will focus on TERGMs. We’ll start with a quick overview of the utilities for data storage, descriptive stats and visualization of temporal network data in the Statnet packages before moving on to the statistical modeling with the package tergm.


Temporal network models and “agent-based” models

All temporal network models can be thought of as a form of “agent-based” model, in the sense that they can be used for stochastic simulation of a population of “agents” interacting over time. What makes the statistical network modeling frameworks distinctive is:

  1. Principled statistical estimation of the network model parameters that allows for hypothesis testing and inference at the model building stage; and

  2. Reproduction of the full joint distribution of observed network configurations that are represented by the terms in the model.

These are both powerful advantages over traditional agent-based modeling frameworks. If your goal is to capture and reproduce (simulate) empirically observed contact patterns in a network, the statistical network modeling frameworks provide that functionality, with a strong scientific foundation.


Exploratory tools

networkDynamic

For storing and working with temporal network data.

Temporal network data in Statnet can be stored in several ways, including lists and series, but the networkDynamic class objects have been specifically designed to provide access to a wide range of features and functions for network data analysis. All networkDynamic objects also have the class network. They can thus be edited or queried using standard functions from the network package, as well as the functions designed for dynamic networks in the package networkDynamic.

Let us consider the 3 panels of the Sampson monastery data:

data(samplk)
ls()
[1] "samplk1" "samplk2" "samplk3"

To create a dynamic network object from the panels, we need to combine them into a list:

samp.list <- list(samplk1,samplk2,samplk3)
samp.dyn <- networkDynamic(network.list = samp.list)
Neither start or onsets specified, assuming start=0
Onsets and termini not specified, assuming each network in network.list should have a discrete spell of length 1
Argument base.net not specified, using first element of network.list instead
Created net.obs.period to describe network
 Network observation period info:
  Number of observation spells: 1 
  Maximal time range observed: 0 until 3 
  Temporal mode: discrete 
  Time unit: step 
  Suggested time increment: 1 

The networkDynamic function is able to convert a wide array of temporal network data types into the networkDynamic objects. For more information, see ?networkDynamic.

As with network objects you can get a quick summary of a networkDynamic object by typing the object name:

samp.dyn
NetworkDynamic properties:
  distinct change times: 4 
  maximal time range: 0 until  3 

Includes optional net.obs.period attribute:
 Network observation period info:
  Number of observation spells: 1 
  Maximal time range observed: 0 until 3 
  Temporal mode: discrete 
  Time unit: step 
  Suggested time increment: 1 

 Network attributes:
  vertices = 18 
  directed = TRUE 
  hyper = FALSE 
  loops = FALSE 
  multiple = FALSE 
  bipartite = FALSE 
  net.obs.period: (not shown)
  total edges= 88 
    missing edges= 0 
    non-missing edges= 88 

 Vertex attribute names: 
    active cloisterville group vertex.names 

 Edge attribute names: 
    active 

By default, the starting time is set to 0, so the first network will have this time stamp. You can change that behavior by specifying a different value, for example: samp.dyn <- networkDynamic(network.list = samp.list, start=1).

The summary indicates 4 timepoints (0 through 3), even though the data only have 3 panels. This is an artifact of the discrete time represention. If you look at the final network, you’ll see it is empty:

summary(network.extract(samp.dyn, at = 3)) # empty
Network attributes:
  vertices = 0
  directed = TRUE
  hyper = FALSE
  loops = FALSE
  multiple = FALSE
  bipartite = FALSE
  net.obs.period:
               Length Class  Mode     
observations   1      -none- list     
mode           1      -none- character
time.increment 1      -none- numeric  
time.unit      1      -none- character
 total edges = 0 
   missing edges = 0 
   non-missing edges = 0 
 density = NaN 

No vertex attributes

No edge attributes

Network adjacency matrix:
Empty Graph
summary(network.extract(samp.dyn, at = 0)) # the first network, as expected
Network attributes:
  vertices = 18
  directed = TRUE
  hyper = FALSE
  loops = FALSE
  multiple = FALSE
  bipartite = FALSE
  net.obs.period:
               Length Class  Mode     
observations   1      -none- list     
mode           1      -none- character
time.increment 1      -none- numeric  
time.unit      1      -none- character
 total edges = 55 
   missing edges = 0 
   non-missing edges = 55 
 density = 0.1797386 

Vertex attributes:

 active:
   mixed class attribute
    18 values

 cloisterville:
   logical valued attribute
   attribute summary:
   Mode   FALSE    TRUE 
logical      12       6 

 group:
   character valued attribute
   attribute summary:
   Loyal Outcasts    Turks Waverers 
       5        3        7        3 
  vertex.names:
   character valued attribute
   18 valid vertex names

Edge attributes:

 active:
   mixed class attribute
    55 values

Network edgelist matrix:
      [,1] [,2]
 [1,]    3    2
 [2,]   15    2
 [3,]    5    4
 [4,]    1    5
 [5,]    4    5
 [6,]   13    7
 [7,]   11    8
 [8,]    8    9
 [9,]    9   16
[10,]   17   18
[11,]    2    1
[12,]    3    1
[13,]    6    1
[14,]    8    1
[15,]   12    1
[16,]   14    1
[17,]   15    1
[18,]   16    1
[19,]   18    1
[20,]    7    2
[21,]    8    2
[22,]   12    2
[23,]   16    2
[24,]   18    2
[25,]    1    3
[26,]   17    3
[27,]    6    4
[28,]   10    4
[29,]    9    5
[30,]   11    5
[31,]   13    5
[32,]    4    6
[33,]    2    7
[34,]   16    7
[35,]   18    7
[36,]    7    8
[37,]    9    8
[38,]   10    8
[39,]    6    9
[40,]    4   10
[41,]    5   11
[42,]   14   11
[43,]   14   12
[44,]    5   13
[45,]   17   13
[46,]    1   14
[47,]    2   14
[48,]   10   14
[49,]   11   14
[50,]   12   14
[51,]   15   14
[52,]   14   15
[53,]    7   16
[54,]    3   17
[55,]   13   18

The discrete time representation means that specifying at=0 is equivalent to specifying the semi-open interval [0-1) with onset = 0, terminus = 1.

# Equivalent statements
nw <- network.extract(samp.dyn, at = 0) # first network
nw <- network.extract(samp.dyn, onset = 0, terminus=1) # same thing

The networkDynamic package contains many utilities for modifying, extracting and querying networkDynamic objects. For example, the network.extract function above extracts one or more networks from the series, while the network.collapse function extracts one or more networks and collapses them into a single network object.

You can get a good overview of the wide range of functionality in this package by reading the package vignette:

vignette("networkDynamic")

As one small example, we’ll just make a quick plot of the three network panels, using the network.extract function (this also extracts one or more networks, but preserves the time info if present) and the network.

par(mfrow = c(2,2), oma=c(1,1,1,1), mar=c(4,1,1,1))
plot(network.extract(samp.dyn, at = 0), main = "Time 1", 
     displaylabels = T, label.cex = 0.6, vertex.cex = 2, pad = 0.5)
plot(network.extract(samp.dyn, at = 1), main = "Time2", 
     displaylabels = T, label.cex = 0.6, vertex.cex = 2, pad = 0.5)
plot(network.extract(samp.dyn, at = 2), main = "Time3", 
     displaylabels = T, label.cex = 0.6, vertex.cex = 2, pad = 0.5)
plot(samp.dyn, main = "Collapsed", 
     displaylabels = T, label.cex = 0.6, vertex.cex = 2, pad = 0.5)

This confirms the expectation that the collapsed network has the most edges. That said, it’s not the most helpful display if you’re seeking some insight into the temporal changes in these friendships. The next packages we’ll review are designed to facilitate that task.

tsna

For descriptive temporal network analysis

As the name suggests, this package generalizes the sna package functionality for temporal network data. It provides utilities for calculating a range of cross-sectional and temporal statistics. We’ll take a brief look at these here.

For a detailed introduction to the tsna package, see the vignette.

vignette("tsna_vignette")

SNA metrics

the tSnaStats function calculates traditional cross-sectional social network analysis metrics at multiple time points, as a time-series object.

tSnaStats(samp.dyn, "degree") # Changes in degree centrality
Time Series:
Start = 0 
End = 3 
Frequency = 1 
  John Bosco Gregory Basil Peter Bonaventure Berthold Mark Victor Ambrose
0         12      10     5     6           8        4    7      7       5
1         11      12     4     8          10        5    6      5       4
2          7       9     7     7           9        5    8      5       7
3         NA      NA    NA    NA          NA       NA   NA     NA      NA
  Romauld Louis Winfrid Amand Hugh Boniface Albert Elias Simplicius
0       4     5       4     5   10        4      5     4          5
1       4     5       7     5    6        6      5     5          6
2       4     5       9     5    5        5      4     5          6
3      NA    NA      NA    NA   NA       NA     NA    NA         NA

ERGM terms

The tErgmStats function calculates cross-sectional ergm term statistics at multiple time points, as a time-series object.

tErgmStats(samp.dyn, "~ edges+triangle") # Note the increase in triangles
Time Series:
Start = 0 
End = 3 
Frequency = 1 
  edges triangle
0    55       31
1    57       56
2    56       62
3     0        0

Temporal paths

The tPath, tReach and plotPaths functions calculate temporal paths through networks, the temporal versions of geodesics.

Temporal paths are unique to dynamic networks. Similar to a path in a static network, they trace out the sequence and distances of nodes in a networkDynamic object reachable from an initial node, following paths constrained by edge timing (and direction, if the network is directed). A temporal path can only traverse active nodes and edges, so the onset times of successive elements must be greater than or equal than those of the previous. These paths determine the diffusion potential across a network.

Below, we compute and plot the forward reachable set (FRS) from node 1 (v1) in the Sampson networks (the vertices that node 1 can reach).

# who is v1?
get.vertex.attribute(samp.dyn, "vertex.names")[1]
[1] "John Bosco"
# who is in v1's FRS?
tp <- tPath(samp.dyn, v=1, direction = 'fwd')
print(tp)
$tdist
 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

$previous
 [1]  0  3  1  5  1  4  2  7  6  4  5 14  5  1 14  7  3 13

$gsteps
 [1] 0 2 1 2 1 3 3 4 4 3 2 2 2 1 2 4 2 3

$start
[1] 0

$end
[1] Inf

$direction
[1] "fwd"

$type
[1] "earliest.arrive"

attr(,"class")
[1] "tPath" "list" 
par(mfrow=c(1,2))
coords <- plot(tp, main="Forward Reachable Set from v1", cex.main=.8)
plotPaths(samp.dyn, tp, 
          coord = coords,
          main = "Overlaid on collapsed Network",
          label.cex=.8, cex.main=.8)

Because all of the vertices are in one component in the first graph, node 1 (Bosco) is able to reach every other vertex in the first spell; the first network alone determines the temporal path. This is a bit of a boring example, things get much more interesting when there are multiple components in a graph that change composition over time.

A forward tpath traces the earliest arriving path by default, so in this case, tp$tdist = 0 for all vertices, because they can all be reached in the first spell, tp$gsteps is simply the geodesic from Bonaventure to each other vertex in the first network, and plotting tp shows those geodesics.

And note that one can also construct a “backwards reachable set” for Bosco – the set of all vertices that can reach him.

Forward and backward reachable sets are key metrics for understanding diffusion processes over networks. The tsna package vignette demonstrates many more interesting features of temporal paths in dynamic networks with multiple components that change over time.

Durations

The edgeDuration and vertexDuration functions summarize node and tie dynamics.

Durations are another feature unique to temporal networks, representing the lenth of time that vertices and edges are active. The tsna package contains several functions for reporting on active durations. Most of these functions have options for varying the units of aggregation or analysis. For example, the edge measures can be adjusted from focusing on an ‘edge’ (aggregating across all of the activity spells associated with that edge) or a ‘spell’ (a single interval of contiguous time during which an edge is activated).

# a table of spell lengths
table(edgeDuration(samp.dyn, mode = 'duration', subject = 'spells')) 

 1  2  3 
48 15 30 
# Note bimodality -- what does this suggest?

# a table of edge active durations
table(edgeDuration(samp.dyn, mode = 'duration', subject = 'edges'))

 1  2  3 
38 20 30 
# comparing the two: 5 of the dyads have the pattern 1,0,1.  so these
# show up as 10 spells of length 1, or 2 edges of active duration 2.

For a list of all the functions available in the tsna package, type:

help(package="tsna")

ndtv

For visualizing dynamic networks

The Network Dynamic Temporal Visualization (ndtv) package provides tools for visualizing changes in network structure and attributes over time.

ndtv has its own workshop and tutorial, with materials online at our Workshops page

The package includes an example network data set named short.stergm.sim which is the output of a toy model based on Padgett’s Florentine Family Business Ties dataset simulated using the tergm package. (We’ll use the tergm package to construct this simulated dynamic network in a later section.)

data(short.stergm.sim)

Network Movies

To get a quick visual summary of how the structure changes over time, we can render the dynamic network as an animation; here we will use an interactive HTML5 animation in a web browser.

render.d3movie(short.stergm.sim, 
               plot.par=list(displaylabels=T))

This should bring up a browser window displaying the animation. In addition to playing and pausing the movie, it is possible to click on vertices and edges to show their ids, double-click to highlight neighbors, and zoom into the network at any point in time.

Finally, we can render the interactive movie from an Rmarkdown document to an html document like this one.

render.d3movie(short.stergm.sim,
               plot.par=list(displaylabels=T),
               output.mode = 'htmlWidget') # using htmlwidgets package here
slice parameters:
  start:0
  end:25
  interval:1
  aggregate.dur:1
  rule:latest

Proximity Timelines

Another interesting visualization tool is the “proximity timeline”. In this view vertices are positioned vertically by their geodesic distance proximity. This means that changes in network structure deflect the vertices’ lines into new positions, attempting to keep closely-tied vertices as neighbors. The edges are not shown at all in this view.

proximity.timeline(short.stergm.sim,default.dist = 6,
          mode = 'sammon',labels.at = 17,vertex.cex = 4)

Notice how the bundles of vertex lines diverge at time=20, reflecting the split of the large component into two smaller components.

Ok, so that’s a whirlwind tour through the descriptive tools available in Statnet for exploring temporal network data. We strongly encourage exploring your data before you start to model it with tergm.

Statistical Modeling with tergm

Temporal ERGMs (STERGMs) are an extension of ERGMs for modeling dynamic networks in discrete time. Where an ERGM posits one model for the prevalence of ties in a single cross-sectional single network, TERGMs instead typically posit two or more models for the tie dynamics in a network over time. It’s worth noting that each of these models is itself an ERGM, but an ERGM that operates on a specific set of nodes and links.

Model specifications in the tergm package use the standard R formula syntax (nw ~ term1 + term2 …), with terms that represent network statistics, just like we do for ERGMs. But it also uses some new functions called “Term operators” that determine how the network statistics (the terms in the model) are calculated.

Elements of a model

The network

As with all ERGMs, the object on the LHS of the formula is a network. Depending on the type of data you have, this will either be a dynamic network (for panel data) or a simple network (for cross-sectional estimation with additional information on tie duration). Dynamic networks can be passed as an R list object (the samp.list object we created above), as a networkDynamic object (the samp.dyn object we created above), or as a NetSeries object.

NetSeries objects are specifically optimized for TERGM calculations. To construct a NetSeries object from the Sampson data:

samp.series <- NetSeries(list(samplk1,samplk2,samplk3))

So which type of network object should you use?

  • For tergm model fitting, it doesn’t really matter. All objects are transformed to NetSeries behind the scenes for computational efficiency.

  • For initial descriptives and EDA, the networkDynamic format is needed to access the functionality of the tsna and ndtv packages.

  • Both of these objects can also be constructed from a standard R list object, and a list may be more useful for working with base R or other packages.

Bottom line: use what makes the most sense in each context.


Model terms

Term names, arguments and syntax carry over from the ergm package, and refer to the same configuration (e.g., edges counts the ties between two nodes, and degree(1) counts the nodes with degree equal to 1).

There are a number of ways to get the help on the terms available in ergm:

# full documentation
?ergmTerm

# helpful summaries and tables of terms
vignette('ergm-term-crossRef')

For tergm there are some new temporally-specific terms available for monitoring. We won’t be using these here, but you can get more information by typing:

search.ergmTerms(package="tergm")

So, much will look familiar to you from ergm. That said, there are some important differences.

The way the terms count configurations is different, and depends on context. This context is set by the term operators.

As a result, the values of the network statistics, and the interpretation of the coefficients will be different than in a simple ergm.


Term Operators

The biggest difference you’ll notice in specifying a TERGM is that this typically involves more than one formula. The formulas are specified using the new temporal “operators” available since version 4.0 of the tergm package.


Just a warning here: there is a lot of conceptual material condensed into a brief introduction.

The best way to unpack it and make sure you understand it is to work through the examples in Appendix B.


There are five temporal operators: Form(), Diss(), Persist(), Cross() and Change(). Each operator tracks a specific type of tie dynamic. We describe them below for the case of a two panel network dataset (t and t+1).

  • Form() tracks the formation of ties between time steps, so the terms in this model represent the factors that influence tie formation. For example, Form(~edges) is a model for homogeneous rates of tie formation, and the estimated coefficient would represent the log-odds of a tie forming in each timestep. The Form() operator constructs a NetSeries object that is the union of the t and t+1 networks, so the edges term will count all ties that are present in either network.

  • Persist() tracks the persistence of ties between time steps, so the terms in this model represent the factors that influence tie persistence. For example, Persist(~edges) is a model for homogeneous rates of tie persistence, and the estimated coefficient would represent the log-odds of a tie persisting (i.e., not dissolving) in each time step. The Persist() operator constructs a NetSeries object that is the intersection of the t and t+1 networks, so the edges term will count all ties that are present in both networks.

  • Diss() tracks the dissolution of ties between time steps, so the terms in this model represent the factors that influence tie dissolution. It is the opposite of Persist() and only one of these can be used in specifying a model. For example, Diss(~edges) is a model for homogeneous tie dissolution rates, and the estimated coefficient will be equal to the Persist(~edges) coefficient multiplied by -1.

  • Change() tracks the total number of dyads that change status between time steps, both formations and dissolutions. So it represents the rate of “churn” or turnover in dyad status. The Change(~edges) model would specify a homogeneous rate of change, and the estimated coefficient would represent the log-odds of a dyad changing status – either forming a tie or dissolving a tie – in each time step. The Change() operator constructs a NetSeries object that includes only the ties that are present in one of the networks t and t+1, but not both. This operator does not distinguish between formation and dissolution changes, so the terms in this operator, and their coefficients, represent effects on both dynamics.

  • Cross() tracks the average cross-sectional structure of the network over time, and in this sense it is not a model for tie-dynamics. This operator is analogous to a cross-sectional ergm – but it operates on a set of networks (typically, a time-series). It summarizes the presence of the structural feature across these networks. For example, Cross(~edges) is a model for homogeneous tie density, and the estimated coefficient would represent the log-odds of a tie existing in the network at an arbitrary time point. The Cross() operator constructs a NetSeries object from the t+1 network, so the edges term will count all ties that are present in that network.

Generalizing to a longer time series just pools the tie counts from the operators applied to each pair of time-points (or, in the case of the Cross() operator, pools all of the time points after t).

You can mix these operators in different ways, but no more than 2 operators can include the same model term, otherwise a model will be over-specified.

While the operators can be mixed in different ways, there are two pairings that are most frequently used:

  • Form() + Diss() (a “separable” model)

  • Cross() + Change() (a “joint” model)

So we focus on these here.

Joint vs. Separable Models

TERGMs are a very general family of models. Sub-classes within this family are defined by which tie changes are tracked and counted (the “operators” you use), and the model specification for each type of change (the model terms in the operators).

We will focus on two important classes of TERGMs in this tutorial: the joint model and the separable model. These allow us to introduce all of the operator terms implemented in the tergm packages, and provide a good intuitive foundation for temporal model specification.

The joint and separable models both specify a pair of equations, but they differ in how they represent the tie-change dynamics:

  • Joint models specify a process for tie dynamics using operators that are dependent within time steps; the Cross() + Change() model is the classic example. Here, every dyad is represented in both operators: the Cross() operator evaluates cross-sectional network statistics over the whole network, and the Change() operator evaluates the changes in dyad status over the whole network. The terms in the two operators are correlated because the same dyads appear in both sets of terms, so this model must be jointly evaluated at each step of estimation or simulation (hence the name).

  • Separable models specify a process for tie dynamics using operators that are independent within time-step; the Form() + Diss() (or Persist()) model is the classic example. Here, the dyads can be partitioned into two mutually exclusive sets at each timepoint: the empty dyads, which are subject to formation, and the tied dyads, which are subject to dissolution. A single dyad change will affect either the Form() model statistics or the Diss()/Persist() model statistics at each timestep, but not both. So the terms in the two operators are uncorrelated, and can be separately evaluated at each step for estimation or simulation.

Note that while these separable models posit that the 2 sets of dyads are independent within timestep, there are two types of dependence still operating:

  • There is still Markov-dependence between timesteps: the formation of a tie at time t can influence the dissolution of an adjacent tie at t+1.

  • And within each operator set, there can still be dyad-dependence within step if dyad-dependent terms are specified in the model.

This distinction also has important implications for the type of data that can be used to estimate a TERGM.

tergm syntax

In the ergm package, the model is specified using standard R formula notation, with the network on the LHS and the ergm-terms on the RHS:

> ergm(my.network ~ edges + nodefactor('age') + gwesp(0, fixed=T))     #do not run this!
           

For a call to tergm, you pass

  • the formula, which will typically include more than one Operator (each with its own set of terms), and

  • the estimation method, which will depend on the type of data you have.

For example, for a model specified with Form() and Diss() operators:

> tergm(my.dynamic.network ~                    #do not run this!
      Form(~ edges + gwesp(0, fixed=T)) +
      Diss(~ edges + nodefactor('age')),
      estimate =  'insert method'
)

The two current options for the estimate argument are

  • CMLE (conditional maximum likelihood estimation) for fitting a model to network panel data, and

  • EGMME (equilibrium generalized method of moments estimation), for fitting a model to a single cross-sectional network with duration information.

There are many other features of a call to tergm that will be important; we illustrate them in one or more examples below.


Examples

We’ll work through three examples here, first with network panel data, next with cross-sectional data plus duration information, and finally (briefly) with an approximation used in the cross sectional case when durations are very long.

CMLE

For network panel data

The canonical form of data for modeling dynamic network processes consists of observations of a complete network at two or more points in time on the same node set. Many classic temporal network studies were of this type, and this remains a gold standard for temporal network data collection.

Let us return to the Sampson monastery data, and consider models for the way this network changes across the 3 observed time points. We will start with some very basic models, to ensure that we understand how the temporal term operators work.

  • What do you think would happen if you specified a TERGM with just a Form() operator? Would that work? What type of networks would it produce as at equilibrium?

  • How about if you specified just a Diss() operator?

The best way to answer these questions is to try it and see what happens. For that, we’ve developed a series of exercises to explore in Appendix B.

Form() + Persist()

This is a separable model. We’ll use the Persist() operator rather than the Diss() here for several reasons; one is that the sign of the coefficient indicates the same impact as in the Form() operator on whether you expect a tie to be present.

This is a directed network, so it would be natural to consider mutuality as a predictor.

Should this be in the formation model, the persistence model, or both?

From the descriptive statistics we saw that the number of triangles increased over time. Given directedness, it would be natural to examine the role of cyclical (non-hierarchical) vs. transitive (hierarchical) triangles in the network. The robust way to model this in ERGMs is with the terms transitiveties and cyclicalties (the number of ties \(i{\rightarrow}j\) that have at least one two-path from \(i{\rightarrow}j\) and from \(j{\rightarrow}i\), respectively).

Should these be in the formation model, the persistence model, or both?

In this case, we will specify the same terms in both the formation and persistence model. This is not required in stergms; we could instead, for instance, specify a simple homogeneous Bernoulli model for persistence (all ties are equally likely to persist at each time step) if we thought that was appropriate. Having the same terms also does not mean we have the “same model” for formation and persistence: we might find that the coefficient estimates differ in sign or magnitude.

What are your hypotheses going in? Do you think cyclical or transitive ties will positively influence tie formation and persistence?

In the call to tergm, we specify CMLE (since we have a network panel), and the time slices we wish to model:

samp.fit.fp <- tergm(samp.list ~
    Form(~edges+mutual+cyclicalties+transitiveties) +
    Persist(~edges+mutual+cyclicalties+transitiveties),
  estimate = "CMLE",
  times = c(1:3)
    )

summary(samp.fit.fp)
Call:
tergm(formula = samp.list ~ Form(~edges + mutual + cyclicalties + 
    transitiveties) + Persist(~edges + mutual + cyclicalties + 
    transitiveties), estimate = "CMLE", times = c(1:3))

Monte Carlo Conditional Maximum Likelihood Results:

                          Estimate Std. Error MCMC % z value Pr(>|z|)    
Form(1)~edges              -3.4928     0.3454      0 -10.112   <1e-04 ***
Form(1)~mutual              2.0242     0.4076      0   4.966   <1e-04 ***
Form(1)~cyclicalties       -0.1356     0.2061      0  -0.658   0.5105    
Form(1)~transitiveties      0.4067     0.2396      0   1.697   0.0897 .  
Persist(1)~edges            0.1950     0.3108      0   0.628   0.5303    
Persist(1)~mutual           0.7693     0.5196      0   1.480   0.1387    
Persist(1)~cyclicalties    -0.1921     0.2588      0  -0.742   0.4578    
Persist(1)~transitiveties   0.5215     0.2824      0   1.847   0.0648 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

     Null Deviance: 848.4  on 612  degrees of freedom
 Residual Deviance: 375.7  on 604  degrees of freedom
 
AIC: 391.7  BIC: 427  (Smaller is better. MC Std. Err. = 2.134)

First: what do you notice about the p-values?

Not much is significant here. Keep in mind that this is a small sparse network, with only two changes observed, so the amount of information available for testing these effects is minimal (especially for the persistence model – why?).

But let’s take a look at the direction of the coefficients, and see if they indicate support for our hypotheses, … or not.

All else equal, a relationship is much more likely to form if it will close a mutual pair; the conditional log-odds are increased by 2.02 which translates to an increase in the conditional odds of 7.57 (note that the change statistic can equal only \(0\) or \(1\) in this case). This is one of the few significant effects in the model.

The reciprocity effect on persistence is also positive, but less strong and not statistically significant; the point estimate is an increase of 0.77 in the conditional log-odds of persistence, a bit more than double when transformed to the odds scale.

The coefficients for transitive triads (hierarchical) are positive and borderline significant for both formation and persistence. The coefficients for cyclical triads (egalitarian) are negative for both models, but not significant.

Keep in mind that this is a small sparse network, so the amount of information available for testing these effects is minimal (especially for the dissolution model). Overall, the results suggest that hierarchy plays a role in tie formation and persistence in this monastery, and there is a weak but consistent anti-egalitarianism dynamic.

Cross() + Change()

For comparison we will use the same terms in these two operators, so we can think about the difference in interpretation.

What are your hypotheses going in this time? Which type of configuration would you expect to be more common in the cross-section? Which type would be most likely to change?

samp.fit.cc <- tergm(samp.list ~
    Cross(~edges+mutual+cyclicalties+transitiveties) +
    Change(~edges+mutual+cyclicalties+transitiveties),
  estimate = "CMLE",
  times = c(1:3)
    )
Starting maximum pseudolikelihood estimation (MPLE):
Obtaining the responsible dyads.
Evaluating the predictor and response matrix.
Maximizing the pseudolikelihood.
Finished MPLE.
Starting Monte Carlo maximum likelihood estimation (MCMLE):
Iteration 1 of at most 60:
Optimizing with step length 1.0000.
The log-likelihood improved by 1.8335.
Estimating equations are not within tolerance region.
Iteration 2 of at most 60:
Optimizing with step length 1.0000.
The log-likelihood improved by 0.1634.
Estimating equations are not within tolerance region.
Iteration 3 of at most 60:
Optimizing with step length 1.0000.
The log-likelihood improved by 0.0528.
Convergence test p-value: 0.2665. Not converged with 99% confidence; increasing sample size.
Iteration 4 of at most 60:
Optimizing with step length 1.0000.
The log-likelihood improved by 0.0288.
Convergence test p-value: 0.6634. Not converged with 99% confidence; increasing sample size.
Iteration 5 of at most 60:
Optimizing with step length 1.0000.
The log-likelihood improved by 0.0297.
Convergence test p-value: 0.6251. Not converged with 99% confidence; increasing sample size.
Iteration 6 of at most 60:
Optimizing with step length 1.0000.
The log-likelihood improved by 0.0675.
Convergence test p-value: 0.0524. Not converged with 99% confidence; increasing sample size.
Iteration 7 of at most 60:
Optimizing with step length 1.0000.
The log-likelihood improved by 0.0296.
Convergence test p-value: 0.0105. Not converged with 99% confidence; increasing sample size.
Iteration 8 of at most 60:
Optimizing with step length 1.0000.
The log-likelihood improved by 0.0088.
Convergence test p-value: 0.0001. Converged with 99% confidence.
Finished MCMLE.
Evaluating log-likelihood at the estimate. Fitting the dyad-independent submodel...
Bridging between the dyad-independent submodel and the full model...
Setting up bridge sampling...
Using 16 bridges: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 .
Bridging finished.

This model was fit using MCMC.  To examine model diagnostics and check
for degeneracy, use the mcmc.diagnostics() function.
summary(samp.fit.cc)
Call:
tergm(formula = samp.list ~ Cross(~edges + mutual + cyclicalties + 
    transitiveties) + Change(~edges + mutual + cyclicalties + 
    transitiveties), estimate = "CMLE", times = c(1:3))

Monte Carlo Conditional Maximum Likelihood Results:

                         Estimate Std. Error MCMC % z value Pr(>|z|)    
Cross(1)~edges           -1.87171    0.23834      0  -7.853   <1e-04 ***
Cross(1)~mutual           1.65292    0.39289      0   4.207   <1e-04 ***
Cross(1)~cyclicalties    -0.04319    0.18129      0  -0.238   0.8117    
Cross(1)~transitiveties   0.45429    0.21595      0   2.104   0.0354 *  
Change(1)~edges          -1.64397    0.23678      0  -6.943   <1e-04 ***
Change(1)~mutual         -0.32231    0.51687      0  -0.624   0.5329    
Change(1)~cyclicalties   -0.09907    0.17255      0  -0.574   0.5659    
Change(1)~transitiveties  0.44690    0.23948      0   1.866   0.0620 .  
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

     Null Deviance: 848.4  on 612  degrees of freedom
 Residual Deviance: 376.7  on 604  degrees of freedom
 
AIC: 392.7  BIC: 428  (Smaller is better. MC Std. Err. = 1.394)

Again: what do you notice about the p-values?

Not much is significant, again. This time, both operators are working with the same number of observations (why?).

But let’s take a look at the direction of the coefficients, and see if they indicate support for our hypotheses, … or not.

All else equal, a relationship is much more likely to be present in the network if it is part of a mutual pair; the conditional log-odds are increased by 1.65 which translates to an increase in the conditional odds of 5.22. This is again one of the few significant effects in the model. It’s not surprising given what we saw in the first model – mutual ties are both more likely to form, and to persist.

The reciprocity effect on change is negative: the rate of change for ties in a mutual pair is 0.77 on the log-odds scale, or 5.22 on the odds scale.

Can you explain what those odds mean in terms that make sense to a kid in primary school?

The coefficient for transitive triads (hierarchical) in the cross section is positive and significant, again what we would expect from the first model. But note that the coefficient for change is also positive and borderline significant. So these ties turn over a lot, though we can’t say if that’s because they’re more likely to form, or to dissolve; that is the limitation of using the Change() operator.

The coefficients for cyclical triads (egalitarian) are very weakly negative in the cross-section. This suggests that, whatever the formation and dissolution dynamics, the number of cyclical triads is roughly equal to what you would expect by chance. In contrast to the transitive triads, the ties in cyclical triads are a bit less likely to turn over, but again, this is not a significant effect.

So, which model should you use? Discuss :-)

EGMME

For cross sectional network data with tie duration information

Now, imagine a different scenario in which we have observed a single cross-sectional network, with retrospective information collected on the duration of ties. This kind of data can be collected in a simple one-time survey, so it is much easier to obtain, and in many contexts it may be the only type of network data that is feasible to collect.

  • How can we estimate the formation and persistence models with a single cross-sectional network?
  • … By making an equilibrium assumption.

If we assume that the process is in equilibrium, then we can rely on the fact that, at equilibrium, \(prevalence = incidence \times duration\).
Our cross-sectional network allows us to observe the \(prevalence\) of ties, and the retrospective information collected allow us to estimate the \(duration\), so we can use tergm to solve for the \(incidence\) in the formation model that would be consistent with this prevalence and duration.

The duration information required here is obtained by asking respondents to report the duration of relationships. In the simple case of a time-constant persistence hazard, the mean duration is the estimate we need to calculate the persistence edge coefficient. This estimate can come from the same cross-sectional study, or, if necessary, from a completely different data source.

We will demonstrate the latter by creating a toy dataset, based on Padgett’s cross-sectional flobusiness network, using a fictional mean tie duration estimate of 10 time steps, and assuming a homogeneous persistence process (that is, every existing tie has the same probability of dissolving, at each step). With real data we could model heterogeneous durations as we did above, but in this simple case will suffice to demonstrate the basic modeling tasks.

  • First, we specify the formation and persistence models.

We begin with a model that sets the density (edges) and includes a term to test for possible triad formation bias (gwesp):

Form(~ edges + gwesp(0,fixed=T))

Note that with the decay parameter alpha set to \(0\) the gwesp term only counts the first triad closed by a tie so the coefficient will represent the log-odds of forming a tie given that it creates at least one “shared-parter” triad.

For our persistence model, we will assume a simple homogenous process, which corresponds to a model with only an edges term in it. The coefficient on this term represents the conditional log-odds of tie persistence at each step, and the inverse is the mean log duration.

In this case, however, we already know the mean duration, which means we know the rate of persistence/dissolution, so we don’t need to estimate it.

In STERGM notation we specify this as:

Persist(~offset(edges))


A term with a known coefficient in statistical modeling is called an “offset”. The coefficient on the persistence edges term is derived below.


  • Second, we calculate the offset coefficient: theta.persist.

A persistence model is applied to the set of ties that exist at each step, as reflected in the conditional present in both the numerator and denominator:

\[ \ln{\frac{P(Y_{ij,t+1} = 1 \mid Y_{ij,t} = 1)}{P(Y_{ij,t+1} = 0\mid Y_{ij,t} = 1)}} = \theta'\delta(g(y))_{ij} \]

The numerator represents the case when a tie persists to the next step, and the denominator represents the case when it dissolves.

The one term in our \(\delta(g(y))_{ij}\) vector is the change statistic for the network edge count, which equals one for all \(i,j\).

Let the probability of persistence from one time step to the next for actor pair \(i,j\) be \(p_{ij}\), and the probability of dissolution be \(q_{ij} = 1-p_{ij}\). Our persistence model is homogenous, so we further define \(p_{ij} = p\) for all \(i,j\). Then:

\(\ln{(\frac{p_{ij}}{1-p_{ij}})} = \theta ' \delta(g(y))_{ij}\)

\(\ln{(\frac{p}{1-p})} = \theta\)

\(\ln{(\frac{1-q}{q})} = \theta\)

\(\ln{(\frac{1}{q}-1)} = \theta\)


This is a discrete memoryless process, so the durations have a geometric distribution; and for the geometric distribution, the mean duration is equal to the reciprocal of the dissolution probability. Symbolizing mean relational duration as \(d\), we have \(d = \frac{1}{q}\), and thus:

\(\theta = \ln{(d-1)}\)


So, for our persistence model, theta.persist = \(\ln{(10-1)}\) = \(\ln{9}\) (\(\approx 2.2\)):

theta.persist <- log(9)

In short, we can calculate the persistence coefficient using a (rather simple) closed form solution in this case. And in general, we can do this for all dyadic-dependent terms in a persistence model.

  • Third, we specify our equilibrium target statistics

This is the next difference in the EGMME specification.

We specify this with a one-sided formula listing the statistics that will be used as equilibrium targets.
This can be the same formula as used in one of the operators, or a totally different formula.

Typically, the target statistic values are drawn from the observed cross-sectional network that is the focus of analysis. In this case, the target statistics will be equal to the values of the terms returned by a call to the summary function.

For tergms, as for ergms, however, the target values do not have to come from a specific observed network – they can be derived as counterfactuals, or from multiple data sets, as long as they are internally consistent (for example, the number of ties for a nodefactor level cannot exceed the total number of ties in the network). In this case, we would pass the values of the target statistics to the model with the argument target.stats. If that argument appears in the model specification, it overrides the values in the observed network data.

Here, we will use the formation model to define the statistics, and take the values from our observed cross-sectional network.

targets = ~edges + gwesp(0, fixed=T)


Note: If one is specifying targets = ~ <Form() formula>, then the persistence coefficient(s) should be specified with an offset, and vice versa.


  • Finally, we estimate the formation model, conditional on the dissolution model.

We put this all together in the call to tergm, adding in one additional control argument to monitor model convergence: plotting the progress of the coefficient estimates and the simulated sufficient statistics in real time. When one is using a GUI tool like RStudio, it helps to output this plotting to a separate window, which we do below with the function X11 (and then turn off that window again with dev.off()):

data(florentine)
X11()

set.seed(1)
egmme.fit <- tergm(
  flobusiness ~ 
    Form(~ edges + gwesp(0, fixed=T)) + 
    Persist(~ offset(edges)),
  targets = ~ edges + gwesp(0, fixed=T),
  offset.coef = theta.persist,
  estimate = "EGMME",
  control = control.tergm(SA.plot.progress=TRUE)
  )

dev.off()

In the X11 window, you should see the MCMC traceplots showing the progress of the coefficient estimates (the f. plots) and the corresponding values of the target statistics.

The real-time feedback suggests that the fitting went well, but let’s double-check by running the mcmc.diagnostics:

mcmc.diagnostics(egmme.fit, which="plots") # only returns the plots

These look pretty good. The serial correlation evident in the traceplots could be reduced by modifying some of tergm’s control parameters. You can experiment with increasing the mcmc.interval to see how that works. But the level of serial correlation here is not enough to cause concern.

So, we’ll move on to explore the fit object to see what we have:

egmme.fit

Call:
tergm(formula = flobusiness ~ Form(~edges + gwesp(0, fixed = T)) + 
    Persist(~offset(edges)), offset.coef = theta.persist, estimate = "EGMME", 
    control = control.tergm(SA.plot.progress = TRUE), targets = ~edges + 
        gwesp(0, fixed = T))

Gradient Descent Equilibrium Generalized Method of Moments Results Coefficients:
           Form~edges     Form~gwesp.fixed.0  offset(Persist~edges)  
               -6.474                  2.298                  2.197  
names(egmme.fit)
 [1] "newnetwork"    "newnetworks"   "init"          "covar"        
 [5] "mc.se"         "eta"           "opt.history"   "sample"       
 [9] "network"       "network"       "coef"          "targets"      
[13] "target.stats"  "estimate"      "sample.obs"    "control"      
[17] "reference"     "constraints"   "etamap"        "offset"       
[21] "mle.lik"       "MPLE_is_MLE"   "ergm_version"  "call"         
[25] "formula"       "estimate.desc" "tergm_version"
summary(egmme.fit)
Call:
tergm(formula = flobusiness ~ Form(~edges + gwesp(0, fixed = T)) + 
    Persist(~offset(edges)), offset.coef = theta.persist, estimate = "EGMME", 
    control = control.tergm(SA.plot.progress = TRUE), targets = ~edges + 
        gwesp(0, fixed = T))

Gradient Descent Equilibrium Generalized Method of Moments Results Results:

                      Estimate Std. Error MCMC % z value Pr(>|z|)    
Form~edges              -6.474      2.366      0  -2.737  0.00621 ** 
Form~gwesp.fixed.0       2.298      2.248      0   1.022  0.30661    
offset(Persist~edges)    2.197      0.000      0     Inf  < 1e-04 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1


 The following terms are fixed by offset and are not estimated:
  offset(Persist~edges) 

We have now obtained estimates for the coefficients of a formation model that, conditional on the given dissolution model (and its offsets), yields simulated targets over time that match (in expectation) those observed in the cross-sectional flobusiness network.

From this fitted model we can now simulate new dynamic networks (that is, entire network panels over time) that have the desired cross-sectional structure and mean relational duration. This is a very useful tool – essentially an agent-based simulation that is guaranteed to reproduce, on average, the full joint distribution of the cross-sectional network statistics and partnership durations in the model that we observed in our data.

egmme.sim <- simulate(egmme.fit, nsim = 1, 
                        time.slices = 1000)

We can use ndtv to visualize the simulated network time series (we’ll just look at the 1st 25 steps):

wealthsize <- log(get.vertex.attribute(flobusiness, "wealth")) * 2/3

# Set the ndtv animation parameter
slice.par = list(start = 0, 
               end = 25, 
               interval = 1, 
               aggregate.dur = 1, 
               rule = "any")
# Animate
compute.animation(egmme.sim, slice.par = slice.par)

# Set some ndtv rendering parameters
render.par = list(tween.frames = 5,
                show.time = T,
                show.stats = "~edges+gwesp(0,fixed = T)")
plot.par = list(edge.col = "darkgray",
              displaylabels = T,
              label.cex = .8,
              label.col = "blue",
              vertex.cex = wealthsize)

# Show the movie!
render.d3movie(egmme.sim,
               render.par = render.par,
               plot.par = plot.par,
               output.mode = 'htmlWidget')

How well do the cross-sectional networks within our simulated dynamic network fit the probability distribution implied by our model?

We can check by comparing the summary statistics for our observed network to those for our cross-sectional networks. This is easy, since by default, the simulate command for a stergm object not only simulates a dynamic network, but calculates the statistics from the model for each time point. These are stored in attribute(simulated.networkDynamic)$stats.

cbind(model = summary(flobusiness ~ edges + gwesp(0, fixed = T)),
      obs = colMeans(attributes(egmme.sim)$stats))
              model    obs
edges            15 14.849
gwesp.fixed.0    12 11.749

And we can also easily look at a time series and histogram for each statistic:

plot(attributes(egmme.sim)$stats)

Of course, one is always free to look under the hood to probe the model more deeply.For example, consider running this code on your own, identifying what it is plotting and what you can learn about your model as a result: plot(as.matrix(attributes(egmme.sim)$stats)).

Returning to the elements directly included in the model, we should also check to make sure that our mean duration is what we specified (10 time steps).

This time we’ll use a different approach, using as.data.frame, which, when applied to an object of class networkDynamic, generates a timed edgelist. From this we can directly calculate the mean. We’ll show that this produces the same result as the tsna edgeDuration function.

# create dataFrame for direct estimation
egmme.sim.df <- as.data.frame(egmme.sim)
names(egmme.sim.df)
[1] "onset"             "terminus"          "tail"             
[4] "head"              "onset.censored"    "terminus.censored"
[7] "duration"          "edge.id"          
egmme.sim.df[1,]
  onset terminus tail head onset.censored terminus.censored duration edge.id
1     0       13    3    5           TRUE             FALSE       13       1
cbind(directEst = mean(egmme.sim.df$duration),
      ndEst = mean(edgeDuration(egmme.sim, 
                                mode = 'duration', 
                                subject = 'spells')))
     directEst    ndEst
[1,]  9.896138 9.896138

Although right-censoring is present for some edges in our simulation, with a mean duration of 10 time steps and a simulation 1000 time steps long, the effect of censoring on our observed mean duration should be small, and we see above that it is.

EGMME approximation

An edge dissolution approximation (EDA) approach for ties with long durations

We can show (Carnegie et al. 2015, Klumb et al. under review) that a good set of starting values for the estimation of the formation model is as follows:

  1. Fit the terms in the formation model using a static ERGM on the cross-sectional network; then

  2. Subtract the values of either the dissolution coefficients themselves (Carnegie et al. 2015) or a slightly adjusted version of them (Klumb et al. under review, see below for adjustment details) from the estimated coefficients for the corresponding terms in the cross-sectional ERGM. The latter is a better fit for sparse networks, and the former for dense ones. (For terms present in the dissolution model but not the formation model, one subtracts them from the implicit 0 coefficient).

The result is a vector of parameter values that are a reasonable place to start the MCMC chain for the estimation of the formation model. This is in fact what the tergm estimation code does by default for this type of model.

In fact … when mean relational duration is very long, this approximation is so good that it may not be necessary to run a STERGM estimation at all.

This turns out to be quite useful, since models with long mean duration are precisely the ones that are the slowest and most difficult to fit using EGMME. That’s because, with long durations, very few ties dissolve at each MCMC step (toggle), so the fitting algorithm gets very little information to update the estimates, and needs many (many) more steps to accumulate that information.

Again, the equation from epidemiology sheds light on why this works :

\[ incidence \approx prevalence \div duration \]

The edge offset for the dissolution/persistence model gives us log-odds that map onto duration. Fitting the cross-sectional ergm gives us log-odds for prevalence. To estimate incidence, we subtract the duration from prevalence, rather than divide, since we are working on a log scale.

It bears repeating that the terms in your dissolution model must be a subset of the terms in your formation model for you to be able to take advantage of this approximation.

To illustrate, let us reconsider Example 2, but with a mean relational duration of 100 time steps. And this time, we’ll fit both the Persist() and Diss() versions of the model to demonstrate.

theta.persist.100 <- log(99)
theta.diss.100 <- -theta.persist.100

First, we treat the formation process as if it were a stand-alone cross-sectional model, and estimate it using a standard cross-sectional ERGM. (We fit this same formation model in an earlier call to tergm, so will snip the output here):

ergm.fit <- ergm(flobusiness ~ edges + gwesp(0, fixed = T))
summary(ergm.fit)
Call:
ergm(formula = flobusiness ~ edges + gwesp(0, fixed = T))

Monte Carlo Maximum Likelihood Results:

              Estimate Std. Error MCMC % z value Pr(>|z|)    
edges          -3.3595     0.6382      0  -5.264  < 1e-04 ***
gwesp.fixed.0   1.5893     0.5960      0   2.667  0.00766 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

     Null Deviance: 166.36  on 120  degrees of freedom
 Residual Deviance:  77.79  on 118  degrees of freedom
 
AIC: 81.79  BIC: 87.37  (Smaller is better. MC Std. Err. = 0.1775)
theta.form <- coef(ergm.fit)
theta.form
        edges gwesp.fixed.0 
    -3.359524      1.589315 

Next, we subtract the log of the durations from the corresponding terms (adjusted if necessary for sparse networks) in the formation model. Specifically, theta.persist = \(\log{D-1}\) for mean relational duration; for dense networks, we subtract \(\log{D-1}\) from the formation edges coefficient in the formation model, while for sparse networks, we subtract \(\log{D}\). Our network density is about 0.125, so we will use the sparse correction.

In this example, the dissolution model contains only an edges term, so this coefficient should be subtracted from the starting value for the edges term in the formation model.

theta.form[1] <- theta.form[1] - log(100)
theta.form
        edges gwesp.fixed.0 
    -7.964694      1.589315 

How well does this approximation do in capturing our desired dynamic network properties? First, we can simulate from it – here is where we switch back to a tergm simulation, with a tergm formula:

## Form + Persist
tergm.sim.fp <- simulate(
  flobusiness ~
    Form(~ edges + gwesp(0,fixed=T)) +
    Persist(~ edges),
  monitor = "all",
  coef = c(theta.form, theta.persist.100),
  time.slices = 10000,
  dynamic = TRUE)

Then compare the results for cross-sectional network structure.

## Compare
cbind(Observed = summary(flobusiness ~ edges + gwesp(0,fixed = T)),
      Simulated = colMeans(attributes(tergm.sim.fp)$stats)[1:2])
              Observed Simulated
edges               15   15.7941
gwesp.fixed.0       12   12.8100

And recovery of the tie duration

cbind(Observed = 100,
      Simulated = mean(edgeDuration(tergm.sim.fp, 
                                  mode="duration", 
                                  subject="spells"))
)
     Observed Simulated
[1,]      100  100.7372

Additional functionality

One of the most important extensions to tergm functionality is the ability to estimate models based on egocentrically sampled network data. This makes it possible to start with data on a single, cross-sectional, egocentrically sampled network, plus tie duration, estimate a tergm, and use the fitted model to simulate complete dynamic networks over time. For more information, see:

All of the packages reviewed in this tutorial have additional functionality, which you can learn about and explore through the use of R’s many help features.

If you begin to use them in depth, you will likely have further questions. If so, we encourage you to join the Statnet users’ group (https://mailman13.u.washington.edu/mailman/listinfo/statnet_help), where you can then post your questions (and possibly answer others). You may also encounter bugs; please use the same place to report them.


References

Krivitsky, P.N., Handcock, M.S,(2014). A separable model for dynamic networks JRSS Series B-Statistical Methodology, 76 (1):29-46; 10.1111/rssb.12014 JAN 2014

Krivitsky, P. N., Handcock, M. S., & Morris, M. (2011). Adjusting for network size and composition effects in exponential-family random graph models. Statistical Methodology, 8(4), 319-339. doi:10.1016/j.stamet.2011.01.005

Snijders, T. A. B., van de Bunt, G. G., & Steglich, C. E. G. (2010). Introduction to stochastic actor-based models for network dynamics. Social Networks, 32(1), 44-60. doi:http://dx.doi.org/10.1016/j.socnet.2009.02.004

Butts, C. T. (2008). A relational event framework for social action. Sociological Methodology, 38(1), 155-200. doi:10.1111/j.1467-9531.2008.00203.

Hanneke, S., Fu, W., & Xing, E. P. (2010) Discrete temporal models of social networks. Electron. J. Statist. 4 , 585–605. http://projecteuclid.org/euclid.ejs/1276694116.

Almquist, Z. W., & Butts, C. T. (2014). Logistic Network Regression for Scalable Analysis of Networks with Joint Edge/Vertex Dynamics. Sociological Methodology, 44(1), 273-321. doi:doi:10.1177/0081175013520159

Krivitsky, P. N., & Morris, M. (2017). Inference for social network models from egocentrically sampled data, with application to understanding persistent racial disparities in HIV prevalence in the US. Annals of Applied Statistics, 11(1), 427-455. doi:10.1214/16-aoas1010

Carnegie, N. B., Krivitsky, P. N., Hunter, D. R., & Goodreau, S. M. (2015). An approximation method for improving dynamic network model fitting. Journal of Computational and Graphical Statistics, 24(2), 502-519. doi:10.1080/10618600.2014.903087.

Klumb, C., Morris, M., Goodreau, S. M., & Jenness, S. M. (under review). Approximations for STERGMs based on cross-sectional data. Journal of Computational and Graphical Statistics.

Appendix A: Separable models (STERGMs)

Intuition

The separable model was introduced in Krivitsky and Handcock (2010). “Separable” here means that formation is assumed to be independent of dissolution within time step, and Markov dependent between steps. This allows the factors that influence formation to be different than those that influence dissolution.

Allowing the formation model to be different than the dissolution model is useful in many contexts. Take friendships. It seems intuitive that the factors influencing who becomes friends with whom, out of the set of people who aren’t already) are likely to be different than the factors affecting who stops liking whom, out of the set of people currently in relationships). Any reasonable model of formation would need to include a variety of homophily parameters (mixing on age, for example). Friendship dissolution may or may not. (Conditional on being friends, does a difference in age affect the probability that your friendship ends? Perhaps, but probably not as fundamentally or as strongly as for formation).

In thinking about how STERGMs work, and the difference between the prevalence of ties in the cross section, and the incidence of ties in a temporal data set, it can be helpful to think of the approximation commonly used in epidemiology to consider basic disease dynamics:

\[ prevalence = incidence \times duration \]

To translate this to dynamic networks: the expression above says that the number of ties present in the cross-section (prevalence) is a function of the rate at which they form (incidence) and the rate at which they dissolve (1/duration). The faster ties form, the more ties will be present in the cross-section, and the more slowly they form, the fewer will be present. The slower ties dissolve, the longer the duration, the more ties will be present in the cross-section, and the reverse (faster/shorter/fewer) again holds. The cross-sectional prevalence of ties is determined by both processes.

This same concept extends to other network configurations, for example triangles—the faster that triangles are formed and the slower that they’re dissolved, the more that will be present in the cross-section.

ERGMs are models for the prevalence of ties; they do not represent the implicit rates of incidence and duration, they simply model the net result.

STERGMs are models that explicitly represent the incidence and duration processes.

The two equations governing a STERGM are commonly called the formation equation and the dissolution (or persistence) equation, respectively:

\(\ln{\frac{P(Y_{ij,t+1} = 1 \mid y^{c}_{ij}, Y_{ij,t} = 0)}{P(Y_{ij,t+1} = 0\mid y^{c}_{ij}, Y_{ij,t} = 0)}} = \theta^+ \delta(g^+(y_{ij}))\)


\(\ln{\frac{P(Y_{ij,t+1} = 1 \mid y^{c}_{ij}, Y_{ij,t} = 1)}{P(Y_{ij,t+1} = 0\mid y^{c}_{ij}, Y_{ij,t} = 1)}} = \theta^- \delta(g^-(y_{ij}))\)


These parallel the traditional cross-sectional ERGM. We have simply:

  • added a time index to the tie values

  • added in a new conditional. In the formation equation, the expression is conditional on the tie not existing at the prior time step, and in the dissolution equation it is conditional on the tie existing; and

  • defined two \(\theta\) and \(g\) vectors instead of just one. Now there are \(\theta^+\) and \(g^+(y)_{ij}\), reflecting the coefficients and statistics in the formation model, and \(\theta^-\) and \(g^-(y)_{ij}\) reflecting those in the dissolution model.


Note that for the dissolution model, the \(P(Y_{ij,t+1} = 1)\) is in the numerator and the \(P(Y_{ij,t+1} = 0)\) is in the denominator. This makes the mathematics parallel to that of the formation model; however, it also means the “dissolution” model is actually a “persistence” model. The probability of dissolution is simply 1 - persistence, so the model can be interpreted in both ways.


When a model is separable, estimation at each step of the MCMC chain proceeds by sending off all empty dyads to be considered for formation (conditioning on the ties that exist), and sending off all the paired dyads to be considered for dissolution (conditioning on the empty dyads), and these two processes proceed independently during that step.

Visually, we can sum this up as:

Formal representation

To understand STERGMs formally, we first review the ERGM framework for cross-sectional or static networks. Let \(\mathbb{Y}\subseteq \{1,\dotsc,n\}^2\) be the set of potential relations (dyads) among \(n\) nodes, ordered for directed networks and unordered for undirected. We can represent a network \(\mathbf{y}\) as a set of ties, with the set of possible sets of ties, \(\mathcal{Y}\subseteq 2^\mathbb{Y}\), being the sample space: \(\mathbf{y} \in \mathcal{Y}\). Let \(\mathbf{y}_{ij}\) be 1 if \((i,j)\in\mathbf{y}\) — a relation of interest exists from \(i\) to \(j\) — and 0 otherwise.

The network also has an associated covariate array \(\mathbf{X}\) containing attributes of the nodes, the dyads, or both. An exponential-family random graph model (ERGM) represents the pmf of \(\mathbf{Y}\) as a function of a \(p\)-vector of network statistics \(g(\mathbf{Y},\mathbf{X})\), with parameters \(\theta \in \mathbb{R}^p\), as follows:

\(\mbox{Pr}\left(\mathbf{Y} = \mathbf{y} \mid \mathbf{X}\right) = \frac{\exp\left\{\theta\cdot g(\mathbf{y}, \mathbf{X})\right\} } {k(\theta, \mathbf{X}, \mathcal{Y})},\)


where the normalizing constant \(k(\theta, \mathbf{X}, \mathcal{Y}) = \sum\limits_{\mathbf{y}' \in \mathcal{Y}}\exp\left\{\theta\cdot g(\mathbf{y}', \mathbf{X})\right\}\) is a summation over the space of possible networks on \(n\) nodes, \(\mathcal{Y}\). Where \(\mathcal{Y}\) and \(\mathbf{X}\) are held constant, as in a typical cross-sectional model, they may be suppressed in the notation. Here, on the other hand, the dependence on \(\mathcal{Y}\) and \(\mathbf{X}\) is made explicit.

In modeling the transition from a network \(\mathbf{Y}^{t}\) at time \(t\) to a network \(\mathbf{Y}^{t+1}\) at time \(t+1\), the separable temporal ERGM assumes that the formation and dissolution of ties occur independently from each other within each time step, with each half of the process modeled as an ERGM. For two networks (sets of ties) \(\mathbf{y},\mathbf{y}'\in \mathcal{Y}\), let \(\mathbf{y} \supseteq \mathbf{y}'\) if any tie present in \(\mathbf{y}'\) is also present in \(\mathbf{y}\). Define \(\mathcal{Y}^+(\mathbf{y}) = \{\mathbf{y}'\in\mathcal{Y}:\mathbf{y}'\supseteq\mathbf{y}\}\), the networks that can be constructed by forming ties in \(\mathbf{y}\); and \(\mathcal{Y}^-(\mathbf{y}) = \{\mathbf{y}'\in\mathcal{Y}:\mathbf{y}'\subseteq\mathbf{y}\}\), the networks that can be constructed dissolving ties in \(\mathbf{y}\).

Given \(\mathbf{y}^{t}\), a formation network \(\mathbf{Y}^+\) is generated from an ERGM controlled by a \(p\)-vector of formation parameters \(\theta^+\) and formation statistics \(g^+(\mathbf{y}^+, \mathbf{X})\), conditional on only adding ties:

\(\Pr\left(\mathbf{Y}^+ = \mathbf{y}^+\mid \mathbf{Y}^{t};\theta^+\right) = \frac{\exp\left\{\theta^+\cdot g^+(\mathbf{y}^+, \mathbf{X})\right\} } {k\left(\theta^+, \mathbf{X}, \mathcal{Y}^+(\mathbf{Y}^{t})\right)}, \quad \mathbf{y}^+ \in \mathcal{Y}^+(\mathbf{y}^{t})\).


A dissolution network \(\mathbf{Y}^-\) is simultaneously generated from an ERGM controlled by a (possibly different) \(q\)-vector of dissolution parameters \(\theta^-\) and corresponding statistics \(g^-(\mathbf{y}^-, \mathbf{X})\), conditional on only dissolving ties from \(\mathbf{y}^{t}\), as follows:

\(\Pr\left(\mathbf{Y}^- = \mathbf{y}^-\mid \mathbf{Y}^{t};\theta^-\right) = \frac{\exp\left\{\theta^-\cdot g^-(\mathbf{y}^-, \mathbf{X})\right\} } {k\left(\theta^-, \mathbf{X}, \mathcal{Y}^-(\mathbf{Y}^{t})\right)}, \quad \mathbf{y}^- \in \mathcal{Y}^-(\mathbf{y}^{t}).\)


The cross-sectional network at time \(t+1\) is then constructed by applying the changes in \(\mathbf{Y}^+\) and \(\mathbf{Y}^-\) to \(\mathbf{y}^{t}\), as follows: \(\mathbf{Y}^{t+1} = \mathbf{Y}^{t}\cup (\mathbf{Y}^+ - \mathbf{Y}^{t}) \, - \, ( \mathbf{Y}^{t} - \mathbf{Y}^-).\) which simplifies to either: \(\mathbf{Y}^{t+1} = \mathbf{Y}^+ - (\mathbf{Y}^{t} - \mathbf{Y}^-)\) \(\mathbf{Y}^{t+1} = \mathbf{Y}^-\cup (\mathbf{Y}^+ - \mathbf{Y}^{t})\)

Independence: within vs. between timesteps

STERGMs assume that the formation and dissolution processes are independent of each other within the same time step.

This does not mean that they will be independent across time; and in fact, for any dyadic dependent model, they will not be. To see this point, consider a romantic relationship example with:

     Form(~ edges + degree(2:10))
     Diss(~ edges)

with increasingly negative parameters on the degree terms.

The negative parameters on higher order degree terms means that there is some underlying tendency for relational formation to occur, governed by the coefficient on the edges term, but it is reduced with each pre-existing tie that the two actors involved already have. In other words, there is a norm against being in multiple simultaneous romantic relationships.

However, dissolution in this model is homogeneous—all existing relationships have the same underlying dissolution probability at every time step. (The latter assumption is probably unrealistic; in practice, if someone just acquired a second partner, their first is likely to be at increased risk of dissoving their relation. We ignore this now for simplicity).


While formation and dissolution are independent within a time step, there is dependence between time steps.


Imagine that Chris and Pat are in a relationship at time t, and each of them has only this one partner. During the time between t and t+1, whether they break up does not depend on when either of them acquires a new partner, and vice versa.

  • If they do not break up during this time, then during the next time period between t+1 and t+2, the probability that either one forms a new partnership will be lower, because it is influenced by their existing partnership.

  • If they do break up during this time, then during the next time period between t+1 and t+2, the probability that either forms a new partnership will be higher, as neither is currently involved in a partnership.

If we had modeled dissolution as a function of degree, then a similar logic would induce dependence in the hazard of dissolution, as a function of partnerships formed in the prior step.

The simple implication is that formation and dissolution can be dependent in this framework, but that dependence occurs across time steps, not within.

Note that the length of the time step here is abritrary, and left to the user to define.
At the limit, a STERGM can approximate a continuous-time model by letting the time interval become very small—the only issue is computational limitations. The choice of interval length will therefore depend on context, and on whether the assumption of within-step independence makes sense in that context. In general, a larger time interval increases the impact of this assumption, while a smaller interval reduces the impact and makes the assumption easier to justify. With a time step of 1 month, if I start a second relationship today, the earliest I can break up with my first partner as a direct result of my new partnership is one month later. Shortening the time step to a day means I can break up a day later, rather than a month later, which is probably more reasonable. The tradeoff is that a shorter time interval means longer computation time for both model estimation and simulation.

Appendix B: Single Operator Models

The basic intuition for the term operators used in TERGMs is relatively clear – formation of ties (“form”) and dissolution of ties (“diss” or “persist”), cross-sectional equilibrium structure (“cross”) and overall churn (“change”). But, as is often the case with ERGMs, understanding how a specific term in a model influences the structure and dynamics of the network can require a bit more effort. In the TERGM context, the term operators add level of complexity, as they determine which dyads are included in the calculations and which ties are counted by a model term. An “edges” term in an ERGM always has the same meaning: the count of ties in the network. But the meaning of an “edges” term in a TERGM depends on the term operator.

The best way to understand how model terms work in each of the term operators is to start with the simplest possible examples: an “edges only” model using a single term operator, cycling through to each operator to see how this term changes meaning, and what implication that has for the predicted dynamic network. That is the approach we take below.


Approach

We work with 2 panels of the Sampson data to:

  1. Fit and simulate from the single Operator(~edges) models, to see what they produce in equilibrium.

  2. Verify that the estimated coefficient on the edges term = logit(p(component change))

The probability of tie component changes in these models is easy to calculate by hand, so it is easy to verify the relationship to the estimated coefficient.

Component Change probability from t1 to t2
form (ties formed) / (empty dyads t1)
diss (ties dissolved) / (ties t1)
cross density of network at t2
change (changed dyads) / (all dyads)

Setup

library(tergm)
#library(tsna)
library(dplyr)

sessioninfo::package_info(pkgs = c("network",
                                   "ergm", "tergm"),
                          dependencies = FALSE)
 package * version date (UTC) lib source
 ergm    * 4.5.0   2023-05-28 [1] CRAN (R 4.3.1)
 network * 1.18.1  2023-01-24 [1] CRAN (R 4.3.1)
 tergm   * 4.2.0   2023-05-30 [1] CRAN (R 4.3.1)

 [1] C:/Users/Steven Goodreau/AppData/Local/R/win-library/4.3
 [2] C:/Program Files/R/R-4.3.1/library

Data

data(samplk)
samp.series <- NetSeries(list(samplk1,samplk2))
samp.series
 Combined 1 networks on '.TimeID'/'.Time':
  1: n = 18, directed = TRUE, bipartite = FALSE, loops = FALSE

 Network attributes:
  vertices = 18 
  directed = TRUE 
  hyper = FALSE 
  loops = FALSE 
  multiple = FALSE 
  bipartite = FALSE 
  ergm:
            Length Class   Mode
constraints 2      formula call
 .PrevNet:
 Combined 1 networks on '.TimeID'/'.Time':
  1: n = 18, directed = TRUE, bipartite = FALSE, loops = FALSE

Network attributes:
  vertices = 18
  directed = TRUE
  hyper = FALSE
  loops = FALSE
  multiple = FALSE
  bipartite = FALSE
  ergm:
            Length Class  Mode
constraints 2      -none- call
 total edges = 55 
   missing edges = 0 
   non-missing edges = 55 
 density = 0.1797386 

Vertex attributes:

 .Time:
   integer valued attribute
   18 values

 .TimeID:
   integer valued attribute
   18 values

 cloisterville:
   logical valued attribute
   attribute summary:
   Mode   FALSE    TRUE 
logical      12       6 

 group:
   character valued attribute
   attribute summary:
   Loyal Outcasts    Turks Waverers 
       5        3        7        3 
  vertex.names:
   character valued attribute
   18 valid vertex names

No edge attributes

Network edgelist matrix:
      [,1] [,2]
 [1,]    1    3
 [2,]    1    5
 [3,]    1   14
 [4,]    2    1
 [5,]    2    7
 [6,]    2   14
 [7,]    3    1
 [8,]    3    2
 [9,]    3   17
[10,]    4    5
[11,]    4    6
[12,]    4   10
[13,]    5    4
[14,]    5   11
[15,]    5   13
[16,]    6    1
[17,]    6    4
[18,]    6    9
[19,]    7    2
[20,]    7    8
[21,]    7   16
[22,]    8    1
[23,]    8    2
[24,]    8    9
[25,]    9    5
[26,]    9    8
[27,]    9   16
[28,]   10    4
[29,]   10    8
[30,]   10   14
[31,]   11    5
[32,]   11    8
[33,]   11   14
[34,]   12    1
[35,]   12    2
[36,]   12   14
[37,]   13    5
[38,]   13    7
[39,]   13   18
[40,]   14    1
[41,]   14   11
[42,]   14   12
[43,]   14   15
[44,]   15    1
[45,]   15    2
[46,]   15   14
[47,]   16    1
[48,]   16    2
[49,]   16    7
[50,]   17    3
[51,]   17   13
[52,]   17   18
[53,]   18    1
[54,]   18    2
[55,]   18    7
  total edges= 57 
    missing edges= 0 
    non-missing edges= 57 

 Vertex attribute names: 
    .Time .TimeID cloisterville group vertex.names 

No edge attributes
samp.dyn <- networkDynamic(network.list = list(samplk1,samplk2), start=1)
Onsets and termini not specified, assuming each network in network.list should have a discrete spell of length 1
Argument base.net not specified, using first element of network.list instead
Created net.obs.period to describe network
 Network observation period info:
  Number of observation spells: 1 
  Maximal time range observed: 1 until 3 
  Temporal mode: discrete 
  Time unit: step 
  Suggested time increment: 1 

Descriptives

Cross sectional stats and form/diss changes from tsna

samp.stats <- cbind(edges = tsna::tErgmStats(samp.dyn, "~edges"),
                    form = tsna::tEdgeFormation(samp.dyn),
                    diss = tsna::tEdgeDissolution(samp.dyn))

samp.stats
Time Series:
Start = 1 
End = 3 
Frequency = 1 
  edges form diss
1    55   55    0
2    57   22   20
3     0    0   57
dyads = network.dyadcount(samplk1)
type <- c("form", "diss", "cross", "change")

prob.form = samp.stats[2,"form"]/(dyads-samp.stats[1,"edges"])
prob.diss = samp.stats[2,"diss"]/network.edgecount(samplk1)
prob.cross = network.edgecount(samplk2)/dyads
prob.change = network.edgecount(xor(samplk1, samplk2))/dyads

def.form = "Fraction of empty dyads at t1 that formed a tie by t2"
def.diss = "Fraction of ties at t1 that dissolved by t2"
def.cross = "Density at t2 (probability of a tie)"
def.change = "Fraction of all dyads at t1 that changed state by t2"

data.frame(Component = type,
           Definition = c(def.form, def.diss, def.cross, def.change),
           Probability = c(prob.form, prob.diss, prob.cross, prob.change)) %>%
  kableExtra::kable(caption = "Observed probabilities of tie change components in Sampson data", 
        digits=3) %>%
  kableExtra::kable_styling(full_width=F,
                            bootstrap_options = c("striped"))
Observed probabilities of tie change components in Sampson data
Component Definition Probability
form Fraction of empty dyads at t1 that formed a tie by t2 0.088
diss Fraction of ties at t1 that dissolved by t2 0.364
cross Density at t2 (probability of a tie) 0.186
change Fraction of all dyads at t1 that changed state by t2 0.137
# target edgecount
target.edges <- summary(samp.series ~ edges)

Single Operator Models

Form

This model sets the tie formation rates based on the observed probability of tie formation from t1 to t2. But the other free parameter is not set, so the effective tie dissolution coef is 0, which means ties dissolve with probability 0.5.

We saw from the descriptives above that the observed probability of a tie dissolving from t1 to t2 is 0.36). So, what equilibrium density will be generated by this model? Higher? Lower? Or the same as the observed density in the Sampson data?

Fit

form.fit <- tergm(
  samp.series ~ Form(~edges),
  estimate = "CMLE")

summary(form.fit)
Call:
tergm(formula = samp.series ~ Form(~edges), estimate = "CMLE")

Conditional Maximum Likelihood Results:

              Estimate Std. Error MCMC % z value Pr(>|z|)    
Form(1)~edges  -2.3427     0.2232      0   -10.5   <1e-04 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

     Null Deviance: 424.2  on 306  degrees of freedom
 Residual Deviance: 225.4  on 305  degrees of freedom
 
AIC: 227.4  BIC: 231.1  (Smaller is better. MC Std. Err. = 0)

Simulate

The net result is a lower predicted equilibrium tie count, compared to t2 (57). This suggests that the observed Sampson data are not consistent with a tie dissolution probability of 50%. To reproduce the observed density with this formation rate, one needs a lower dissolution rate than 50%. And to get that, you would need to add a diss operator to the TERGM specification.

form.sim <- simulate(form.fit, nsim = 1, 
                    time.slices = 1000, 
                    nw.start = "first",
                    monitor = ~edges,
                    stats = T,
                    output = "stats")

plot(as.numeric(form.sim$stats), type="l",
     main = "Cross-sectional edgecount in simulated network timeseries",
     sub = "Model: Form(~edges)",
     ylab="edges") 
abline(h=target.edges, col="red")

print(form.mon <- cbind(obs = target.edges,
                        sim = colMeans(form.sim$stats)))
      obs    sim
edges  57 45.279

Diss

This model sets the tie dissolution rates based on the observed probability of tie formation from t1 to t2. But the other free parameter is not set, so the effective tie formation coef is 0, which means ties form with probability 0.5.

We saw from the descriptives above that the observed probability of a tie forming from t1 to t2 is 0.09). So, what equilibrium density will be generated by this model? Higher? Lower? Or the same as the observed density in the Sampson data?

Fit

diss.fit <- tergm(
  samp.series ~ Diss(~edges),
  estimate = "CMLE")

summary(diss.fit)
Call:
tergm(formula = samp.series ~ Diss(~edges), estimate = "CMLE")

Conditional Maximum Likelihood Results:

              Estimate Std. Error MCMC % z value Pr(>|z|)  
Diss(1)~edges  -0.5596     0.2803      0  -1.996   0.0459 *
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

     Null Deviance: 424.2  on 306  degrees of freedom
 Residual Deviance: 420.1  on 305  degrees of freedom
 
AIC: 422.1  BIC: 425.8  (Smaller is better. MC Std. Err. = 0)

Simulate

The net result is a much higher predicted equilibrium tie count, compared to t2 (57). This suggests implied formation rate of 50% is too high. Here you would need to add a form operator to the TERGM model specification to control the formation rate, in order to reproduce the observed density.

diss.sim <- simulate(diss.fit, nsim = 1, 
                    time.slices = 1000, 
                    nw.start = "first",
                    monitor = ~edges,
                    stats = T,
                    output = "stats")


plot(as.numeric(diss.sim$stats), type="l",
     main = "Cross-sectional edgecount in simulated network timeseries",
     sub = "Model: Diss(~edges)",
     ylab="edges",
     ylim = c(0, 200)) 
abline(h=target.edges, col="red")

print(diss.mon <- cbind(obs = target.edges,
                        sim = colMeans(diss.sim$stats)))
      obs     sim
edges  57 176.697

Cross

This model sets the target cross-sectional tie count to the t2 observed value. It is the one operator that does not explicitly condition on the state of the dyad at t1. With only two time steps of data, this is equivalent to fitting an ergm on the t2 network.

So, what equilibrium density will be generated by this model? Higher? Lower? Or the same as observed at t2?

Fit

cross.fit <- tergm(
  samp.series ~
    Cross(~edges),
  estimate = "CMLE")

summary(cross.fit)
Call:
tergm(formula = samp.series ~ Cross(~edges), estimate = "CMLE")

Conditional Maximum Likelihood Results:

               Estimate Std. Error MCMC % z value Pr(>|z|)    
Cross(1)~edges  -1.4744     0.1468      0  -10.04   <1e-04 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

     Null Deviance: 424.2  on 306  degrees of freedom
 Residual Deviance: 294.2  on 305  degrees of freedom
 
AIC: 296.2  BIC: 300  (Smaller is better. MC Std. Err. = 0)

Simulate

Here, the equilibrium tie count stochastically reproduces the t2 value and the observed density is preserved.

The simulation effectively operates like a cross-sectional ergm: drawing a network from the distribution specified by the model at each time step, with no information used from the time step before. The way the changes are distributed between “formations” and “dissolutions” is controlled by the coefficient on the edges term: as in an ergm, it represents the log-odds of a tie (here in the t2 network), so it will reproduce the density observed at t2.

cross.sim <- simulate(cross.fit, nsim = 1, 
                    time.slices = 1000, 
                    nw.start = "first",
                    monitor = ~edges,
                    stats = T,
                    output = "stats")

plot(as.numeric(cross.sim$stats), type="l",
     main = "Cross-sectional edgecount in simulated network timeseries",
     sub = "Model: Cross(~edges)",
     ylab="edges") 
abline(h=target.edges, col="red")

print(cross.mon <- cbind(obs = target.edges,
                         sim = colMeans(cross.sim$stats)))
      obs    sim
edges  57 56.956

Change

This model sets the dyad change rates based on the observed probability of a dyad changing state from t1 to t2. Dyads are selected at random and changed with this probability – there is no bias towards either formation or dissolution.

What equilibrium density do you think this model will generate? Higher? Lower? Same as observed?

Fit

change.fit <- tergm(
  samp.series ~
  Change(~edges),
  estimate = "CMLE")

summary(change.fit)
Call:
tergm(formula = samp.series ~ Change(~edges), estimate = "CMLE")

Conditional Maximum Likelihood Results:

                Estimate Std. Error MCMC % z value Pr(>|z|)    
Change(1)~edges  -1.8383     0.1661      0  -11.07   <1e-04 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

     Null Deviance: 424.2  on 306  degrees of freedom
 Residual Deviance: 244.8  on 305  degrees of freedom
 
AIC: 246.8  BIC: 250.5  (Smaller is better. MC Std. Err. = 0)

Simulate

The equilibrium density for this model is 0.5, well above the observed density at t2 (0.19).

The changes are distributed at random in this model.

  • If the starting network has density less than 0.5, more of the dyads selected for toggle will be empty, so there are more potential formations and the network will become more dense over time.

  • If the starting density is greater than 0.5, more of the dyads selected will be tied, so there are more potential dissolutions and the network will become more sparse over time.

In both cases, the density moves towards 50%, and is stable once it gets there.

change.sim <- simulate(change.fit, nsim = 1, 
                    time.slices = 1000, 
                    nw.start = "first",
                    monitor = ~edges,
                    stats = T,
                    output = "stats")


plot(as.numeric(change.sim$stats), type="l",
     ylim = c(0, 200), # so the target line is visible
     main = "Cross-sectional edgecount in simulated network timeseries",
     sub = "Model: Change(~edges)",
     ylab="edges") 
abline(h=target.edges, col="red")

print(change.mon <- cbind(obs = target.edges,
                          sim = colMeans(change.sim$stats)))
      obs     sim
edges  57 153.195

Compare coefficients

Here, we verify that the estimated exp(coefficient) values are equal to the odds of each tie component as calculated by hand.

As shown in the table below, they are equal, which means we can interpret the coefficients in terms of the probabilities of each change component. The coefficients are on the log-odds scale, so to obtain the corresponding probability, we transform using p(tie change component) = 1/(1+exp(coef))).

As with ergm coefficients, these tergm coefficients can be interpreted in terms of the conditional probability at the dyad level (conditioning on the state of the rest of the network).

In the dynamic context, this is the probability of a dyad changing state, if that change satisfies the definition of this component operator: a formation, dissolution, cross-sectional tie or a change in state.

odds.form = prob.form / (1-prob.form)
odds.diss = prob.diss / (1-prob.diss)
odds.cross = prob.cross / (1-prob.cross)
odds.change = prob.change / (1-prob.change)

ecoef.form = exp(coef(form.fit))
ecoef.diss = exp(coef(diss.fit))
ecoef.cross = exp(coef(cross.fit))
ecoef.change = exp(coef(change.fit))

data.frame(
  exp.coef = c(ecoef.form, ecoef.diss, ecoef.cross, ecoef.change),
  handcalc.odds = c(odds.form, odds.diss, odds.cross, odds.change),
  handcalc.prob = c(prob.form, prob.diss, prob.cross, prob.change)) %>%
  kableExtra::kable(
    caption = "Estimated exp(coef) vs. hand calculated odds and probabilities", 
    digits=3) %>%
  kableExtra::kable_styling(bootstrap_options = c("striped"))
Estimated exp(coef) vs. hand calculated odds and probabilities
exp.coef handcalc.odds handcalc.prob
Form(1)~edges 0.096 0.096 0.088
Diss(1)~edges 0.571 0.571 0.364
Cross(1)~edges 0.229 0.229 0.186
Change(1)~edges 0.159 0.159 0.137
coef <- c(NA_real_,
          coef(form.fit),
          coef(diss.fit),
          coef(cross.fit),
          coef(change.fit))
mon.edges <- c(form.mon[1],
               form.mon[2],
               diss.mon[2],
               cross.mon[2],
               change.mon[2])
names(coef)[1] <- "obs"

data.frame(coef=round(coef,1), edges=round(mon.edges)) %>% 
  kableExtra::kable(caption = "Compare coefs and obs to equilibrium edgecounts", 
        digits=3) %>%
  kableExtra::kable_styling(bootstrap_options = c("striped"))
Compare coefs and obs to equilibrium edgecounts
coef edges
obs NA 57
Form(1)~edges -2.3 45
Diss(1)~edges -0.6 177
Cross(1)~edges -1.5 57
Change(1)~edges -1.8 153