View source: R/get_cluster_regions.R
| get_cluster_regions | R Documentation |
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.).
get_cluster_regions(result, n_clusters = 1L, overlap = TRUE, ...)
## Default S3 method:
get_cluster_regions(result, n_clusters = 1L, overlap = TRUE, ...)
## S3 method for class 'iterative_scan'
get_cluster_regions(result, n_clusters = 1L, overlap = TRUE, ...)
result |
Either a |
n_clusters |
Integer. (Single-pass methods only.) Number of
clusters to extract. |
overlap |
Logical. If |
... |
Further arguments passed to methods. |
This is a generic with methods for objects returned by
treespatial_scan, circular_scan, and
iterative_scan.
A data.frame with columns from result$regions plus:
Integer cluster number (1 = most likely / first
iteration, 2 = first secondary / second iteration, etc.), or
NA if the region is not in the cluster.
The tree node of the cluster, or NA.
The log-likelihood ratio of the cluster, or NA.
The p-value of the cluster, or NA.
(Iterative method only) The Holm-Bonferroni adjusted p-value and corresponding significance flag for the iteration.
(Only when overlap = TRUE) A two-line label
for 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 "#1 P209\n(LR=39.6)"; for
iterative scans it looks like
"Iter 1: P209\n(LR=39.6, p_adj=0.005)". The newline
keeps long node identifiers from overflowing the strip in
multi-panel layouts.
treespatial_scan, circular_scan,
iterative_scan, filter_clusters
data(london_collisions); data(london_tree)
result <- treespatial_scan(
cases = london_collisions$cases,
population = london_collisions$population,
region_id = london_collisions$region_id,
x = london_collisions$x,
y = london_collisions$y,
node_id = london_collisions$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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.