<p class="MsoNormal"><span class="gd"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">Dear Prof </span></span><span class="gd"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">Bivan</span>d,</span></p>
<p class="MsoNormal"><span class="gd"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US"> </span></span></p>
<p class="MsoNormal"><span class="gd"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">You are very helpful. Following your instruction, I can create </span></span><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">listw and <span class="gd">regress
now.</span></span></p>
<p class="MsoNormal"><span class="gd"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US"> </span></span></p>
<p class="MsoNormal"><span class="gd"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">Meanwhile,<span style> </span>I would like to </span></span><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">row-standardize a square
matrix before changing it into a listw file. </span></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US"> </span></p>
<p style="color:rgb(0,0,153)" class="MsoNormal"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">library(spdep)</span></p>
<p class="MsoNormal" style="color:rgb(0,0,153)"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">mat0 <- read.csv(file="46states.csv",
h=F)</span></p>
<p class="MsoNormal" style="color:rgb(0,0,153)"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">mat0 [<a href="http://is.na">is.na</a>(mat0)] <- 0</span></p>
<p class="MsoNormal" style="color:rgb(0,0,153)"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">mat<- as.matrix(mat0, zero.policy=TRUE)</span></p>
<p class="MsoNormal" style="color:rgb(0,0,153)"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">mat<- mat /apply(mat, 1, sum</span><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">, </span><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">zero.policy=TRUE)</span></p>
<p class="MsoNormal" style="color:rgb(0,0,153)"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">summary(mat, zero.policy=TRUE)</span></p>
<p class="MsoNormal" style="color:rgb(0,0,153)"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">lw <- mat2listw(mat)</span></p>
<p class="MsoNormal"><b><span style="font-size:12.0pt;font-family:Arial;color:red" lang="EN-US">Error in mat2listw(mat) : x must be a square matrix</span></b><span style="font-size:12.0pt;font-family:Arial" lang="EN-US"><br>
<span style="color:rgb(0,0,153)">summary(lw, zero.policy=TRUE)</span></span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p>
<p class="MsoNormal"><span class="gd"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US"><b>Attached is the data. </b> Usually the above commands work very well. But this time, </span></span><span style="font-size:12.0pt;font-family:Arial;color:red" lang="EN-US"></span><span style="font-size:12pt;font-family:Arial" lang="EN-US">I have tried to add<span style="color:rgb(255,102,0)"> <b>zero.policy=TRUE</b> </span><span style> </span>in different places of commands<span style></span> in vain.</span></p>
<p class="MsoNormal"><span style="font-size:12pt;font-family:Arial" lang="EN-US"><br></span></p><p class="MsoNormal"><br></p><p class="MsoNormal"><span class="gd"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US"> Thank you so much for your time.</span></span></p>
<p class="MsoNormal"><br><span style="font-size:12.0pt;font-family:Arial" lang="EN-US"><span class="gd"></span></span></p>
<p class="MsoNormal"><span class="gd"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US"> </span></span></p>
<p class="MsoNormal"><span class="gd"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US"> </span></span></p>
<p class="MsoNormal"><span class="gd"><span style="font-size:12.0pt;font-family:Arial" lang="EN-US">Best regard</span></span></p>
Zz<br><br><div class="gmail_quote">On Mon, Apr 9, 2012 at 11:13 AM, Roger Bivand <span dir="ltr"><<a href="mailto:Roger.Bivand@nhh.no">Roger.Bivand@nhh.no</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Mon, 9 Apr 2012, Zz wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear spdep users,<br>
<br>
<br>
<br>
I tried to follow below command to create a neighborhood list. The<br>
data "Matrix.txt"<br>
is enclosed<br>
<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
mat0 <- read.table("Matrix.txt", header=FALSE, sep="\t", fill=TRUE)<br>
mat <- as.matrix(mat0)<br>
dim(mat)<br>
</blockquote>
[1] 46 46<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
summary(c(mat))<br>
</blockquote>
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's<br>
1 1 1 1 1 1 1918<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
mat[<a href="http://is.na" target="_blank">is.na</a>(mat)] <- 0<br>
summary(c(mat))<br>
</blockquote>
Min. 1st Qu. Median Mean 3rd Qu. Max.<br>
0.00000 0.00000 0.00000 0.09357 0.00000 1.00000<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
lw <- mat2listw(mat, style="B")<br>
</blockquote>
Warning message:<br>
In nb2listw(res$neighbours, glist = res$weights, style = style, :<br>
zero sum general weights<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
summary(lw)<br>
</blockquote>
Characteristics of weights list object:<br>
Neighbour list object:<br>
Number of regions: 46<br>
Number of nonzero links: 198<br>
Percentage nonzero weights: 9.357278<br>
Average number of links: 4.304348<br>
2 regions with no links:<br>
2 18<br>
Link number distribution:<br>
<br>
0 2 3 4 5 6 7 8<br>
2 5 5 14 8 9 1 2<br>
5 least connected regions:<br>
7 8 9 36 41 with 2 links<br>
2 most connected regions:<br>
24 38 with 8 links<br>
<br>
Weights style: B<br>
Weights constants summary:<br>
Error in print(data.frame(rbind(unlist(<u></u>spweights.constants(object,<br>
zero.policy = zero.policy))[c(1, :<br>
error in evaluating the argument 'x' in selecting a method for function<br>
'print': Error in spweights.constants(object, zero.policy = zero.policy) :<br>
regions with no neighbours found<br>
</blockquote>
<br></div></div>
The error message says: "regions with no neighbours found". If you permit no-neighbour observations by using:<br>
<br>
summary(lw, zero.policy=TRUE)<br>
<br>
or equivalently:<br>
<br>
get.ZeroPolicyOption()<br>
set.ZeroPolicyOption(TRUE)<br>
summary(lw)<br>
set.ZeroPolicyOption(FALSE)<br>
get.ZeroPolicyOption()<br>
<br>
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.<br>
<br>
Roger<div class="HOEnZb"><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
is.symmetric.nb(lw$neighbours)<br>
</blockquote>
[1] TRUE<br>
<br>
<br>
<br>
The neighborhood list cannot be used in spatial regression. The main<br>
error seems to be "Error in<br>
print(data.frame(rbind(unlist(<u></u>spweights.constants(object, zero.policy =<br>
zero.policy))[c(1, :<br>
error in evaluating the argument 'x' in selecting a method for function<br>
'print': Error in spweights.constants(object, zero.policy = zero.policy) :<br>
regions with no neighbours found"<br>
<br>
<br>
Is there anyone know what wrong with the data? I have tried to add<br>
"zero.policy=true". Thanks<br>
<br>
<br>
<br>
<br>
Happy Easter<br>
<br>
</blockquote>
<br></div></div><span class="HOEnZb"><font color="#888888">
-- <br>
Roger Bivand<br>
Department of Economics, NHH Norwegian School of Economics,<br>
Helleveien 30, N-5045 Bergen, Norway.<br>
voice: <a href="tel:%2B47%2055%2095%2093%2055" value="+4755959355" target="_blank">+47 55 95 93 55</a>; fax <a href="tel:%2B47%2055%2095%2095%2043" value="+4755959543" target="_blank">+47 55 95 95 43</a><br>
e-mail: <a href="mailto:Roger.Bivand@nhh.no" target="_blank">Roger.Bivand@nhh.no</a><br>
<br>
</font></span></blockquote></div><br>