nwkcomponents
Maximal k-component enumeration
Syntax
nwkcomponents
[netlist]
[,
k(int)
gen:erate(newvarname)
replace
nom:atrix
silent
force]
k(int) |
Minimum vertex connectivity required; default = 2 |
gen:erate(newvarname) |
Required. Name of the Stata variable that stores each node’s largest qualifying k-component size |
replace |
Replace existing variable |
nom:atrix |
Do not store r(kcomp_matrix); the gen:erate(newvarname) variable and r(kcomponents) are still returned |
silent |
Suppress display of results |
force |
Run the command although its estimated time is more than 2 minutes (it stops with r(484) otherwise) |
Description
nwkcomponents enumerates every maximal k-component (Kanevsky 1993) in the network(s) in netlist - a subgraph with vertex connectivity of at least k(int), meaning at least k(int) nodes would have to be removed from it to disconnect it (or reduce it to a single node). A k-component is a genuine strengthening of an ordinary connected component (which is just the k(int)=1 case - nwcomponents already implements that, more cheaply, via a simple reachability search rather than a connectivity computation): k(int)=2 excludes single cut-vertices/bridges that would fracture the group, k(int)=3 additionally excludes any 2-node cutset, and so on. This directly formalizes the intuition that a group connected only by a single “weak link” is less cohesive than one where several independent paths connect every pair of members.
k(int) defaults to 2 - the smallest level that is a genuine refinement of nwcomponents’ own plain connectivity - and must be at least 1 (nwcomponents already covers that trivial case directly). Vertex connectivity is computed via the standard node-splitting reduction to max-flow (Even 1979) combined with Menger’s theorem (the minimum vertex set separating any two non-adjacent nodes equals the maximum flow between them in the split graph); the network’s own overall k-components are then found by the standard recursive decomposition also underlying Moody and White’s (2003) cohesive blocking - see Algorithm below for the one respect in which this command deliberately does less than the full Moody-White procedure.
Like cliques/k-plexes/n-cliques/n-clans, k-components can genuinely overlap - the nodes whose removal disconnects a graph (a cutset) remain shared members of every resulting sub-block their removal reveals, not assigned to just one side - so nwkcomponents follows the same output shape as nwclique / nwkplex / nwnclique: a single per-node “largest qualifying k-component size” summary variable (gen:erate(newvarname), required), plus the complete overlapping structure in r(kcomp_matrix) (a k-components-by-nodes 0/1 membership matrix) and r(kcomponents) (count). Unlike those commands there is no minsize() - a k-component’s own minimum possible size is already k(int)+1 (a smaller set cannot reach connectivity k(int) at all, since the maximum possible connectivity of an s-node graph is s-1), so there is no equivalent “trivial small case” to filter out separately.
With a list of several networks the variables are numbered by network (newvarname1, newvarname2, …), and the stored results are those of the last network.
Algorithm
nwkcomponents computes k-components for exactly the single level k(int) requested, not the full Moody-White hierarchy (which recursively re-applies this same procedure at every increasing connectivity level found, building a complete nested tree from the whole network down to its most cohesive core). Computing just one target level directly is both simpler to verify by hand and matches how nwkplex / nwnclique already expose their own single-parameter cohesion concepts in this package - a full recursive multi-level hierarchy, if wanted later, would be a natural, separate follow-on built on the same k(int)-level primitive this command already provides, not a reason to withhold the single-level version now.
Network types
Directed: symmetrized. Valued: tie values are ignored and a note is printed. Two-mode: same as for the bipartite graph read as a one-mode network. Signed: not checked. See nwnetworktypes.
Limits
The search for vertex cuts runs in compiled code and the network is not turned into a matrix. For k(2), the default, the search needs a single pass over the ties (the blocks of the network, one depth-first search) instead of one max-flow computation per node; for k(3) and higher it is one max-flow computation per node and per level. Measured in Stata/BE on a random undirected network with 10 ties drawn per node and k(2): 1,000 / 5,000 / 20,000 nodes in 0.02 / 0.1 / 1.0 seconds. Both routes give the same components in the same order. Without the compiled plugin for the platform the Mata code is used and is much slower. For large k or many cuts the time is longer.
Every level of the recursion looks for a vertex cut, so the time grows with the number of cuts. From about 40,000 nodes on, most of the time is spent in Stata itself, which needs time growing with the square of the number of columns to store the matrix r(kcomp_matrix) (one row per component, one column per node): 100,000 nodes take about one minute. Option nomatrix leaves the matrix out; the variable and r(kcomponents) are the same. When the estimated time is more than 2 minutes (about 31,000 nodes, an estimate made for the slower route) the command stops at once with r(484) and a message; option force runs it anyway. For components use nwcomponents, for cores nwkcore.
For all commands at network sizes of 1,000 to 100,000 nodes see the web page How large a network can I analyze?
Examples
. nwwebuse florentine, nwclear
. nwkcomponents flomarriage, generate(_kcompnum)
. nwkcomponents flomarriage, k(3) generate(_kcompnum) replace
Stored results
- Scalars
-
r(kcomponents) — number of maximal k-components found
- Matrices
- r(kcomp_matrix) — k-components-by-nodes 0/1 membership matrix, one row per maximal k-component (not with
nomatrix)
References
Kanevsky, A. (1993). Finding all minimum-size separating vertex sets in a graph. Networks 23(6), 533-541.
Moody, J., White, D.R. (2003). Structural cohesion and embeddedness: a hierarchical concept of social groups. American Sociological Review 68(1), 103-127.
Even, S. (1979). Graph Algorithms. Computer Science Press. (the vertex-splitting max-flow reduction for vertex connectivity)
Wasserman, S., Faust, K. (1994). Social Network Analysis: Methods and Applications. Cambridge University Press. (k-components and structural cohesion)
See also
nwcommands version 3.25.0, 14 November 2026 (check your installed version)