On Wed, 22 Apr 2009, evans...@umn.edu wrote:

Hi Roger,

Thanks for the response. Unfortunately, I'm still getting the same error running predict.sarlm ("Error in if (nrow(newdata) != length(listw$neighbours)) stop("mismatch between newdata and spatial weights") : argument is of length zero"). Here's what I've done since.

OK, see below for analysis


Thanks for providing the verbatim code. If this is the verbatim code, then newdata = "dak_test_data" is saying that newdata is not the data.frame object called dak_test_data, but a single element character vector - that is, nrow("dak_test_data") is NULL. However, this does not trigger the error message as such, so it could also be that you wrote newdata = dak_test_data, and nrow(dak_test_data) is not equal to

I removed quotes, but still get the same error. The dak_test_data file was imported using readShapePoly. I also tried importing the dataset using read.dbf, but still got the same error using the resulting data frame.

Then the dak_test_data is a SpatialPolygonsDataFrame, for which there is no nrow() method, leading to problems. Please get around this by saying newdata=as(dak_test_data, "data.frame") to coerce it to data frame. I'll look at providing dim methods for Spatial*DataFrame objects other than SpatialPointsDataFrame, which are in sp already; nrow() just returns dim()[1] of the object.

Thanks,

Roger


However, this does not trigger the error message as such, so it could also be that you wrote newdata = dak_test_data, and nrow(dak_test_data) is not equal to length(dak_test.10nn.listw) - or here nrow(coords), which is the test.

As you suggested, nrow(dak_test_data)is NULL and thus is not equal to length(dak_test.10nn.listw), which equals 3. nrow(coords) = 2255. Here's the sequence of code that went into creating these weights:

coords<-coordinates(dak_test_data)
rn<-sapply(slot(dak_test_data, "polygons"), function(x) slot(x, "ID"))
dak_test.10nn <- knearneigh(coords, k=10)
dak_test.10nn.nb <- knn2nb(dak_test.10nn, row.names=rn, sym=TRUE)
dak_test.10nn.listw <- nb2listw(dak_test.10nn.nb, zero.policy=TRUE)

When I ran this using the imported dbf, I used the same weights since I'm not aware of a way to create weights without tracing back to a shapefile. The data frame in this case had nrow=2255. I still received the same error message.

I'd appreciate any help you can offer in solving this problem.  Thanks.

Heather Sander


--
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

Reply via email to