Skip to content

nwcommands 3.35.0

Choose a tag to compare

@thomas-u-grund thomas-u-grund released this 22 Nov 16:24
· 136 commits to main since this release

Summary. One rule now holds in every command: a command never changes the type of your network by itself. A directed network is analysed as a directed network, a valued network as a valued one, and where a command needs something else (undirected, binary) you ask for it with an option (sym, weak, binary, ...). Every command also prints one line that says how the network was read, and how many missing ties were treated as 0. The release also adds lists of networks and save() to nwgeodesic and nwclustering, ntimes() to nwhomophily and nwdyadprob, and a reader for the data sets of the R package networkdata (nwwebuse schoch).

Results that change, in short (read before you re-run old analyses on directed networks). Undirected networks give the same numbers as before everywhere.

  • nwbetween, nwcloseness, nwevcent, nwinduced, nwkatz: a directed network is analysed as it is. Option sym restores the old default result (nwevcent: option out restores the previous out-tie centrality).
  • nwassortativity: one pair per tie, sender against receiver. sym restores the old result.
  • nwcomponents (and large(), components(), lgc() in nwgenerate): a directed network gives its strongly connected components. weak restores the old result (large(net, weak) in nwgenerate).
  • nwrandomwalk: the walk follows the direction of the ties. sym (or symmetrize) restores the old result.
  • nwcohesion, nwclique, nwkplex, nwnclique, nwnclan, nwkcomponents, nwlambda, nwspectral, nwcoreperiphery, nwfactions: a directed network with unreciprocated ties is refused with error 198 instead of being symmetrized silently. Option sym analyses the symmetrized network, with the same numbers as before.
  • nwbalance: a pair of nodes with ties of opposite signs in the two directions is refused with error 198 (the sign of the pair is not defined; use nwsym with a mode of your choice first).

Added, in short. Lists of networks (wildcards allowed) and save() in nwgeodesic and nwclustering; ntimes() in nwhomophily and nwdyadprob; nwnetworkdata and nwwebuse schoch (needs R with the package igraph, only for this reader); printed notes that say how every network was read; (N missing ties treated as 0) notes. The details follow.

