% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/get_cluster_regions.R
\name{get_cluster_regions}
\alias{get_cluster_regions}
\alias{get_cluster_regions.default}
\alias{get_cluster_regions.sequential_scan}
\title{Extract Cluster Membership for Each Region}
\usage{
get_cluster_regions(result, n_clusters = 1L, overlap = TRUE, ...)

\method{get_cluster_regions}{default}(result, n_clusters = 1L, overlap = TRUE, ...)

\method{get_cluster_regions}{sequential_scan}(result, n_clusters = 1L, overlap = TRUE, ...)
}
\arguments{
\item{result}{A \code{"treespatial_scan"} or \code{"circular_scan"}
object (single-pass scan), or a \code{"sequential_scan"} object
(Zhang, Assuncao and Kulldorff, 2010).}

\item{n_clusters}{Integer. (Single-pass methods only.) Number of
clusters to extract. \code{1} returns only the most likely cluster.
Values greater than 1 use \code{\link{filter_clusters}} internally
to identify distinct secondary clusters. Default is \code{1}.
Ignored for sequential scan inputs (all detected iterations are
returned).}

\item{overlap}{Logical. If \code{TRUE} (default), returns a facet-ready
data.frame: all regions are replicated for each cluster panel, with a
\code{panel} column for faceting and \code{cluster} marked only for
member regions. If \code{FALSE}, returns one row per region assigned
to its highest-ranked cluster (for single-panel maps).}

\item{...}{Further arguments passed to methods.}
}
\value{
A \code{data.frame} with columns from \code{result$regions} plus:
  \describe{
    \item{cluster}{Integer cluster number (1 = most likely / first
      iteration, 2 = first secondary / second iteration, etc.), or
      \code{NA} if the region is not in the cluster.}
    \item{node_id}{The tree node of the cluster, or \code{NA}.}
    \item{llr}{The log-likelihood ratio of the cluster, or \code{NA}.}
    \item{pvalue}{The p-value of the cluster, or \code{NA}.}
    \item{panel}{(Only when \code{overlap = TRUE}) A two-line label
      for \code{facet_wrap}, with the cluster identifier on the first
      line and the test statistic on the second. For single-pass
      scans the label looks like \code{"#1 P209\\n(LR=39.6)"}; for
      sequential scans it looks like
      \code{"Iter 1: P209\\n(LR=39.6, p=0.005)"}. The newline keeps
      long node identifiers from overflowing the strip in multi-panel
      layouts.}
  }
}
\description{
Returns a data.frame indicating which cluster (if any) each region
belongs to. This is the primary output for visualization — use it with
any mapping package (ggplot2, leaflet, tmap, etc.).
}
\details{
This is a generic with methods for objects returned by
\code{\link{treespatial_scan}}, \code{\link{circular_scan}}, and
\code{\link{sequential_scan}}.
}
\examples{
data(london_collisions); data(london_tree)
result <- treespatial_scan(
  london_collisions,
  cases       = cases,
  population  = population,
  region_id   = region_id,
  x           = x,
  y           = y,
  node_id     = node_id,
  tree        = london_tree,
  nsim        = 99, seed = 42
)

# Long format suitable for merging with a polygon layer.
cr <- get_cluster_regions(result, n_clusters = 2L, overlap = TRUE)
head(cr)

}
\seealso{
\code{\link{treespatial_scan}}, \code{\link{circular_scan}},
  \code{\link{sequential_scan}}, \code{\link{filter_clusters}}
}
