I am trying to estimate a spatial SAR model using the lagsarlm
command and I get the following error:
Error in lagsarlm(f1, data = df, spatialList, tol.solve = 1e-30) : NAs in lagged dependent variable In addition: Warning message: In lag.listw(listw, y, zero.policy = zero.policy) : NAs in lagged values
Apparently, this happens because I have islands (observations that are not connected to any other observation). If I run the following code without creating an island (by deleting W[1,1:50] <- 0), the code works just fine.
library(spdep)
library(spatialreg)
library(sna)
set.seed(123)
W <- rgraph(50, m=1, tprob=0.1, mode="graph", diag=FALSE)
W[1,1:50] <- 0
spatialList <- mat2listw(W)
y <- rnorm(50)
x <- rnorm(50)
df <- cbind.data.frame(y,x)
f1 <- y ~ x
m2s = lagsarlm(f1, data=df, spatialList, tol.solve=1.0e-30)
This is just a toy example. Given that my real matrix has several islands, any ideas about how to proceed with the estimation?
Many thanks