Network.
contiguityweights
(self, graph=True, weightings=None)[source]¶Create a contiguity-based libpysal W object.
{True, False}
controls whether the W is generated using
the spatial representation or the graph representation.
Default is True
.
dictionary of lists of weightings for each arc/edge.
A pysal
W Object representing the binary adjacency of
the network.
Examples
Instantiate an instance of a network.
>>> import spaghetti as spgh
>>> from libpysal import examples
>>> import esda
>>> import numpy as np
>>> ntw = spgh.Network(examples.get_path('streets.shp'))
Snap point observations to the network with attribute information.
>>> ntw.snapobservations(examples.get_path('crimes.shp'),
... 'crimes', attribute=True)
Find counts per network arc.
>>> counts = ntw.count_per_link(ntw.pointpatterns['crimes']
... .obs_to_arc, graph=False)
>>> counts[(50, 165)]
4
Create a contiguity based W object.
>>> w = ntw.contiguityweights(graph=False)
Using the W object, access to ESDA functionality is provided. First, a vector of attributes is created for all edges with observations.
>>> w = ntw.contiguityweights(graph=False)
>>> arcs = w.neighbors.keys()
>>> y = np.zeros(len(arcs))
>>> for i, e in enumerate(arcs):
... if e in counts.keys():
... y[i] = counts[e]
>>> y[3]
3.0
Next, a standard call ot Moran is made and the
result placed into res
.
>>> res = esda.moran.Moran(y, w, permutations=99)
>>> type(res)
<class 'esda.moran.Moran'>