ergm-js — simulating from an ERGM

A small, dependency-light Exponential Random Graph Model simulator, for teaching and for slides -- not an estimation package. See README.md for the full docs.

Drag the sliders and hit Run. Each frame proposes a random directed pair (i, j) and adds or removes that one tie based on how much it would change the network's edge count, homophilous-tie count, and reciprocated-tie count -- weighted by the three θ sliders. No fitting, no data: this is what an ERGM generates for a given θ, not what it infers from an observed network.

What to look for

SliderEffect
θ edgesOverall density. Very negative → sparse; near 0 → dense.
θ nodematchHomophily. Push it up and the two colored groups visibly pull apart into separate clusters as same-group ties dominate; cross-group ties thin out.
θ mutualReciprocity. Push it up and arrowheads start pairing up -- most ties become two-way, and reciprocated pairs sit noticeably closer together.
n / mean out-degreeRebuilds the network with new settings as soon as you release the slider -- no extra click needed.

The layout is a small live force simulation: nodes repel each other, ties pull their endpoints together, and it keeps resettling as ties come and go. Pass layout: "circle" to ERGMWidget.mount() for the original fixed two-arc layout instead -- see README.md.

Use it on your own page

<div id="demo"></div>

<script src="vendor/graphology.umd.min.js"></script>
<script src="vendor/sigma.min.js"></script>
<script src="src/ergm.js"></script>
<script src="src/ergm-widget.js"></script>
<script>
  ERGMWidget.mount(document.getElementById("demo"), {
    n: 40,
    meanDegree: 4,
    model: ["edges", "nodematch", "mutual"],
    theta: { edges: -2.5, nodematch: 1.5, mutual: 1 },
  });
</script>

See README.md for the full API, the model itself, and how to embed this in reveal.js / Quarto.