Skip to contents

With OLS residuals e, \(\sigma^2 = e'e/n\), \(T = tr(W'W + WW)\) and \(J = ((W\hat y)' M (W\hat y) + T\sigma^2)/(n\sigma^2)\): RSerr \((e'We/\sigma^2)^2/T\), RSlag \((e'Wy/\sigma^2)^2/(nJ)\), the robust adjRSerr and adjRSlag (Anselin, Bera, Florax and Yoon 1996) and SARMA (adjRSlag + RSerr, 2 df), each against chi-square (NaN when a denominator vanishes, e.g. W = cI); exactly spdep::lm.RStests with test = "all".

Usage

LMSpatialTests(y, X, W)

Arguments

y

Response.

X

Design matrix including any intercept column.

W

Spatial weights matrix.

Value

Named list (RSerr, RSlag, adjRSerr, adjRSlag, SARMA) of lists with statistic, df, p_value.

References

Anselin, L. (1988). Spatial Econometrics: Methods and Models. Kluwer, Dordrecht.

Anselin, L., Bera, A. K., Florax, R. and Yoon, M. J. (1996). Simple diagnostic tests for spatial dependence. Regional Science and Urban Economics 26, 77-104.

Examples

W <- 1 * (abs(outer(1:8, 1:8, "-")) == 1)
W <- W / rowSums(W)
X <- cbind(1, c(.1, .6, .2, .9, .3, .5, .8, .4))
LMSpatialTests(c(1, 2.2, 1.4, 3.1, .9, 2, 2.6, 1.1), X, W)$RSerr$statistic
#> [1] 0.003086626