On Mon, 26 Apr 2010, Scott L Minkoff wrote:
To be a bit more precise than I was in the previous note, the full error
message I get is:
Error in res[i, listw$neighbours[[i]]] <- listw$weights[[i]] :
NAs are not allowed in subscripted assignments
That helps a little - the output of traceback() would have helped more,
and shows (by grepping the source code) that the error occurs in
listw2mat(), so at least one of listw$neighbours[[i]]] is an NA. Since I
have a copy of the input data file, I see that:
summary(unlist(lw$neighbours))
Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
2.0 336.0 668.0 667.9 1006.0 1330.0 137.0
If you form the sn object dropping the possibly spurious +1 in
to=match(xx$NID+1, to_IDs):
sn <- data.frame(from=match(xx$FID2, from_IDs), to=match(xx$NID,
to_IDs), weights=xx$WEIGHT)
the sn object converts to a listw object and on to a matrix without
complaining. match() by default returns NA when no match is found. I think
the original +1 came from being misled by the 0-base in the FID values.
Hope this helps,
Roger
Thanks,
Scott
-----Original Message-----
From: r-sig-geo-boun...@stat.math.ethz.ch
[mailto:r-sig-geo-boun...@stat.math.ethz.ch] On Behalf Of Scott L Minkoff
Sent: Monday, April 26, 2010 1:55 PM
To: r-sig-geo@stat.math.ethz.ch
Subject: [R-sig-Geo] ArcGIS SWMs in R
Hello,
I am still fairly new to spatial data analysis using R and would appreciate
any help the list might be able to provide. I have been using Roger's code
to bring ArcGIS Spatial Weights Matrices into R (see below). However, when
I go to run spatial lag models, I get the following error:
"NAs are not allowed in subscripted assignments"
I have tried the various na.action arguments to no avail. Note that the
objects seem to work fine for Moran's I tests. Does anybody know how to
solve this problem?
Thanks in advance,
Scott
Roger's Script for bringing Arc SWMs into R and making them list objects:
library(foreign)
x <- read.dbf("spatialweightmatrix3.dbf")
from_IDs <- sort(unique(x$FID2))
to_IDs <- sort(unique(x$NID))
# find the IDs used
all.equal(from_IDs, to_IDs)
o <- order(x$FID2, x$NID)
# order the object
xx <- x[o,]
# convert manually to a spatial.neighbours representation
sn <- data.frame(from=match(xx$FID2, from_IDs), to=match(xx$NID+1,
to_IDs), weihts=xx$WEIGHT)
attr(sn, "n") <- length(from_IDs)
attr(sn, "region.id") <- as.character(from_IDs)
class(sn) <- c("spatial.neighbour", class(sn))
library(spdep)
lw <- sn2listw(sn)
lw
summary(sapply(lw$weights, sum))
table(card(lw$neighbours))
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: roger.biv...@nhh.no
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo