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 its older name. onemode gives the 4-node census of the bipartite graph read as a one-mode graph (the result of earlier releases).

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.

Examples

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

Supported network types

Binary: yes. Directed: the command still runs, but every tie is treated as undirected (a directed 4-node census has 218 distinct isomorphism classes and is not attempted here); a note is printed to this effect. Weighted: not applicable (a motif census is inherently a binary count). Signed: not checked. Two-mode: two-mode form by default - the bipartite motifs of Simmons et al. (2019; bmotif) and the positions of the nodes in them; onemode forces the 4-node census of the bipartite graph read as a one-mode graph (igraph::motifs); nw2motifs is an alias. Requires at least 4 nodes.

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

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.17.6, 9 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.