# neurostatx.network.metrics

*module*

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L1-L1)

## neurostatx.network.metrics.PathLengthsMethods

*class*

```python
class PathLengthsMethods(str, Enum)
```

Bases: `str`, `Enum`

Shortest-path algorithms accepted by NetworkX path-length helpers.

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L368-L374)

### neurostatx.network.metrics.PathLengthsMethods.BellmanFord

*attribute* · *class attribute* · *instance attribute*

```python
BellmanFord = ('bellman-ford')
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L372-L372)

### neurostatx.network.metrics.PathLengthsMethods.Dijkstra

*attribute* · *class attribute* · *instance attribute*

```python
Dijkstra = ('dijkstra')
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L371-L371)

### neurostatx.network.metrics.PathLengthsMethods.FloydWarshall

*attribute* · *class attribute* · *instance attribute*

```python
FloydWarshall = ('floyd-warshall')
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L373-L373)

### neurostatx.network.metrics.PathLengthsMethods.FloydWarshallNumpy

*attribute* · *class attribute* · *instance attribute*

```python
FloydWarshallNumpy = 'floyd-warshall-numpy'
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L374-L374)

## neurostatx.network.metrics.betweennesscentrality

*function*

```python
def betweennesscentrality(graph, weight=None)
```

Compute betweenness centrality for every node.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `weight` (`str`) (default: `None`) — Edge attribute used as weight. Defaults to None.

**Returns**

- `scores` (`dict`) — Betweenness centrality for each node.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import betweennesscentrality
>>> betweennesscentrality(nx.path_graph(3))
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L96-L117)

## neurostatx.network.metrics.closenesscentrality

*function*

```python
def closenesscentrality(graph, weight=None)
```

Compute closeness centrality for every node.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `weight` (`str`) (default: `None`) — Edge attribute used as distance. Defaults to None.

**Returns**

- `scores` (`dict`) — Closeness centrality for each node.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import closenesscentrality
>>> closenesscentrality(nx.path_graph(3))
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L72-L93)

## neurostatx.network.metrics.closenessvitality

*function*

```python
def closenessvitality(graph, nodes, weight=None)
```

Compute closeness vitality for a single node.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `nodes` (`str`) — Node identifier passed to NetworkX as ``node``.
- `weight` (`str`) (default: `None`) — Edge attribute used as weight. Defaults to None.

**Returns**

- `score` (`float`) — Closeness vitality of ``nodes``.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import closenessvitality
>>> closenessvitality(nx.path_graph(3), nodes=1)
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L317-L340)

## neurostatx.network.metrics.clustering

*function*

```python
def clustering(graph, weight=None)
```

Compute the clustering coefficient for every node.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `weight` (`str`) (default: `None`) — Edge attribute used as weight. Defaults to None.

**Returns**

- `scores` (`dict`) — Clustering coefficient for each node.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import clustering
>>> clustering(nx.complete_graph(4))
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L241-L262)

## neurostatx.network.metrics.constraint

*function*

```python
def constraint(graph, nodes, weight=None)
```

Compute Burt's constraint for the requested nodes.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `nodes` (`str`) — Space-separated node identifiers.
- `weight` (`str`) (default: `None`) — Edge attribute used as weight. Defaults to None.

**Returns**

- `scores` (`dict`) — Constraint for each requested node.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import constraint
>>> constraint(nx.path_graph(3), nodes="0 1")
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L265-L288)

## neurostatx.network.metrics.currentflowbc

*function*

```python
def currentflowbc(graph, weight=None)
```

Compute current-flow betweenness centrality for every node.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `weight` (`str`) (default: `None`) — Edge attribute used as weight. Defaults to None.

**Returns**

- `scores` (`dict`) — Current-flow betweenness centrality for each node.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import currentflowbc
>>> currentflowbc(nx.path_graph(3))
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L144-L166)

## neurostatx.network.metrics.degree

*function*

```python
def degree(graph, weight=None)
```

Return the degree of every node.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `weight` (`str`) (default: `None`) — Edge attribute used as weight. Defaults to None.

**Returns**

- `degrees` (`networkx.DegreeView`) — Degree of each node.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import degree
>>> dict(degree(nx.path_graph(3)))
{0: 1, 1: 2, 2: 1}
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L343-L365)

## neurostatx.network.metrics.eccentricity

*function*

```python
def eccentricity(graph, weight=None)
```

Compute eccentricity for every node.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `weight` (`str`) (default: `None`) — Edge attribute used as weight. Defaults to None.

**Returns**

- `scores` (`dict`) — Eccentricity for each node.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import eccentricity
>>> eccentricity(nx.path_graph(3))
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L217-L238)

