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

Zz fairyland118 at gmail.com
Mon Apr 9 22:28:51 CEST 2012


Dear Prof Bivand,



You are very helpful. Following your instruction,  I can create listw
and regress
now.



Meanwhile,  I would like to row-standardize a square matrix before changing
it into a listw file.



library(spdep)

mat0 <- read.csv(file="46states.csv", h=F)

mat0 [is.na(mat0)] <- 0

mat<- as.matrix(mat0, zero.policy=TRUE)

mat<- mat /apply(mat, 1, sum, zero.policy=TRUE)

summary(mat, zero.policy=TRUE)

lw <- mat2listw(mat)

*Error in mat2listw(mat) : x must be a square matrix*
summary(lw, zero.policy=TRUE)





*Attached is the data. * Usually the above commands work very well.  But
this time,  I have tried to add *zero.policy=TRUE*  in different places of
commands in vain.



Thank you so much for your time.






Best regard
Zz

On Mon, Apr 9, 2012 at 11:13 AM, Roger Bivand <Roger.Bivand at nhh.no> wrote:

> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120409/94f54450/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 46states.csv
Type: text/csv
Size: 2269 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20120409/94f54450/attachment.bin>


More information about the R-sig-Geo mailing list