Skip to contents

Counts the pairs near in space and near in time, \(J_k = \sum_i \sum_j a_{ij} b_{ij}\), where \(a_{ij}\) marks \(j\) among \(i\)'s \(k\) nearest neighbours in space and \(b_{ij}\) the same in time. Neither indicator is symmetric, so the sum runs over ordered pairs.

Usage

morie_jacquez_knn(coords, time, k = 3L, B = 999L)

Arguments

coords

Numeric matrix of case locations (n x d).

time

Numeric vector of case times, length n.

k

Number of nearest neighbours, in space and time alike.

B

Number of time-label permutations. Default 999.

Value

Named list with statistic, p_value, expected, k, n, B, null_statistics, method.

Details

The statistic is a count, so it does not depend on the units of the coordinates or the clock and stays valid for irregular regions. That is also why the null is simulated: under no interaction the time labels are exchangeable, so permuting them and ranking the observed count gives \(p = (1 + \#\{J^{(b)} \ge J^{obs}\}) / (1 + B)\).

Mirrors morie.fn.jacqkn on the Python side.

References

Jacquez GM (1996). A k nearest neighbour test for space-time interaction. Statistics in Medicine, 15(18), 1935-1949.

Examples

set.seed(1)
morie_jacquez_knn(matrix(runif(60), 30, 2), runif(30), k = 3, B = 99)$p_value
#> [1] 0.76