Skip to contents

Source: the reference implementation spdep::joincount.test (Bivand, spdep 1.4-2, R/jc.R), whose comments cite Cliff, A. D. and Ord, J. K. (1981), Spatial Processes: Models and Applications, Pion, page 20, equations (1.31) and (1.32) for nonfree sampling: E[J_kk] = S0 n_k (n_k - 1) / (2 N (N-1)) and 4 Var + 4 E^2 = S1 n_k(n_k-1)/(N(N-1)) + (S2 - 2 S1) n_k(n_k-1)(n_k-2)/(N(N-1)(N-2)) + (S0^2 + S1 - S2) n_k(n_k-1)(n_k-2)(n_k-3)/(N(N-1)(N-2)(N-3)), with S0 = sum w_ij, S1 = 0.5 sum (w_ij + w_ji)^2 and S2 = sum_i (rowsum_i + colsum_i)^2. The variance is defined only for n_k >= 4; NaN is returned below that.

Usage

Joincnt(x, W)

Arguments

x

Binary vector of length N coded 0/1.

W

N x N spatial weights matrix; the diagonal is ignored.

Value

list: BB, WW, BW, E_BB, E_WW, V_BB, V_WW, z_BB, z_WW, p_BB, p_WW, S0, S1, S2, n, method.

Examples

W <- matrix(0, 8, 8)
for (i in 1:7) {
  W[i, i + 1] <- 1
  W[i + 1, i] <- 1
}
Joincnt(c(1, 1, 1, 1, 0, 0, 0, 0), W)$BB
#> [1] 3