# R - Understanding output of the Knoxtest (Package (surveillance))

The function knox of the "Surveillance" package performs Knox test for space-time interaction. The output is supposed to give the numbers of events that occur in a specific distance in space and time define by the function arguments. This function also perform a Monte Carlo permutation test, which give the estimated value (based on a random distribution) which are supposed to be compared to the observed value. This comparison gives a ratio which means the chance that event occur in a specific distance in time and space.

Here is the example of the function and it's output:

    library(surveillance)
data("imdepi")
imdepiB <- subset(imdepi, type == "B")

## Obtain the p-value via a Monte Carlo permutation test,
## where the permutations can be computed in parallel
## (using forking on Unix-alikes and a cluster on Windows, see ?plapply)
knoxtest <- knox(
dt = dist(imdepiB$events$time), eps.t = 30,
ds = dist(coordinates(imdepiB$events)), eps.s = 50, simulate.p.value = TRUE, B = 19, .parallel = 2, .seed = 1, .verbose = FALSE ) knoxtest  Output: Knox test with Poisson approximation data: dt = dist(imdepiB$events$time) and ds = dist(coordinates(imdepiB$events))
number of close pairs = 204, lambda = 181.57, p-value = 0.04649
alternative hypothesis: true number is greater than 181.5686

contingency table:
ds
dt      <= 50  > 50
<= 30   204  1295
> 30  6613 48168


The "imdepi" dataset include 636 events, so, the output isn't a count of the event occuring in a specific distance in space and time. Also, even if I change the value of "B", which correspond to the number of permutation for the Monte Carlo approach, the results stays the same.

What the numbers of output contingency table mean?

How the Monte Carlo iteration influence the results?

Here are the links to the Knox Test function Description and it's Code.

The Knox test looks at the pairwise spatial and temporal distances of a set of events and checks if events closer in time also tend to be closer in space. What "close" means is defined for the specific application at hand by choosing spatial and temporal distance thresholds. To answer your first question, consider that applying these thresholds results in a two-by-two contingency table of event pairs being close/not close in space/time. The corresponding test statistic is the "number of close pairs", 204 in this example, or the top-left cell of the printed contingency table. With nobs(imdepiB) = 336 events in this example, there are $336\cdot 335 / 2 = 56280$ event pairs, which equals sum(knoxtest$table). To answer your second question I first have to clarify that I do not get the output stated by you when running the example code. Instead, both with R 3.0.2 + surveillance 1.11.0 and with R.3.3.0 + the current development version of surveillance I get: > knoxtest Knox test with simulated p-value data: dt = dist(imdepiB$events$time) and ds = dist(coordinates(imdepiB$events))

Your output seems to be from a call of the knox() test with simulate.p.value = FALSE, as indicated by the title "Knox test with Poisson approximation". In this case, the argument B has no meaning. However, with simulate.p.value = TRUE, increasing B will increase the number of Monte Carlo samples and thus the "resolution" of the $p$-value.