Skip to content

Commit

Permalink
hotspots is correct
Browse files Browse the repository at this point in the history
  • Loading branch information
knaaptime committed Mar 14, 2024
1 parent 3bab35a commit ce8de73
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pointpats/spacetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,8 @@ def hotspots(self, crit=0.05, inference="permutation", keep_neighbors=True):
whether to included nonsignificant members of hotspots. While these
observations are not themselves significant, these still define the spatial
extent of the cluster, and the the focal observation cannot become
significant without their presence.
significant without their presence. If True, return all members of a
significant hotspot, else return only the significant locations
Returns
-------
Expand Down Expand Up @@ -1347,21 +1348,20 @@ def hotspots(self, crit=0.05, inference="permutation", keep_neighbors=True):

# if keep_neighbors, we want to include a 'cluster' column denoting which
# cluster nonsig observations belong to. Need to use a graph for that
how = "outer" if keep_neighbors else "inner"

temp_neighbors = self.adjlist[
(self.adjlist.focal.isin(pdf_sig.index.values))
| self.adjlist.neighbor.isin(pdf_sig.index.values)
]

pdf_sig = pdf_sig.merge(
temp_neighbors, how=how, left_index=True, right_on="focal"
temp_neighbors, how='outer', left_index=True, right_on="focal"
).reset_index(drop=True)
if how == "outer":
# significant focals can be neighbors of others (dupes)
pdf_sig = pdf_sig.groupby("focal").first().reset_index()
graph = Graph.from_adjacency(pdf_sig.assign(weight=1))
pdf_sig["cluster"] = graph.component_labels.values
# significant focals can be neighbors of others (dupes)
pdf_sig = pdf_sig.groupby("focal").first().reset_index()
graph = Graph.from_adjacency(pdf_sig.assign(weight=1))
pdf_sig["cluster"] = graph.component_labels.values
if not keep_neighbors :
pdf_sig = pdf_sig.dropna(subset=['pvalue'])

return self._gdf[["geometry"]].merge(
pdf_sig.copy(), left_index=True, right_on="focal"
Expand Down

0 comments on commit ce8de73

Please sign in to comment.