libpysal.graph.GraphSummary

class libpysal.graph.GraphSummary(graph, asymmetries=False)[source]

Graph Summary

An object containing the statistical attributes summarising the Graph and its basic properties.

Attributes:
n_nodesint

number of Graph nodes

n_edgesint

number of Graph edges

n_componentsint

number of connected components

n_isolatesint

number of isolates (nodes with no neighbors)

nonzeroint

number of edges with nonzero weight

pct_nonzerofloat

percentage of nonzero weights

n_asymmetriesint

number of intrinsic asymmetries

cardinalities_meanfloat

mean number of neighbors

cardinalities_stdfloat

standard deviation of number of neighbors

cardinalities_minfloat

minimal number of neighbors

cardinalities_25float

25th percentile of number of neighbors

cardinalities_50float

50th percentile (median) of number of neighbors

cardinalities_75float

75th percentile of number of neighbors

cardinalities_maxfloat

maximal number of neighbors

weights_meanfloat

mean edge weight

weights_stdfloat

standard deviation of edge weights

weights_minfloat

minimal edge weight

weights_25float

25th percentile of edge weights

weights_50float

50th percentile (median) of edge weights

weights_75float

75th percentile of edge weights

weights_maxfloat

maximal edge weight

s0float

S0 (global) sum of weights

s0 is defined as

\[s0=\sum_i \sum_j w_{i,j}\]

s0, s1, and s2 reflect interaction between observations and are used to compute standard errors for spatial autocorrelation estimators.

s1float

S1 sum of weights

s1 is defined as

\[s1=1/2 \sum_i \sum_j \Big(w_{i,j} + w_{j,i}\Big)^2\]

s0, s1, and s2 reflect interaction between observations and are used to compute standard errors for spatial autocorrelation estimators.

s2float

S2 sum of weights

s2 is defined as

\[s2=\sum_j \Big(\sum_i w_{i,j} + \sum_i w_{j,i}\Big)^2\]

s0, s1, and s2 reflect interaction between observations and are used to compute standard errors for spatial autocorrelation estimators.

diag_g2np.ndarray

diagonal of \(GG\)

diag_gtgnp.ndarrray

diagonal of \(G^{'}G\)

diag_gtg_ggnp.ndarray

diagonal of \(G^{'}G + GG\)

trace_g2np.ndarray

trace of \(GG\)

trace_gtgnp.ndarrray

trace of \(G^{'}G\)

trace_gtg_ggnp.ndarray

trace of \(G^{'}G + GG\)

Examples

>>> import geopandas as gpd
>>> from geodatasets import get_path
>>> nybb = gpd.read_file(get_path("nybb")).set_index("BoroName")
>>> nybb
                BoroCode  ...                                           geometry
BoroName                 ...
Staten Island         5  ...  MULTIPOLYGON (((970217.022 145643.332, 970227....
Queens                4  ...  MULTIPOLYGON (((1029606.077 156073.814, 102957...
Brooklyn              3  ...  MULTIPOLYGON (((1021176.479 151374.797, 102100...
Manhattan             1  ...  MULTIPOLYGON (((981219.056 188655.316, 980940....
Bronx                 2  ...  MULTIPOLYGON (((1012821.806 229228.265, 101278...
[5 rows x 4 columns]
>>> contiguity = graph.Graph.build_contiguity(nybb)
>>> contiguity
<Graph of 5 nodes and 10 nonzero edges indexed by
    ['Staten Island', 'Queens', 'Brooklyn', 'Manhattan', 'Bronx']>
>>> summary = contiguity.summary(asymmetries=True)
>>> summary
Graph Summary Statistics
========================
Graph indexed by:
['Staten Island', 'Queens', 'Brooklyn', 'Manhattan', 'Bronx']
==============================================================
number of nodes:                                             5
number of edges:                                            10
number of connected components:                              2
number of isolates:                                          1
number of non-zero edges:                                   10
Percentage of non-zero edges:                           44.00%
number of asymmetries:                                       0
--------------------------------------------------------------
Cardinalities
==============================================================
Mean:                       2    25%:                        2
Standard deviation:         1    50%:                        2
Min:                        0    75%:                        3
Max:                        3
--------------------------------------------------------------
Weights
==============================================================
Mean:                       1    25%:                        1
Standard deviation:         0    50%:                        1
Min:                        1    75%:                        1
Max:                        1
--------------------------------------------------------------
Sum of weights
==============================================================
S0:                                                         10
S1:                                                         20
S2:                                                        104
--------------------------------------------------------------
Traces
==============================================================
GG:                                                         10
G'G:                                                        10
G'G + GG:                                                   20
>>> summary.s1
20
__init__(graph, asymmetries=False)[source]

Create GraphSummary

Parameters:
graphGraph
asymmetriesbool

whether to compute n_asymmetries, which is considerably more expensive than the other attributes. By default False.

Methods

__init__(graph[, asymmetries])

Create GraphSummary