Skip to content
Prev 27714 / 29559 Next

poly2nb neighbour itself should be considered a neighbour

Hello,

I found this matter easier when working with matrix representations. Set

 ?A^0 = I (identity matrix),

 ?A^1 = A, where A_{ij} = 1 if j is neighbor to j and zero otherwise 
(this consider A_{ii} = 0)

 ?A^2 = A'A

 ?A^3 = A'A^2 and so on

The A^k_{ij} entry gives _how many steps of length k there is between i 
and j_. To me, this definition makes this matter clear. See an example 
considering a 10x10 regular grid:

nb <- grid2nb(d=c(10,10), queen = FALSE)
nn <- card(nb)
A1 <- sparseMatrix(
 ?i = rep(1:length(nn), nn),
 ?j = unlist(nb[nn>0]), x=1)
A2 <- crossprod(A1)
image(A1)
image(A2)

best regards,

Elias
On 03/11/2019 17:46, Dexter Locke wrote: