[R-sig-Geo] Error in print(data.frame) & zero.policy

Roger Bivand Roger.Bivand at nhh.no
Mon Apr 9 17:13:20 CEST 2012


On Mon, 9 Apr 2012, Zz wrote:

> Dear spdep users,
>
>
>
> I tried to follow below command to create a neighborhood list.   The
> data "Matrix.txt"
> is enclosed
>
>
>> mat0 <- read.table("Matrix.txt", header=FALSE, sep="\t", fill=TRUE)
>> mat <- as.matrix(mat0)
>> dim(mat)
> [1] 46 46
>> summary(c(mat))
>   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's
>      1       1       1       1       1       1    1918
>> mat[is.na(mat)] <- 0
>> summary(c(mat))
>   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
> 0.00000 0.00000 0.00000 0.09357 0.00000 1.00000
>> lw <- mat2listw(mat, style="B")
> Warning message:
> In nb2listw(res$neighbours, glist = res$weights, style = style,  :
>  zero sum general weights
>> summary(lw)
> Characteristics of weights list object:
> Neighbour list object:
> Number of regions: 46
> Number of nonzero links: 198
> Percentage nonzero weights: 9.357278
> Average number of links: 4.304348
> 2 regions with no links:
> 2 18
> Link number distribution:
>
> 0  2  3  4  5  6  7  8
> 2  5  5 14  8  9  1  2
> 5 least connected regions:
> 7 8 9 36 41 with 2 links
> 2 most connected regions:
> 24 38 with 8 links
>
> Weights style: B
> Weights constants summary:
> Error in print(data.frame(rbind(unlist(spweights.constants(object,
> zero.policy = zero.policy))[c(1,  :
>  error in evaluating the argument 'x' in selecting a method for function
> 'print': Error in spweights.constants(object, zero.policy = zero.policy) :
>  regions with no neighbours found

The error message says: "regions with no neighbours found". If you permit 
no-neighbour observations by using:

summary(lw, zero.policy=TRUE)

or equivalently:

get.ZeroPolicyOption()
set.ZeroPolicyOption(TRUE)
summary(lw)
set.ZeroPolicyOption(FALSE)
get.ZeroPolicyOption()

you can proceed. The lagged value of a no-neighbour observation is not 
well defined, as setting 0 may be misleading, and setting NA will break 
the next operations, in this case calculating measures based on the 
weights. Setting zero.policy=TRUE sets 0.

Roger

>> is.symmetric.nb(lw$neighbours)
> [1] TRUE
>
>
>
> The neighborhood list cannot be used in spatial regression.    The main
> error seems to be "Error in
> print(data.frame(rbind(unlist(spweights.constants(object, zero.policy =
> zero.policy))[c(1,  :
>  error in evaluating the argument 'x' in selecting a method for function
> 'print': Error in spweights.constants(object, zero.policy = zero.policy) :
>  regions with no neighbours found"
>
>
> Is there anyone know what wrong with the data?  I have tried to add
> "zero.policy=true".  Thanks
>
>
>
>
> Happy Easter
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list