Skip to contents

From the OLS fit of y on X (an intercept is prepended when X has no constant column), with residuals u, sigma2 = u'u/n, T = tr((W' + W) W), nJ = ((WXb)'M(WXb) + T sigma2) / sigma2, d_err = u'Wu / sigma2 and d_lag = u'Wy / sigma2: lmerr is RSerr = d_err^2 / T, lmlag is RSlag = d_lag^2 / nJ, lmrerr and lmrlag the robust adjRSerr and adjRSlag of Anselin, Bera, Florax and Yoon (1996), lmsarma and lmjoint the joint SARMA = adjRSlag + RSerr (2 df), and lmdiag all five (as spdep::lm.RStests). lmrerr2 is the one-sided standard normal form of the Bera-Yoon robust error score. lmslx is the Koley-Bera score test for the lagged regressors WX (k_x df) and lmsdm the joint spatial Durbin test of rho = 0 and gamma = 0 (1 + k_x df), as spdep::SD.RStests. lmkp is the Kelejian-Prucha (2001) Moran-type test for spatial error in the spatial lag model estimated by spatial 2SLS, in the Anselin-Kelejian form of miiv. sphet is the studentised Breusch-Pagan (Koenker) n R^2 of the squared residuals on (1, Z), Z defaulting to W e^2.

Usage

lmdiag(y, X, W)

lmerr(y, X, W)

lmlag(y, X, W)

lmrerr(y, X, W)

lmrlag(y, X, W)

lmsarma(y, X, W)

lmjoint(y, X, W)

lmrerr2(y, X, W)

lmslx(y, X, W)

lmsdm(y, X, W)

lmkp(y, X, W)

sphet(residuals, W, Z = NULL)

Arguments

y

Numeric response.

X

Regressor matrix.

W

Spatial weights matrix.

residuals

Residual vector.

Z

Optional matrix of variance regressors; defaults to the spatial lag of the squared residuals.

Value

A list with statistic, p_value, df and test-specific parts; lmdiag returns all five statistics and p-values.

References

Anselin, L. (1988). Lagrange multiplier test diagnostics for spatial dependence and spatial heterogeneity. Geographical Analysis 20, 1-17. 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. Bera, A. K. and Yoon, M. J. (1993). Specification testing with locally misspecified alternatives. Econometric Theory 9, 649-658. Koley, M. and Bera, A. K. (2024). To use, or not to use the spatial Durbin model? Spatial Economic Analysis 19, 30-56. Kelejian, H. H. and Prucha, I. R. (2001). On the asymptotic distribution of the Moran I test statistic with applications. Journal of Econometrics 104, 219-257. Koenker, R. (1981). A note on studentizing a test for heteroscedasticity. Journal of Econometrics 17, 107-112.

Examples

W <- rbind(c(0, 1, 0, 0, 0), c(0.5, 0, 0.5, 0, 0), c(0, 0.5, 0, 0.5, 0),
           c(0, 0, 0.5, 0, 0.5), c(0, 0, 0, 1, 0))
lmdiag(c(1, 2.5, 2, 4.5, 4), matrix(0:4), W)$RSerr
#> [1] 3.490411