You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The tabulergm package provides an easy way to generate
publication-ready tables and explanatory summaries for
Exponential-Random Graph Family Models [ERGMs]. Users can generate
tables either directly from fitted models or by parsing a formula to
inspect the available terms and their metadata. Generated tables can be
incorporated into Quarto or RMarkdown documents, and can also be
exported as Markdown or LaTeX snippets for use in other projects.
The package includes a term dictionary with metadata for each term: a
short title, a plain-language description, a LaTeX definition, an
example figure, and – where the term has an identifiable source – a
citation. Figures are currently drawn using the
netplot package, but
users can also provide their own custom figure generation methods. Every
text field can be replaced on a per-table basis without editing the
dictionary (see Customizing term
metadata).
Future version of this package may extend its functionality to support
stochastic actor-oriented models (SAOMs) and other network modeling
frameworks.
Installation
# From CRAN
install.packages("tabulergm")
# Development version from GitHub# install.packages("remotes")remotes::install_github("gvegayon/tabulergm")
Example
Here is a simple example fitting an ERGM to the Florentine marriage
network and generating a summary table:
library(ergm)
library(tabulergm)
# Fit a simple ERGM
data(florentine)
model<- ergm(
flomarriage~edges+triangle,
control= control.ergm(seed=42)
)
# Parse the modelmodel_terms<- parse_ergm_model(model)
model_terms[, c("term", "title", "estimate", "se", "pvalue")]
#> term title estimate se pvalue#> 1 edges Number of edges -1.6507266 0.3179320 2.079634e-07#> 2 triangle Triangles 0.1082377 0.5183562 8.345969e-01
You can also export the table code and generated term figures into a
folder that can be copied into another paper or report project:
This writes Markdown and LaTeX table snippets plus a figures/ folder
with the copied image assets.
The term dictionary also includes mode-specific terms for bipartite
ERGMs. A formula is enough to inspect the available metadata before
fitting a model:
Titles and descriptions come from the term dictionary, falling back to
the ergm term database for terms the dictionary does not cover. Either
can be replaced for a single table with the override.* arguments,
which are keyed by term name:
custom<- tabulergm_table(
model,
include_title=TRUE,
override.title= c(edges="Density"),
override.desc= c(edges="Baseline propensity to form ties.")
)
custom[, c("term", "title")]
#> term title#> 1 edges (holland1981) Density#> 2 triangle (frank1986) Triangles
edges and triangle pick up (holland1981) and (frank1986) markers
because they carry citations in the term dictionary. The marker attaches
to the description when that column is shown and to the term otherwise,
so a citation is never silently dropped.
The same works for math, figure, and citation, and a single
override list can set several fields of several terms at once:
tabulergm_table(
model,
override=list(
edges=list(title="Density", desc="Baseline tie propensity."),
nodematch=list(citation="doi:10.1016/S0378-8733(01)00029-6")
)
)
Terms that carry a citation get a (key) marker next to their
description, and the matching reference is appended below the table.
Storing a DOI, arXiv id, or PubMed id (rather than a formatted
reference) lets readers pull the full citation into their own
bibliography software:
Summarizes how many partners tied nodes share, weighting each additional shared partner geometrically less than the last. Provides a better-behaved measure of transitive closure than a raw triangle count; the decay parameter controls how fast the weights fall off. (snijders2006; hunter2007)
triangle
$\sum_{i<j<k} y_{ij} y_{jk} y_{ik}$
Counts the sets of three mutually connected nodes, the basic measure of local clustering in an undirected network. (frank1986)
The default layout keeps one metadata component per column. For a
compact term dictionary, with_style_name_over_formula() stacks each
term title over its formula and moves the figure into a
Representation column. It retains model estimates and any metadata
columns you explicitly include:
Styled Markdown uses an HTML table so multi-line name/formula cells
render reliably in HTML-capable Markdown outputs. Use the plain style
for a portable pipe table in non-HTML targets. with_style_plain()
restores the original layout at any point in a pipeline.
Styled tables can also be saved or previewed directly:
The compact LaTeX export uses array, booktabs, and graphicx for
its multiline cells and figures.
Fitted-model tables round every numeric column (estimates, standard
errors, and p-values) to two decimal places by default while retaining
full-precision values in the attached table specification. Set
digits = NULL to display full precision, or choose a different number
of decimal places:
tabulergm_table(model, digits=3)
Compact-style presentation settings are also retained by the table
object, so they survive previews and exports. Column widths are
fractions of the table width and figure height is measured in inches;
omit either setting for automatic columns and the default width-based
figure size:
We can also embed the table in quarto/Rmarkdown. The table below covers
every term currently included in tabulergm’s term dictionary; terms
with both directed and undirected definitions (edges, gwesp,
gwdsp, isolates) display the undirected version:
Summarizes how many partners tied nodes share, weighting each additional shared partner geometrically less than the last. Provides a better-behaved measure of transitive closure than a raw triangle count; the decay parameter controls how fast the weights fall off. (snijders2006; hunter2007)
Summarizes shared partners over every dyad, tied or not, with geometrically decreasing weights. Commonly paired with gwesp to separate shared partnership from closure itself. (snijders2006; hunter2007)
Summarizes the degree distribution with geometrically decreasing weights. Captures whether ties concentrate on a few high-degree nodes or spread evenly, and stabilizes models that would otherwise degenerate. (snijders2006; hunter2007)
Alternating sum of the k-star counts, an equivalent parameterization of the geometrically weighted degree distribution used to model degree heterogeneity. (snijders2006; hunter2007)
nodematch
$\sum_{i<j} y_{ij} \mathbf{1}(x_i = x_j)$
Counts the ties joining nodes that share the same value of a categorical attribute, the standard measure of homophily. Setting diff = TRUE adds one statistic per attribute value (differential homophily). (wasserman1996; mcpherson2001)
Sums the absolute difference in a quantitative attribute across tied nodes. Negative estimates indicate homophily, since similar nodes contribute less.
edgecov
$\sum_{i<j} y_{ij} x_{ij}$
Sums a fixed dyad-level covariate over the observed ties, letting an external matrix such as distance or a previously observed network predict tie formation. (wasserman1996)
Summarizes the in-degree distribution with geometrically decreasing weights. Captures whether incoming ties concentrate on a few popular nodes or spread evenly across receivers. (hunter2007; robins2009)
Summarizes the out-degree distribution with geometrically decreasing weights. Captures whether outgoing ties concentrate on a few highly active nodes or spread evenly across senders. (hunter2007; robins2009)
nodeifactor
$\sum_{i \neq j} y_{ij} \mathbf{1}(x_j = k)$
Counts the incoming ties received by nodes at each level of a categorical attribute, measuring how popular nodes with that value are as receivers.
nodeofactor
$\sum_{i \neq j} y_{ij} \mathbf{1}(x_i = k)$
Counts the outgoing ties sent by nodes at each level of a categorical attribute, measuring how active nodes with that value are as senders.
kstar
$\sum_{i} \binom{\sum_{j \neq i} y_{ij}}{k}$
Counts the sets of k ties that share a common node, a Markov dependence measure of degree heterogeneity. Pass several values of k to include one statistic per star size. (frank1986)
istar
$\sum_{j} \binom{\sum_{i \neq j} y_{ij}}{k}$
Counts the sets of k incoming ties that share a common receiver, capturing the spread of in-degrees (popularity). Pass several values of k to include one statistic per star size. (wasserman1996)
ostar
$\sum_{i} \binom{\sum_{j \neq i} y_{ij}}{k}$
Counts the sets of k outgoing ties that share a common sender, capturing the spread of out-degrees (activity). Pass several values of k to include one statistic per star size. (wasserman1996)
Counts the nodes with two or more ties, the number of actors holding concurrent partnerships. Common in models of sexual networks and disease transmission.
Directed counterpart of the edgewise shared partner statistic, measuring transitive closure with geometrically decreasing weights. Outgoing two-paths are counted by default; the term’s type argument selects a different two-path orientation. (hunter2007; robins2009)
Directed counterpart of the dyadwise shared partner statistic, computed over every ordered dyad. Outgoing two-paths are counted by default; the term’s type argument selects a different two-path orientation. (hunter2007; robins2009)
Summarizes how many second-mode nodes each pair of first-mode nodes has in common, weighting additional shared partners geometrically less. (wang2009; hunter2007)
Summarizes how many first-mode nodes each pair of second-mode nodes has in common, weighting additional shared partners geometrically less. (wang2009; hunter2007)
Summarizes the degree distribution of first-mode nodes with geometrically decreasing weights. Captures whether ties to the second mode concentrate on a few highly active first-mode nodes or spread evenly across them. (wang2009; hunter2007)
Summarizes the degree distribution of second-mode nodes with geometrically decreasing weights. Captures whether ties from the first mode concentrate on a few popular second-mode nodes or spread evenly across them. (wang2009; hunter2007)
Counts the pairs of first-mode nodes that share an attribute value and are both tied to the same second-mode node. The alpha and beta discount parameters temper the count when nodes share many partners. (bomiriya2023)
Counts the pairs of second-mode nodes that share an attribute value and are both tied to the same first-mode node. The alpha and beta discount parameters temper the count when nodes share many partners. (bomiriya2023)
Counts the k-stars centered on a first-mode node with one attribute value whose second-mode neighbors all share another, capturing mixing and degree together.
Counts the k-stars centered on a second-mode node with one attribute value whose first-mode neighbors all share another, capturing mixing and degree together.
Note: Orange nodes indicate nodes with a focal attribute. Orange and
teal nodes represent nodes with different values of the focal attribute.
Square nodes represent nodes in the first mode and circle nodes in the
second mode.
Please note that the tabulergm project is released with a Contributor
Code of
Conduct. By
contributing to this project, you agree to abide by its terms.