Skip to contents

Recomputes a spatial statistic on n_sim random permutations of the values over the fixed locations and ranks the observed value among them (Besag and Diggle 1977). The default statistic is Moran's I with inverse-distance weights; a statistic that ignores the locations is permutation-invariant and can never reject. Permutations are Fisher-Yates shuffles on the package's Philox stream. Identical to the Python arm morie.fn.sgmci.monte_carlo_spatial_test.

Usage

monte_carlo_spatial_test(Z, coords, stat_fn = NULL, n_sim = 999, seed = 42)

Arguments

Z

Numeric vector of observed values.

coords

Two-column matrix of coordinates.

stat_fn

Optional function (z, coords) returning the statistic.

n_sim

Number of permutations.

seed

Philox seed.

Value

A list with value and observed (the statistic), envelope_lo, envelope_hi (2.5 and 97.5 percent points of the permutation distribution), p_value (upper tail), p_two_sided, n_sim, sim_mean, significant and statistic.

References

Besag, J. and Diggle, P. J. (1977). Simple Monte Carlo tests for spatial pattern. Applied Statistics 26, 327-333.

Cliff, A. D. and Ord, J. K. (1981). Spatial Processes: Models and Applications. Pion.

Examples

xy <- cbind(c(0, 1, 2, 0, 1, 2), c(0, 0, 0, 1, 1, 1))
monte_carlo_spatial_test(c(1, 1.2, 0.9, 2, 2.4, 2.2), xy, n_sim = 99)$p_value
#> [1] 0.26