% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/build_zones.R
\name{build_zones}
\alias{build_zones}
\title{Build Candidate Spatial Zones Using Circular Windows}
\usage{
build_zones(regions, max_pop = NULL)
}
\arguments{
\item{regions}{A \code{data.frame} with columns \code{region_id},
\code{population}, \code{x}, and \code{y}. Coordinates \code{x} and
\code{y} represent centroids of each region.}

\item{max_pop}{A numeric value specifying the maximum population allowed
inside a zone. If \code{NULL} (default), it is set to 50\% of the total
population.}
}
\value{
A \code{list} of zones. Each zone is a list with elements:
  \describe{
    \item{center}{Integer index of the center region.}
    \item{region_idx}{Integer vector of region indices inside the zone.}
    \item{population}{Total population inside the zone.}
  }
}
\description{
Constructs the set of candidate spatial zones for the circular scan
statistic. Each zone is defined by a circular window centered on a region's
centroid, containing all regions whose centroids fall within the circle.
}
\details{
For each region \eqn{j}, regions are sorted by distance from \eqn{j}. Regions
are added incrementally to the zone as long as the total population does
not exceed \code{max_pop}. This generates a nested set of circular windows
centered on each region.
}
\examples{
regions <- data.frame(
  region_id = 1:5,
  population = c(1000, 2000, 1500, 800, 1200),
  x = c(0, 1, 2, 0.5, 1.5),
  y = c(0, 0, 0, 1, 1)
)
zones <- build_zones(regions, max_pop = 3000)
length(zones) # number of candidate zones
}
\references{
Kulldorff, M. (1997). A spatial scan statistic. \emph{Communications in
Statistics - Theory and Methods}, 26(6), 1481–1496.
}
