nwmotifs

4-node undirected motif/graphlet census

Syntax

nwmotifs
[netname]
[,
silent
plot
name(string)
onemode
six:node
gen:erate(stub)
replace
mat:rix(name)
norm:alise
posn:orm(type)]
   
silent Suppress display of results
plot Draw a bar chart of the 7 category counts
name(string) Name for the graph created by plot; default = motifs
onemode Two-mode network: the 4-node census of the bipartite graph read as a one-mode graph, instead of the bipartite motifs (the default)
six:node Two-mode network: count the motifs of six nodes too (44 motifs and 148 node positions instead of 17 and 46)
gen:erate(stub) Two-mode network: store the node position counts in the variables stub1, stub2, …
replace Two-mode network: replace existing variables
mat:rix(name) Two-mode network: store the node position counts in a Stata matrix
norm:alise Two-mode network: add the four normalised frequencies of bmotif::mcount to the motif table
posn:orm(type) Two-mode network: normalise the node position counts as bmotif::node_positions

Description

On a two-mode network nwmotifs counts the 17 bipartite motifs of two to five nodes (44 with sixnode) of Simmons et al. (2019), as bmotif does, and the positions of the nodes in them; the options for that form are described in nw2motifs, which is the same command under another name. onemode gives the 4-node census of the bipartite graph read as a one-mode graph.

nwmotifs classifies every induced 4-node subgraph of the network into one of 6 “motif” shapes (Milo et al. 2002’s own term for a small, recurring, structurally-distinct connectivity pattern), plus a residual bucket for the other, disconnected 4-node cases - the same “every case exhaustively accounted for” census convention nwtriads’s own 3-node MAN census already established one dimension down, generalized here to 4 nodes.

The 6 connected shapes, by increasing edge count:

  • path = a-b-c-d, an open 3-edge chain (degrees 1,2,2,1)
  • star = a tied to b, c, and d, with b/c/d mutually untied (degrees 3,1,1,1)
  • cycle = a-b-c-d-a, a closed 4-edge square (degrees 2,2,2,2)
  • paw = a triangle plus one pendant tie (degrees 3,2,2,1)
  • diamond = the complete graph on 4 nodes minus one edge (degrees 3,3,2,2)
  • k4 = the complete graph on 4 nodes (degrees 3,3,3,3)

Every other 4-node induced subgraph (empty, a single tie, either of the two 2-edge shapes, or a triangle plus an isolated 4th node) is disconnected and is reported under disconnected instead - none of these is a meaningful connected structural pattern in the motif sense. path+star+cycle+paw+diamond+k4+disconnected always sums to exactly the total number of 4-node combinations in the network.

Classified by (edge count, sorted degree sequence) alone - a COMPLETE invariant for 4-node graphs (every one of the 11 non-isomorphic 4-vertex graphs has its own unique combination of the two), so no general graph-isomorphism check is needed.

nwmotifs reports a plain census with no significance test of its own - it needs none: because every count is published as an ordinary r() scalar, nwcug’s existing stat()/rname() template machinery already works against it unmodified, the same “compose with existing infrastructure” pattern nwlambda uses with nwhierarchy. To test whether a shape is over- or under-represented relative to a random graph of the same size and density:

  • . nwcug mynet, stat(nwmotifs ##net##, silent) rname(cycle) condition(density)

substituting path/star/cycle/paw/diamond/k4 for whichever shape’s prevalence is of interest, and condition(census) for a directed network to hold the mutual/asymmetric/null dyad counts fixed instead of just density (see nwcug for the full set of conditioning/tail/reps options this test supports).

plot draws a bar chart of the 7 category counts, via this package’s own established preserve/rebuild-a-plotting-dataset/restore convention - the same one nwcug’s own plot option and nwtriads’s own plot option (its 3-node analogue) use. Grayscale by design, matching every other plot this package produces.

Network types

Directed: every tie is treated as undirected and a note is printed. Valued: tie values are ignored and a note is printed. Two-mode: two-mode form by default (option onemode for the one-mode computation) - the bipartite motifs of bmotif. Signed: not checked. See nwnetworktypes.

Limits

The census is not obtained by listing the n(n-1)(n-2)(n-3)/24 four-node sets. The numbers of stars, paths, 4-cycles, triangles with a pendant tie, diamonds and complete 4-sets are counted as subgraphs from the degrees, the triangles on each tie and the common neighbours of node pairs (time proportional to the number of ties times the largest degree), and turned into counts of induced subgraphs with the exact inclusion relations between the six connected shapes; the disconnected count is the remainder of the total. The result is identical to the enumeration. Measured in Stata/BE on a random network with 10 ties drawn per node: 300 / 1,000 / 5,000 nodes take 0.007 / 0.015 / 0.06 seconds. Counts are exact up to the size of a 64-bit integer; stored as Stata scalars they are exact up to 9 x 10^15 (about 20,000 nodes’ worth of four-node sets).

Examples

. nwwebuse florentine, nwclear
. nwmotifs flomarriage
. nwcug flomarriage, stat(nwmotifs ##net##, silent) rname(cycle) condition(density)

Stored results

Scalars

  • r(path) count of 4-node path (P4) subgraphs
  • r(star) count of 4-node star (K1,3) subgraphs
  • r(cycle) count of 4-node cycle (C4/square) subgraphs
  • r(paw) count of paw (triangle + pendant) subgraphs
  • r(diamond) count of diamond (K4 minus one edge) subgraphs
  • r(k4) count of complete-graph (K4) subgraphs
  • r(disconnected) count of every other, disconnected 4-node case

Macros

  • r(netname) name of the network

For a two-mode network (without onemode) the results are instead:

Scalars

  • r(sixnode) 1 if motifs of six nodes were counted, 0 otherwise
  • r(n_mode1) number of nodes in mode 1
  • r(n_mode2) number of nodes in mode 2

Macros

  • r(netname) name of the network
  • r(posnorm) normalisation of the node position counts (posnorm(); none by default)

Matrices

  • r(motifs) one row per motif: columns motif, nodes and frequency
  • (with normalise also the four normalised frequencies)

References

Milo, R., Shen-Orr, S., Itzkovitz, S., Kashtan, N., Chklovskii, D., Alon, U. (2002). Network Motifs: Simple Building Blocks of Complex Networks. Science 298(5594), 824-827.

See also


nwcommands version 3.25.0, 14 November 2026 (check your installed version)


Back to top

nwcommands is free software under the GNU General Public License, version 3, as are the model packages nwsaom, nwergm, nwdynam and nwrem. Citing and licenses · Get help · GitHub. Issues with the core go to the nwcommands repository; issues with a model package go to that package's own repository.

This site uses Just the Docs, a documentation theme for Jekyll.