Skip to content
Prev 7019 / 29559 Next

Converting nb list containing areas with no neighbours with nb2WB()

On Wed, 25 Nov 2009, Xingli Giam wrote:

            
The problem is caused by the nb object encoding no-neighbour status with 
an integer vector of length 1 containing 0. Please try this patched 
version:

nb2WB <- function(nb)
{
   	if (!inherits(nb, "nb")) stop("not a neighbours list")
         num <- card(nb)
         if (any(num == 0)) nb[num == 0] <- NULL
         adj <- unlist(nb)
         weights <- rep(1, sum(num))

         list(adj=adj, weights=weights, num=num)
}

It works for me so far, and num now contains the correct 0 for observation 
233. I haven't tried it with WinBUGS though.

Hope this helps,

Roger