R/edmst.zones.R In smerc: Statistical Methods for Regional Counts

Documented in edmst.zones

```#' Determine zones for the early stopping dynamic Minimum
#' Spanning Tree scan test
#'
#' \code{edmst.zones} determines the zones for the early
#' stopping Dynamic Minimum Spanning Tree scan test
#' (\code{\link{edmst.test}}).  The function returns the
#' zones, as well as the associated test statistic, cases in
#' each zone, the expected number of cases in each zone, and
#' the population in each zone.
#'
#' Every zone considered must have a total population less
#' than \code{ubpop * sum(pop)}.  Additionally, the maximum
#' intercentroid distance for the regions within a zone must
#' be no more than \code{ubd * the maximum intercentroid
#' distance across all regions}.
#' @inheritParams dmst.test
#' @inheritParams mst.all
#' @inheritParams flex.zones
#' @inherit dc.zones return
#' @author Joshua French
#' @references Costa, M.A. and Assuncao, R.M. and Kulldorff,
#'   M. (2012) Constrained spanning tree algorithms for
#'   irregularly-shaped spatial clustering, Computational
#'   Statistics & Data Analysis, 56(6), 1771-1783.
#'   <doi:10.1016/j.csda.2011.11.001>
#' @export
#' @examples
#' data(nydf)
#' data(nyw)
#' coords <- as.matrix(nydf[, c("longitude", "latitude")])
#' # find zone with max statistic starting from each individual region
#' all_zones <- edmst.zones(coords,
#'   cases = floor(nydf\$cases),
#'   nydf\$pop, w = nyw, ubpop = 0.25,
#'   ubd = .25, longlat = TRUE
#' )
edmst.zones <- function(coords, cases, pop, w,
ex = sum(cases) / sum(pop) * pop,
ubpop = 0.5, ubd = 1, longlat = FALSE,
cl = NULL, progress = TRUE) {
# sanity checking
arg_check_dmst_zones(
coords = coords, cases = cases,
pop = pop, w = w, ex = ex,
ubpop = ubpop, ubd = ubd,
longlat = longlat, type = "all",
progress = progress
)
# setup various arguments and such
ty <- sum(cases) # total number of cases
# intercentroid distances
d <- sp::spDists(as.matrix(coords), longlat = longlat)
# upperbound for population in zone
max_pop <- ubpop * sum(pop)
# find all neighbors from each starting zone within distance upperbound
nn <- nndist(d, ubd)
# get zones and relevant information
out <- mst.all(
neighbors = nn, cases = cases, pop = pop,
w = w, ex = ex, ty = ty, max_pop = max_pop,
type = "all", nlinks = "one", early = TRUE,
cl = cl, progress = progress
)
# return results of mst.all in a nicely formatted list
prep.mst(out)
}
```

Try the smerc package in your browser

Any scripts or data that you put into this service are public.

smerc documentation built on Oct. 13, 2022, 9:07 a.m.