Fits the spatial lag model y = rho W y + X beta + e. W y is
endogenous, so it is instrumented with [X, WX, W^2 X] – the
Kelejian and Prucha (1998) instrument set that spatialreg::stsls
uses. Ordinary least squares on this model is inconsistent.
Examples
set.seed(1)
n <- 20
W <- matrix(0, n, n)
for (i in 1:(n - 1)) { W[i, i + 1] <- 1; W[i + 1, i] <- 1 }
W <- W / pmax(rowSums(W), 1)
X <- matrix(rnorm(n), n, 1)
y <- as.numeric(solve(diag(n) - 0.3 * W) %*% (2 * X[, 1] + rnorm(n)))
morie_spatial_2sls(y, X, W)
#> $rho
#> [1] 0.4561389
#>
#> $beta
#> [1] -0.05443898 1.76844227
#>
#> $coefficients
#> [1] 0.45613892 -0.05443898 1.76844227
#>
#> $residuals
#> [1] 0.67987571 0.98239679 -0.23217975 -1.56330931 0.76751456 -0.33895550
#> [7] 0.10457690 -1.35782304 -0.35650117 -0.02393266 1.62326036 -0.21336075
#> [13] 0.57219052 -0.41173560 -0.65696029 -0.36636726 -0.48595836 -0.05113950
#> [19] 0.92681883 0.40158951
#>
#> $sigma2
#> [1] 0.5806859
#>
#> $n
#> [1] 20
#>
