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.

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.

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

--
Heather Sander
Ph.D. Candidate:  Conservation Biology
Office:  305 Ecology & 420 Blegen
Mail: University of Minnesota
Dept. of Geography
414 Social Science Bldg.
267 19th Ave. S.
Minneapolis, MN 55455
USA

_______________________________________________
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