[R-sig-Geo] Spatial filtering with glm with grid sampling

Sima Usvyatsov ghiaco at gmail.com
Wed Jan 10 17:32:36 CET 2018


Hello,

I am running a negative binomial model (MASS) on count data collected on a
grid. The dataset is large - ~4,000 points, with many predictors. Being
counts, there are a lot of zeroes. All data are collected on a grid with 20
points, with high spatial autocorrelation.

I would like to filter out the spatial autocorrelation. My question is:
since I have very limited spatial info (only 20 distinct spatial
locations), is it possible to simplify ME() so that I don't have to run it
on the whole dataset? When I try to run ME() on a 100-point subset of the
data, I get error in glm.fit: NA/NaN/Inf in 'x'. When I run it on a single
instance of the grid, I "get away" with a warning ("algorithm did not
converge").

Here's a fake dataset. It was grinding for a while but not throwing errors
(like my original data would). Regardless, it demonstrates the repeated
sampling at the same points and the large number of zeroes.

Any advice would be most welcome.

library(spdep)
library(MASS)

df <- data.frame(Loc = as.factor(rep(1:20, each = 5)), Lat = rnorm(100, 30,
0.1), Lon = rnorm(1000, -75, 1), x = rnegbin(100, 1, 1))
coordinates(df) <- ~Lon + Lat
proj4string(df) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
nb <- dnearneigh(x=coordinates(df), d1=0, d2=200,longlat = TRUE)
dists <- nbdists(nb, coordinates(df), longlat=TRUE)
glist <- lapply(dists, function(x) 1/x)
lw <- nb2listw(nb, glist, style="W")
me <- ME(x ~ 1, data = df, family = "quasipoisson", listw = lw, alpha = 0.5)

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list