def spillover(self, quadrant=<NUM_LIT:1>, neighbors_on=False):
n, k = self.q.shape<EOL>if self.permutations:<EOL><INDENT>spill_over = np.zeros((n, k - <NUM_LIT:1>))<EOL>components = np.zeros((n, k))<EOL>i2id = {}  <EOL>for key in list(self.w.neighbors.keys()):<EOL><INDENT>idx = self.w.id2i[key]<EOL>i2id[idx] = key<EOL><DEDENT>sig_lisas = (self.q == quadrant)* (self.p_values <= self.significance_level)<EOL>sig_ids = [np.nonzero(<EOL>sig_lisas[:, i])[<NUM_LIT:0>].tolist() for i in range(k)]<EOL>neighbors = self.w.neighbors<EOL>for t in range(k - <NUM_LIT:1>):<EOL><INDENT>s1 = sig_ids[t]<EOL>s2 = sig_ids[t + <NUM_LIT:1>]<EOL>g1 = Graph(undirected=True)<EOL>for i in s1:<EOL><INDENT>for neighbor in neighbors[i2id[i]]:<EOL><INDENT>g1.add_edge(i2id[i], neighbor, <NUM_LIT:1.0>)<EOL>if neighbors_on:<EOL><INDENT>for nn in neighbors[neighbor]:<EOL><INDENT>g1.add_edge(neighbor, nn, <NUM_LIT:1.0>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>components1 = g1.connected_components(op=gt)<EOL>components1 = [list(c.nodes) for c in components1]<EOL>g2 = Graph(undirected=True)<EOL>for i in s2:<EOL><INDENT>for neighbor in neighbors[i2id[i]]:<EOL><INDENT>g2.add_edge(i2id[i], neighbor, <NUM_LIT:1.0>)<EOL>if neighbors_on:<EOL><INDENT>for nn in neighbors[neighbor]:<EOL><INDENT>g2.add_edge(neighbor, nn, <NUM_LIT:1.0>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>components2 = g2.connected_components(op=gt)<EOL>components2 = [list(c.nodes) for c in components2]<EOL>c2 = []<EOL>c1 = []<EOL>for c in components2:<EOL><INDENT>c2.extend(c)<EOL><DEDENT>for c in components1:<EOL><INDENT>c1.extend(c)<EOL><DEDENT>new_ids = [j for j in c2 if j not in c1]<EOL>spill_ids = []<EOL>for j in new_ids:<EOL><INDENT>cj = [c for c in components2 if j in c][<NUM_LIT:0>]<EOL>for i in cj:<EOL><INDENT>if i in c1:<EOL><INDENT>spill_ids.append(j)<EOL>break<EOL><DEDENT><DEDENT><DEDENT>for spill_id in spill_ids:<EOL><INDENT>id = self.w.id2i[spill_id]<EOL>spill_over[id, t] = <NUM_LIT:1><EOL><DEDENT>for c, component in enumerate(components1):<EOL><INDENT>for i in component:<EOL><INDENT>ii = self.w.id2i[i]<EOL>components[ii, t] = c + <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>results = {}<EOL>results['<STR_LIT>'] = components<EOL>results['<STR_LIT>'] = spill_over<EOL>return results<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>
Detect spillover locations for diffusion in LISA Markov.

Parameters
----------
quadrant     : int
               which quadrant in the scatterplot should form the core
               of a cluster.
neighbors_on : binary
               If false, then only the 1st order neighbors of a core
               location are included in the cluster.
               If true, neighbors of cluster core 1st order neighbors
               are included in the cluster.

Returns
-------
results      : dictionary
               two keys - values pairs:
               'components' - array (n, t)
               values are integer ids (starting at 1) indicating which
               component/cluster observation i in period t belonged to.
               'spillover' - array (n, t-1)
               binary values indicating if the location was a
               spill-over location that became a new member of a
               previously existing cluster.

Examples
--------
>>> import libpysal
>>> from giddy.markov import LISA_Markov
>>> f = libpysal.io.open(libpysal.examples.get_path("usjoin.csv"))
>>> years = list(range(1929, 2010))
>>> pci = np.array([f.by_col[str(y)] for y in years]).transpose()
>>> w = libpysal.io.open(libpysal.examples.get_path("states48.gal")).read()
>>> np.random.seed(10)
>>> lm_random = LISA_Markov(pci, w, permutations=99)
>>> r = lm_random.spillover()
>>> (r['components'][:, 12] > 0).sum()
17
>>> (r['components'][:, 13]>0).sum()
23
>>> (r['spill_over'][:,12]>0).sum()
6

Including neighbors of core neighbors
>>> rn = lm_random.spillover(neighbors_on=True)
>>> (rn['components'][:, 12] > 0).sum()
26
>>> (rn["components"][:, 13] > 0).sum()
34
>>> (rn["spill_over"][:, 12] > 0).sum()
8