# NOT RUN {
set.seed(1)
# Create location coordinates, calculate nearest neighbors, and create zones
n_locs <- 50
max_duration <- 5
n_total <- n_locs * max_duration
geo <- matrix(rnorm(n_locs * 2), n_locs, 2)
knn_mat <- coords_to_knn(geo, 15)
zones <- knn_zones(knn_mat)
# Simulate data
baselines <- matrix(rexp(n_total, 1/5), max_duration, n_locs)
thetas <- matrix(runif(n_total, 0.05, 3), max_duration, n_locs)
counts <- matrix(rnbinom(n_total, mu = baselines, size = thetas),
max_duration, n_locs)
# Inject outbreak/event/anomaly
ob_dur <- 3
ob_cols <- zones[[10]]
ob_rows <- max_duration + 1 - seq_len(ob_dur)
counts[ob_rows, ob_cols] <- matrix(
rnbinom(ob_dur * length(ob_cols),
mu = 2 * baselines[ob_rows, ob_cols],
size = thetas[ob_rows, ob_cols]),
length(ob_rows), length(ob_cols))
res <- scan_eb_negbin(counts = counts,
zones = zones,
baselines = baselines,
thetas = thetas,
type = "hotspot",
n_mcsim = 99,
max_only = FALSE)
# }
Run the code above in your browser using DataLab