[R-sig-Geo] ArcGIS SWMs in R

Scott L Minkoff Scott.Minkoff at Colorado.EDU
Mon Apr 26 23:23:32 CEST 2010


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

Thanks, 
Scott

-----Original Message-----
From: r-sig-geo-bounces at stat.math.ethz.ch
[mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf Of Scott L Minkoff
Sent: Monday, April 26, 2010 1:55 PM
To: r-sig-geo at 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 at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list