Results that change

  • nwbetween, nwcloseness and nwevcent recognise whether the network is directed or undirected and say so in the output. A directed network is now analysed as it is: shortest paths follow the direction of the ties (betweenness equals igraph::betweenness(directed = TRUE) and sna::betweenness(gmode = "digraph"), with the directed standardisation (N-1)(N-2); closeness uses the distances from a node to the nodes it can reach, equals igraph::closeness(mode = "out", normalized = TRUE), and is missing for a node that reaches nobody; weights of a valued network as before). Until 3.34.0 the default symmetrized a directed network first (nwsym, mode max) and nosym gave the directed result. Use the new option sym for the previous default result; nosym is still accepted and is the same as the default. sym together with nosym is error 198. Undirected networks give exactly the same numbers as before, and need no symmetrized copy any more (nwbetween and nwcloseness take about 30 to 45 percent less time on 2,000 nodes).
  • Printed notes: (directed network: shortest paths follow the direction of the ties) (nwbetween), (directed network: distances follow the direction of the ties) (nwcloseness), (directed network: the direction of the ties is used) (nwevcent), (directed network symmetrized: the larger of the two directions of a tie) (all three with sym), (undirected network) (all three).
  • The analysed network is the current network after nwbetween, nwcloseness and nwevcent in every mode (3.34.0: nwcloseness made the first network of the list current as a by-product when it symmetrized and left the current network unchanged with nosym; nwevcent and nwbetween with nosym never changed it). After a call with a list of networks the last network of the list is current.
  • Dialogs of the three commands: the nosym check box is replaced by a sym check box.
  • Coercion sweep (standing rule: no command treats a network as another type than it is unless an option asks for it, and every coercion is stated in the output). Helpers _nwdirnote (the note line for directed, undirected or symmetrized) and _nwmissnote ((N missing ties treated as 0), printed only when the network has missing ties); option sym is the same everywhere (the larger of the two directions of a tie).
  • nwassortativity: a directed network is now analysed as it is, one pair per tie with the value at the sender against the value at the receiver (Newman 2003; equals igraph::assortativity_degree(directed = TRUE) for the default degree: out-degree of the sender against in-degree of the receiver, out- and in-strength on a valued network, and igraph::assortativity(directed = TRUE) with attribute()). Until 3.34.0 a directed network was symmetrized silently. Option sym gives the previous result. Notes: (directed network: out-degree of the sender against in-degree of the receiver, one pair per tie), (directed network: the attribute of the sender against that of the receiver, one pair per tie), (directed network symmetrized: ...), (undirected network); r(ties) counts the arcs of a directed network; r(directed) is stored. Undirected networks: same numbers. Example lazega_adv: -0.0802 before, -0.0302 now (sym: -0.0802); glasgow1: 0.1723 before, 0.1509 now.
  • nwcomponents: a directed network gives its strongly connected components (mutual reachability along the direction of the ties; igraph::components(mode = "strong")), as igraph and sna do; until 3.34.0 the weakly connected components were returned silently. Option weak gives the previous result. The output says (directed network: strongly connected components ...), (directed network: weakly connected components, the direction of the ties is ignored) or (undirected network), and (N missing ties treated as 0) when the network has missing ties; r(connected) is stored. nwgenerate ... = nwcomponents(...) follows the new default; nwplot (largest component) keeps the weak components. Example glasgow1: 8 components before, 14 now; lazega_fr: 1 before, 3 now.
  • nwclustering: no number changes. The survey claim that the directed coefficient ignores the direction was checked and is wrong: a directed network already uses the direction (a path a -> i -> b is closed by the tie a -> b). The output now says so: (directed network: a path a -> i -> b is closed by the tie a -> b, the direction of the ties is used), (directed network symmetrized: ...) with symmetrize, (undirected network), (valued network: tie values ignored, every tie counts as 1) for measure(binary) on a valued network, (two-mode network read as the one-mode network of the bipartite graph) with onemode, (N missing ties treated as 0), and for a two-mode network (two-mode network: Opsahl's two-mode clustering of the nodes of mode k (level(k)), 4-paths closed by a 6-cycle; measure ...).
  • nwgenerate ... = large() and components()/lgc(): follow the new default of nwcomponents (strong components for a directed network); large(net, weak) gives the previous result.
  • nwrandomwalk: the random walk on a directed network now follows the direction of the ties (step probability w_ij / out-strength, as igraph::random_walk(mode = "out")); the mean hitting time is missing for a node from which the target is not reached with certainty (a dead end, or a part of the network without a way to the target). Until 3.34.0 the network was symmetrized silently. Option symmetrize (sym) gives the previous result. Needs the dense transition matrix (error 484 above the dense limit; sym keeps the stored-ties solver). Notes: (directed network: the walk follows the direction of the ties; ...), (directed network symmetrized: ...), (undirected network); r(directed) is stored. Example lazega_adv, target n13: mean hitting time 37.66 before, 33.05 now (checked against the linear system solved in R, 1e-9).
  • nwcohesion, nwclique, nwkplex, nwnclique, nwnclan, nwkcomponents, nwlambda (defined for undirected networks): a directed network whose ties are not all reciprocated is now refused with error 198 and a message that names the option sym; with sym the symmetrized network is analysed (the larger of the two directions of a tie) and the output says (directed network symmetrized: the larger of the two directions of a tie). Until 3.34.0 such a network was symmetrized silently, with the same numbers as sym gives now. A directed network whose ties are all reciprocated with the same value is identical to an undirected one: it is analysed and the output says (directed network with every tie reciprocated: analysed as an undirected network). Undirected networks: no change. A valued network says that the tie values are ignored (the existing note, now also in nwlambda). Shared helper _nwsymguard. Dialogs: a sym check box (not for nwcohesion and nwlambda, which have none).
  • nwspectral, nwcoreperiphery, nwfactions: same rule as the cohesion family: a directed network with unreciprocated ties is refused with error 198 (naming option sym) instead of being symmetrized silently; with sym the symmetrized network is analysed (same numbers as before) and the output says so; a directed network with every tie reciprocated runs and says so. nwspectral, plot follows the same rule (before, it refused every directed network). Dialogs of nwspectral and nwcoreperiphery have a sym check box. Example lazega_adv in the book (nwcoreperiphery, ch. 10): add sym; the printed core size and fitness are the same as before.
  • nwbalance: on a directed network a pair of nodes with a tie in each direction and opposite signs used to take the sign of the tie from the node with the lower index (the result depended on the order of the nodes). The sign of such a pair is not defined: the command now stops with error 198 and says how many pairs are affected (use nwsym with the mode of your choice first). Networks without such pairs (all undirected networks, directed ones whose mutual pairs agree in sign) give the same numbers as before. The output now says how a directed network is read (a pair is tied when there is a tie in either direction), that only the sign of a tie counts on a valued network, and (N missing ties treated as 0).
  • nwdiffuse (exposure, threshold, long, simulate): no number changes; the output now states how the network was read, one line each: (directed network: the exposure of a node comes from the nodes it sends ties to; option incoming uses the nodes it receives ties from) or ... receives ties from), (undirected network), (valued network: tie values ignored, every tie counts as 1; option valued weights by the tie values) or (valued network: exposure weighted by the tie values), (self-loops ignored; option self counts them) (only when the network has self-loop ties) and (N missing ties treated as 0).
  • nwmaxflow: no number changes; the output now says (directed network: flow follows the direction of the ties) or (undirected network: a tie carries flow in both directions), (valued network: every tie has capacity 1, tie values ignored; option weighted uses the tie values as capacities) / (valued network: the tie values are the capacities) / (every tie has capacity 1), and (N missing ties treated as 0).
  • nwkatz: a directed network is now analysed as it is also in the default distance-decay form (before, it was symmetrized unless nosym, and the text Network has been symmetrized for calculation. was printed even for undirected networks and for walks, which never symmetrized). _out uses the distances from a node to the nodes it reaches, _in the distances from the nodes that reach it; option sym gives the previous result (_in and _out equal); nosym is accepted and is the default. With walks, _in equals igraph::alpha_centrality() (checked on lazega_adv, alpha 0.05, 1e-9); sym now also works with walks (the larger of the two directions). The output says (directed network: ...), (directed network symmetrized: ...) or (undirected network), whether the distance-decay form ignored the tie values of a valued network, and (N missing ties treated as 0). Undirected networks: same numbers. Example lazega_adv, alpha 0.2, node 1: _in = _out = 6.16 before, _in 5.68 and _out 3.568 now (sym: 6.16). Dialog: the nosym check box is replaced by sym.
  • nwsimindex, nwsimmelian: no number changes; the output says (directed network: the neighbours of a node are the nodes it sends ties to and the nodes it receives ties from) (nwsimindex), (directed network: only mutual ties are used) (nwsimmelian), (undirected network) and (N missing ties treated as 0). No option was added: the direction rule is the definition of the measure.
  • nwkcore, nwego, nwconstraint: no number changes; the output says how a directed network is read (nwkcore and nwego: the neighbours of a node are the nodes it sends ties to and the nodes it receives ties from; nwconstraint: the proportions p_ij come from the out-ties of node i, whereas nwburt uses both directions), (undirected network) and (N missing ties treated as 0). nwdegree and nwcomponents also print (N missing ties treated as 0) when the network has missing ties. nwcomponents test test_usair_full_data now uses weak.
  • nwevcent: on a directed network the default is now the in-tie eigenvector centrality (the score of a node comes from the nodes that send ties to it), as igraph::eigen_centrality(directed = TRUE) (checked on the strongly connected lazega_adv, scaled to a maximum of 1, 1e-8; on a network that is not strongly connected igraph and nwcommands both give 0 or tiny scores outside the dominant strongly connected part). Until now the default was the out-tie centrality (the igraph result on the transposed network). New option out gives the previous result; sym and out together are error 198. Note line: (directed network: the centrality of a node comes from the nodes that send ties to it), with out (... from the nodes it sends ties to). Undirected networks and sym: same numbers. Dialog: check box out.
  • nwinduced (measure(betweenness|closeness|evcent)): a directed network is analysed as it is, as nwbetween, nwcloseness and nwevcent now do (the endogenous centrality equals the direct call; evcent uses the in-ties), for the full network and for every network without one node, so the induced and exogenous values of a directed network change with them. New option sym symmetrizes first (the larger of the two directions of a tie) and gives the result of 3.34.0 and earlier. measure(degree) still stops on a directed network. Test: test_nwinduced compares the endogenous values on the directed lazega_adv with the direct calls, with and without sym.

