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.