## neurostatx.network.metrics.effectivesize

*function*

```python
def effectivesize(graph, nodes, weight=None)
```

Compute effective size for the requested nodes.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `nodes` (`str`) — Space-separated node identifiers.
- `weight` (`str`) (default: `None`) — Edge attribute used as weight. Defaults to None.

**Returns**

- `scores` (`dict`) — Effective size for each requested node.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import effectivesize
>>> effectivesize(nx.path_graph(3), nodes="0 1")
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L291-L314)

## neurostatx.network.metrics.eigencentrality

*function*

```python
def eigencentrality(graph, weight=None)
```

Compute eigenvector centrality for every node.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `weight` (`str`) (default: `None`) — Edge attribute used as weight. Defaults to None.

**Returns**

- `scores` (`dict`) — Eigenvector centrality for each node.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import eigencentrality
>>> eigencentrality(nx.path_graph(3))
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L48-L69)

## neurostatx.network.metrics.get_metrics_ops

*function*

```python
def get_metrics_ops()
```

Return the mapping of metric names to callable implementations.

**Returns**

- `metrics` (`dict`) — Ordered mapping of metric name to function.

**Examples**

```pycon
>>> from neurostatx.network.metrics import get_metrics_ops
>>> "eigencentrality" in get_metrics_ops()
True
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L15-L45)

## neurostatx.network.metrics.harmoniccentrality

*function*

```python
def harmoniccentrality(graph, weight=None)
```

Compute harmonic centrality for every node.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `weight` (`str`) (default: `None`) — Edge attribute used as distance. Defaults to None.

**Returns**

- `scores` (`dict`) — Harmonic centrality for each node.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import harmoniccentrality
>>> harmoniccentrality(nx.path_graph(3))
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L193-L214)

## neurostatx.network.metrics.informationcentrality

*function*

```python
def informationcentrality(graph, weight=None)
```

Compute information centrality for every node.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `weight` (`str`) (default: `None`) — Edge attribute used as weight. Defaults to None.

**Returns**

- `scores` (`dict`) — Information centrality for each node.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import informationcentrality
>>> informationcentrality(nx.path_graph(3))
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L120-L141)

## neurostatx.network.metrics.loadcentrality

*function*

```python
def loadcentrality(graph, weight=None)
```

Compute load centrality for every node.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `weight` (`str`) (default: `None`) — Edge attribute used as weight. Defaults to None.

**Returns**

- `scores` (`dict`) — Load centrality for each node.

**Examples**

```pycon
>>> import networkx as nx
>>> from neurostatx.network.metrics import loadcentrality
>>> loadcentrality(nx.path_graph(3))
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L169-L190)

## neurostatx.network.metrics.weightedpath

*function*

```python
def weightedpath(graph, df, label_name, cohort=None, iterations=1000, weight=None, method='dijkstra', distribution=None, processes=1, verbose=False)
```

Average weighted path length for a group, with a permutation p-value.

**Parameters**

- `graph` (`networkx.Graph`) — Input graph.
- `df` (`pandas.DataFrame`) — Table of nodes. The index must match graph node labels.
- `label_name` (`str`) — Column containing the group label. Nodes with value 0 are excluded.
- `cohort` (`str`) (default: `None`) — If set, restrict ``df`` to this ``cohort`` value. Defaults to None.
- `iterations` (`int`) (default: `1000`) — Number of null-distribution draws. Defaults to 1000.
- `weight` (`str`) (default: `None`) — Edge attribute used as weight. Defaults to None.
- `method` (`str`) (default: `'dijkstra'`) — Shortest-path algorithm. Defaults to ``"dijkstra"``.
- `distribution` (`pd.DataFrame`) (default: `None`) — Precomputed null distribution with a ``label_name`` column. Defaults to None.
- `processes` (`int`) (default: `1`) — Number of worker processes. Defaults to 1.
- `verbose` (`bool`) (default: `False`) — If True, show a progress bar. Defaults to False.

**Returns**

- `avg_path_length` (`float`) — Average shortest-path length of the selected subgraph.
- `dist` (`list`) — Null distribution of path lengths.
- `pvalue` (`float`) — One-sided permutation p-value.

**Examples**

```pycon
>>> import pandas as pd
>>> import networkx as nx
>>> from neurostatx.network.metrics import weightedpath
>>> G = nx.path_graph(4)
>>> df = pd.DataFrame({"group": [1, 1, 0, 0]})
>>> avg, dist, p = weightedpath(
...     G, df, "group", iterations=5, processes=1
... )
```

[View source](https://github.com/gagnonanthony/NeuroStatX/blob/main/neurostatx/network/metrics.py#L377-L490)
