rspatialspdep

How to estimate spatial SAR model with islands?


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


Solution

  • The lagsarlm function has a zero.policy argument, which is FALSE by default, which means that the function will terminate with an error if there are zeros in the data and you omit this argument. SO, change it to TRUE.

    m2s = lagsarlm(f1, data=df, spatialList, tol.solve=1.0e-30, zero.policy=TRUE)
    m2s
    

    Call:
    lagsarlm(formula = f1, data = df, listw = spatialList, zero.policy = TRUE, 
        tol.solve = 1e-30)
    Type: lag 
    
    Coefficients:
             rho  (Intercept)            x 
    -0.007533119  0.209226752  0.058315953 
    
    Log likelihood: -71.21548
    

    From the help page:

    zero.policy
    default NULL, use global option value; if TRUE assign zero to the lagged value of zones without neighbours, if FALSE (default) assign NA - causing lagsarlm() to terminate with an error