[R-sig-Geo] Spatial lags using gridded data
Steve Pickering
pickering at penguin.kobe-u.ac.jp
Thu Aug 21 02:25:30 CEST 2014
Hello, all,
Sorry for the silly question.
I'm struggling to apply spatial lags to a data grid. I've been
working through the notes on Luc Anselin's spdep, but just can't
figure out how to apply it to gridded data.
Consider the following very simple 5 x 5 grid:
ids <- c(1:25)
lats <- c(30,30,30,30,30,31,31,31,31,31,32,32,32,32,32,33,33,33,33,33,34,34,34,34,34)
lngs <- c(10,11,12,13,14,10,11,12,13,14,10,11,12,13,14,10,11,12,13,14,10,11,12,13,14)
conflict <- c(0,0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,1,0,0,0,0,0,0,0,0)
conflictLag <- c(0,0,0.125,0.125,0.125,0,0.125,0.375,0.25,0.25,0.125,0.25,0.375,0.25,0.25,0.125,0.125,0.375,0.25,0.125,0.125,0.125,0.125,0,0)
pop <- sample(100, 25)
newGrid = data.frame(ids, lats, lngs, conflict, conflictLag, pop)
Here, I have a conflict dummy, to determine whether there was some
sort of conflict or war in that grid cell. I also have a population
variable (for the purposes of this exercise, determined at random).
If I wanted to run a regression on this without including spatial
lags, I could do something very simple, like this:
model1 = lm(newGrid$conflict ~ newGrid$pop)
summary(model1)
However, I know that I am supposed to include a spatial lag. As you
can see in the code, I have also created a spatial lag variable based
on whether there was conflict in adjacent cells (Queen's move, hence a
fraction of eight).
What I'm struggling with is the correct way to include the spatial lag
in my model.
Thanks, and sorry for the simple question.
- Steve.
More information about the R-sig-Geo
mailing list