Skip to contents

morie_spatial_lag_model fits y = rho W y + X beta + eps and morie_spatial_error_model fits y = X beta + u, u = lambda W u + eps. Both maximise Ord's concentrated log-likelihood, so only the spatial parameter is searched and the rest follows in closed form. Ordinary least squares on the lag model is inconsistent, which is why the lag version exists at all.

Usage

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

morie_spatial_error_model(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 the spatial parameter, beta, sigma2, loglik and residuals

Examples

set.seed(1)
n <- 25
W <- matrix(0, n, n)
for (i in 2:n) W[i, i - 1] <- W[i - 1, i] <- 1   # a chain of neighbours
W <- W / rowSums(W)
x <- rnorm(n)
y <- 0.4 * as.numeric(solve(diag(n) - 0.4 * W, x + rnorm(n))) + 1
morie_spatial_lag_model(y, X = x, W = W)$rho
#> [1] 0.2649461