Added

  • nwnetworkdata (new): imports the networks of David Schoch's R package networkdata (989 data sets, 2,274 networks) into nwcommands; nwwebuse schoch, nwwebuse schoch list|describe name, nwwebuse schoch name and nwwebuse name, schoch call it. No data are shipped: the original .rda file is downloaded from Schoch's repository when a data set is asked for, cached in the PLUS folder and converted by R (needs R with the package igraph, only for this reader). Names are checked against the catalogue before anything is downloaded or started, from() accepts only the official repository or an existing folder, and every load prints which network was loaded (nodes, ties, directed or undirected, one-mode or two-mode, binary or valued) and where the data came from. Per-data-set documentation (sources, references) is on the website, not in the install.

  • nwgeodesic and nwclustering take a list of networks, as nwsummarize does (wildcards such as draw_* expand the same way). A table with one row per network is printed (nwgeodesic: nodes, average path length, diameter, radius, share of connected pairs, average distance over the connected pairs; nwclustering: nodes, measure, average and global coefficient) with one line that says how each kind of network was read (the notes of the single-network call). r() holds the results of the last network of the list, exactly as the single call for it. New option save(file [, replace]) writes a Stata data set with one observation per network (also for one network), numbers stored as double: nwgeodesic writes name directed valued nodes numpaths unconnected avgpath diameter radius alpha connected avgpath_connected diameter_connected (avgpath, diameter, radius are missing, not -1, when not every pair is connected; avgpath_connected and diameter_connected are missing when unconnected() replaced the distances of unconnected pairs), nwclustering writes name directed valued twomode nodes measure level cluster_global cluster_avg nmissing (a two-mode network: Opsahl's global coefficient and the mean over the nodes of level(); level is missing for a one-mode network). Options that make a variable, a network or a graph for one network (nwgeodesic: generate(), name(), xvars, plot, gname(), saving(), export(); nwclustering: generate(), ra) are error 198 with a list. A two-mode network in a list of nwclustering needs no generate(). A call for a single network without save() is unchanged (output, r(), variables). After nwgeodesic with a list the distance network _geodesic holds the distances of the last network. Dialogs: a field for save(); the nwclustering dialog no longer insists on generate(). Test test_core_netlist: every row against the single call to 1e-12, also for 20 networks from nwrandom ... ntimes(20) and nwsmall ... ntimes(20).

  • nwdyadprob and nwhomophily: option ntimes(#) draws that many networks, named name_1, name_2, ... as nwrandom, nwsmall, nwring and nwpref do; r(netlist) lists them. A call without ntimes() is unchanged; ntimes(0) is error 198 in nwdyadprob. nwhomophily builds the dyad weights once and draws all networks from them. Dialogs: a spinner for ntimes.

  • nwmixing: the output says how the table is read, (directed network: the table counts every tie from ego (row) to alter (column)) or (undirected network), and (N missing ties treated as 0) when the network has missing ties. nwmixing takes one network (no list), so there is no per-network save() for the E-I index.

  • Missing-ties note (N missing ties treated as 0) (printed only when the network has missing ties; checked for each command that the result with a missing tie equals the result with 0 in its place) in nwbetween, nwcloseness, nwevcent, nwpagerank, nwdyads and nwmotifs (one-mode form). nwtriads shows it already through the clustering coefficient it reports; nwhomophily reads no network.

  • nwsummarize: the output says (valued network: edges and density count every tie with a non-zero value; minimum and maximum are tie values) for a valued network, and for a network with missing ties (N missing ties are not counted as ties and not as pairs in the density) (; the measures of detail treat them as 0 with detail). Missing ties are not treated as 0 by the summary itself: the density is taken over the pairs that have a value.

Fixed

  • The missing-ties note (_nwmissnote) counted the within-mode cells of some two-mode networks when the nodes of the two modes are not in two blocks (alphabetical order, e.g. davis): the note named 56 missing ties for a network that has none. It reads the cells between the two modes by node mode now.

Changed

  • Help: nwsummarize says exactly what r(missing_edges) counts (all cells without a value, including the diagonal cells of a network without self-loops, and both cells of a missing tie in an undirected network), how to get the number of missing off-diagonal cells (r(missing_edges) - r(nodes)) and warns against testing r(missing_edges) > 0.