Skip to contents

Fits y = X beta + u with u = lambda W u + e by the Kelejian and Prucha (1999) moment conditions, solved as nonlinear least squares. Unlike maximum likelihood this never needs det(I - lambda W). Mirrors spatialreg::GMerrorsar.

Usage

morie_gm_error_sar(y, X, W, add_intercept = TRUE)

Arguments

y

numeric response

X

predictor matrix

W

spatial weights matrix

add_intercept

prepend an intercept column

Value

list with lambda, beta, residuals and sigma2

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)
u <- as.numeric(solve(diag(n) - 0.4 * W) %*% rnorm(n))
y <- as.numeric(2 * X[, 1] + u)
morie_gm_error_sar(y, X, W)
#> $lambda
#> [1] 0.622637
#> 
#> $beta
#> [1] 0.03070584 1.75840144
#> 
#> $residuals
#>  [1]  1.1469041  1.0386194 -0.3474481 -1.6173483  0.2502168 -0.3494283
#>  [7] -0.4361064 -1.5686654 -0.5963619  0.4787807  1.8659344  0.3437945
#> [13]  0.2033196 -0.8638658 -1.3644732 -0.8859178 -0.5758758  0.3068375
#> [19]  1.5530949  1.4301136
#> 
#> $sigma2
#> [1] 0.5618464
#> 
#> $criterion
#> [1] 1.247917e-05
#> 
#> $n
#> [1] 20
#>