flex.sim: Perform 'flex.test' on simualated data

View source: R/flex.sim.R

flex.simR Documentation

Perform flex.test on simualated data

Description

flex.sim efficiently performs flex.test on a simulated data set. The function is meant to be used internally by the flex.test function, but is informative for better understanding the implementation of the test.

Usage

flex.sim(
  nsim = 1,
  zones,
  ty,
  ex,
  type = "poisson",
  ein = NULL,
  eout = NULL,
  tpop = NULL,
  popin = NULL,
  popout = NULL,
  cl = NULL
)

Arguments

nsim

A positive integer indicating the number of simulations to perform.

zones

A list of zones to compute the test statistic over for each simulated data set.

ty

The total number of cases in the study area.

ex

The expected number of cases for each region. The default is calculated under the constant risk hypothesis.

type

The type of scan statistic to compute. The default is "poisson". The other choice is "binomial".

ein

The expected number of cases in the zone. Conventionally, this is the estimated overall disease risk across the study area, multiplied by the total population size of the zone.

eout

The expected number of cases outside the zone. This should be ty - ein and is computed automatically if not provided.

tpop

The total population in the study area.

popin

The total population in the zone.

popout

The population outside the zone. This should be tpop - popin and is computed automatically if not provided.

cl

A cluster object created by makeCluster, or an integer to indicate number of child-processes (integer values are ignored on Windows) for parallel evaluations (see Details on performance). It can also be "future" to use a future backend (see Details), NULL (default) refers to sequential evaluation.

Value

A vector with the maximum test statistic for each simulated data set.

Examples

data(nydf)
data(nyw)
coords <- with(nydf, cbind(longitude, latitude))
zones <- flex.zones(coords, w = nyw, k = 3, longlat = TRUE)
cases <- floor(nydf$cases)
ty <- sum(cases)
ex <- ty / sum(nydf$pop) * nydf$pop
ein <- zones.sum(zones, ex)
tsim <- flex.sim(nsim = 2, zones, ty, ex, ein = ein, eout = ty - ein)

smerc documentation built on Oct. 10, 2023, 5:07 p.m.