generate_example_data: Generate Example Data for Tree-Spatial Scan

View source: R/generate_example_data.R

generate_example_dataR Documentation

Generate Example Data for Tree-Spatial Scan

Description

Creates a synthetic dataset for demonstrating and testing the tree-spatial scan statistic. Returns parallel vectors (cases, population, region_id, x, y, node_id) and a tree, matching the input format expected by treespatial_scan.

Usage

generate_example_data(
  n_regions = 50L,
  pop_per_region = 1000,
  cluster_regions = 1:7,
  cluster_leaves = c(3, 4),
  rr = 2,
  Cg = 200L,
  seed = NULL
)

Arguments

n_regions

Integer. Default 50.

pop_per_region

Numeric. Default 1000.

cluster_regions

Integer vector. Default 1:7.

cluster_leaves

Integer vector. Default c(3, 4).

rr

Numeric. Relative risk. Default 2.0.

Cg

Integer. Cases per branch. Default 200.

seed

Integer or NULL. Random seed. When non-NULL, the user's pre-existing RNG state is saved on entry and restored on exit, so the seed argument affects only the result of the call. Default NULL (the user's session-level RNG state is used as-is and is not modified by the function).

Value

A list with vector components ready to feed into treespatial_scan: cases, population, region_id, x, y, node_id, plus the tree (data.frame) and a true_cluster list describing the injected cluster.

Examples

ex <- generate_example_data(seed = 42)
result <- treespatial_scan(
  cases       = ex$cases,
  population  = ex$population,
  region_id   = ex$region_id,
  x           = ex$x,
  y           = ex$y,
  node_id     = ex$node_id,
  tree        = ex$tree,
  nsim        = 99
)
print(result)

treeSS documentation built on May 16, 2026, 1:08 a.m.