Spatial Regression Models (spreg)

spreg, short for “spatial regression,” is a python package to estimate simultaneous autoregressive spatial regression models. These models are useful when modeling processes where observations interact with one another. For more information on these models, consult the Spatial Regression short course by Luc Anselin (Spring, 2017), with the Center for Spatial Data Science at the University of Chicago:


Installation

spreg is installable using the Python Package Manager, pip. To install:

pip install spreg

Further, all of the stable functionality is also available in PySAL, the Python Spatial Analysis Library. PySAL can be installed using pip or conda:

pip install pysal #or
conda install pysal

API reference

Spatial Regression Models

These are the standard spatial regression models supported by the spreg package. Each of them contains a significant amount of detail in their docstring discussing how they’re used, how they’re fit, and how to interpret the results.

spreg.OLS(y, x[, w, robust, gwk, sig2n_k, …])

Ordinary least squares with results and diagnostics.

spreg.ML_Lag(y, x, w[, method, epsilon, …])

ML estimation of the spatial lag model with all results and diagnostics; [Ans88]

spreg.ML_Error(y, x, w[, method, epsilon, …])

ML estimation of the spatial error model with all results and diagnostics; [Ans88]

spreg.GM_Lag(y, x[, yend, q, w, w_lags, …])

Spatial two stage least squares (S2SLS) with results and diagnostics; Anselin (1988) [Ans88]

spreg.GM_Error(y, x, w[, vm, name_y, …])

GMM method for a spatial error model, with results and diagnostics; based on Kelejian and Prucha (1998, 1999) [KP98] [KP99].

spreg.GM_Error_Het(y, x, w[, max_iter, …])

GMM method for a spatial error model with heteroskedasticity, with results and diagnostics; based on [ADKP10], following [Ans11].

spreg.GM_Error_Hom(y, x, w[, max_iter, …])

GMM method for a spatial error model with homoskedasticity, with results and diagnostics; based on Drukker et al.

spreg.GM_Combo(y, x[, yend, q, w, w_lags, …])

GMM method for a spatial lag and error model with endogenous variables, with results and diagnostics; based on Kelejian and Prucha (1998, 1999) [KP98] [KP99].

spreg.GM_Combo_Het(y, x[, yend, q, w, …])

GMM method for a spatial lag and error model with heteroskedasticity and endogenous variables, with results and diagnostics; based on [ADKP10], following [Ans11].

spreg.GM_Combo_Hom(y, x[, yend, q, w, …])

GMM method for a spatial lag and error model with homoskedasticity and endogenous variables, with results and diagnostics; based on Drukker et al.

spreg.GM_Endog_Error(y, x, yend, q, w[, vm, …])

GMM method for a spatial error model with endogenous variables, with results and diagnostics; based on Kelejian and Prucha (1998, 1999) [KP98] [KP99].

spreg.GM_Endog_Error_Het(y, x, yend, q, w[, …])

GMM method for a spatial error model with heteroskedasticity and endogenous variables, with results and diagnostics; based on [ADKP10], following [Ans11].

spreg.GM_Endog_Error_Hom(y, x, yend, q, w[, …])

GMM method for a spatial error model with homoskedasticity and endogenous variables, with results and diagnostics; based on Drukker et al.

spreg.TSLS(y, x, yend, q[, w, robust, gwk, …])

Two stage least squares with results and diagnostics.

spreg.ThreeSLS(bigy, bigX, bigyend, bigq[, …])

User class for 3SLS estimation

Regimes Models

Regimes models are variants of spatial regression models which allow for structural instability in parameters. That means that these models allow different coefficient values in distinct subsets of the data.

spreg.OLS_Regimes(y, x, regimes[, w, …])

Ordinary least squares with results and diagnostics.

spreg.ML_Lag_Regimes(y, x, regimes[, w, …])

ML estimation of the spatial lag model with regimes (note no consistency checks, diagnostics or constants added) [Ans88].

spreg.ML_Error_Regimes(y, x, regimes[, w, …])

ML estimation of the spatial error model with regimes (note no consistency checks, diagnostics or constants added); Anselin (1988) [Anselin1988]

spreg.GM_Lag_Regimes(y, x, regimes[, yend, …])

Spatial two stage least squares (S2SLS) with regimes; [Ans88]

spreg.GM_Error_Regimes(y, x, regimes, w[, …])

GMM method for a spatial error model with regimes, with results and diagnostics; based on Kelejian and Prucha (1998, 1999) [KP98] [KP99].

spreg.GM_Error_Het_Regimes(y, x, regimes, w)

GMM method for a spatial error model with heteroskedasticity and regimes; based on Arraiz et al [ADKP10], following Anselin [Ans11].

spreg.GM_Error_Hom_Regimes(y, x, regimes, w)

GMM method for a spatial error model with homoskedasticity, with regimes, results and diagnostics; based on Drukker et al.

spreg.GM_Combo_Regimes(y, x, regimes[, …])

GMM method for a spatial lag and error model with regimes and endogenous variables, with results and diagnostics; based on Kelejian and Prucha (1998, 1999) [KP98] [KP99].

spreg.GM_Combo_Hom_Regimes(y, x, regimes[, …])

GMM method for a spatial lag and error model with homoskedasticity, regimes and endogenous variables, with results and diagnostics; based on Drukker et al.

spreg.GM_Combo_Het_Regimes(y, x, regimes[, …])

GMM method for a spatial lag and error model with heteroskedasticity, regimes and endogenous variables, with results and diagnostics; based on Arraiz et al [ADKP10], following Anselin [Ans11].

spreg.GM_Endog_Error_Regimes(y, x, yend, q, …)

GMM method for a spatial error model with regimes and endogenous variables, with results and diagnostics; based on Kelejian and Prucha (1998, 1999) [KP98] [KP99].

spreg.GM_Endog_Error_Hom_Regimes(y, x, yend, …)

GMM method for a spatial error model with homoskedasticity, regimes and endogenous variables.

spreg.GM_Endog_Error_Het_Regimes(y, x, yend, …)

GMM method for a spatial error model with heteroskedasticity, regimes and endogenous variables, with results and diagnostics; based on Arraiz et al [ADKP10], following Anselin [Ans11].

Seemingly-Unrelated Regressions

Seeimingly-unrelated regression models are a generalization of linear regression. These models (and their spatial generalizations) allow for correlation in the residual terms between groups that use the same model. In spatial Seeimingly-Unrelated Regressions, the error terms across groups are allowed to exhibit a structured type of correlation: spatail correlation.

spreg.SUR(bigy, bigX[, w, regimes, …])

User class for SUR estimation, both two step as well as iterated

spreg.SURerrorGM(bigy, bigX, w[, regimes, …])

User class for SUR Error estimation by Maximum Likelihood

spreg.SURerrorML(bigy, bigX, w[, regimes, …])

User class for SUR Error estimation by Maximum Likelihood

spreg.SURlagIV(bigy, bigX[, bigyend, bigq, …])

User class for spatial lag estimation using IV

spreg.ThreeSLS(bigy, bigX, bigyend, bigq[, …])

User class for 3SLS estimation

Diagnostics

Diagnostic tests are useful for identifying model fit, sufficiency, and specification correctness.

spreg.diagnostics.f_stat(reg)

Calculates the f-statistic and associated p-value of the regression.

spreg.diagnostics.t_stat(reg[, z_stat])

Calculates the t-statistics (or z-statistics) and associated p-values.

spreg.diagnostics.r2(reg)

Calculates the R^2 value for the regression.

spreg.diagnostics.ar2(reg)

Calculates the adjusted R^2 value for the regression.

spreg.diagnostics.se_betas(reg)

Calculates the standard error of the regression coefficients.

spreg.diagnostics.log_likelihood(reg)

Calculates the log-likelihood value for the regression.

spreg.diagnostics.akaike(reg)

Calculates the Akaike Information Criterion.

spreg.diagnostics.schwarz(reg)

Calculates the Schwarz Information Criterion.

spreg.diagnostics.condition_index(reg)

Calculates the multicollinearity condition index according to Belsey, Kuh and Welsh (1980) [BKW05].

spreg.diagnostics.jarque_bera(reg)

Jarque-Bera test for normality in the residuals.

spreg.diagnostics.breusch_pagan(reg[, z])

Calculates the Breusch-Pagan test statistic to check for heteroscedasticity.

spreg.diagnostics.white(reg)

Calculates the White test to check for heteroscedasticity.

spreg.diagnostics.koenker_bassett(reg[, z])

Calculates the Koenker-Bassett test statistic to check for heteroscedasticity.

spreg.diagnostics.vif(reg)

Calculates the variance inflation factor for each independent variable.

spreg.diagnostics.likratiotest(reg0, reg1)

Likelihood ratio test statistic [Gre03]

spreg.diagnostics_sp.LMtests(ols, w[, tests])

Lagrange Multiplier tests.

spreg.diagnostics_sp.MoranRes(ols, w[, z])

Moran’s I for spatial autocorrelation in residuals from OLS regression

spreg.diagnostics_sp.AKtest(iv, w[, case])

Moran’s I test of spatial autocorrelation for IV estimation.

spreg.diagnostics_sur.sur_setp(bigB, varb)

Utility to compute standard error, t and p-value

spreg.diagnostics_sur.sur_lrtest(n, n_eq, …)

Likelihood Ratio test on off-diagonal elements of Sigma

spreg.diagnostics_sur.sur_lmtest(n, n_eq, sig)

Lagrange Multiplier test on off-diagonal elements of Sigma

spreg.diagnostics_sur.lam_setp(lam, vm)

Standard errors, t-test and p-value for lambda in SUR Error ML

spreg.diagnostics_sur.surLMe(n_eq, WS, bigE, sig)

Lagrange Multiplier test on error spatial autocorrelation in SUR

spreg.diagnostics_sur.surLMlag(n_eq, WS, …)

Lagrange Multiplier test on lag spatial autocorrelation in SUR

References

Aka74

Hirotugu Akaike. A new look at the statistical model identification. IEEE transactions on automatic control, 19(6):716–723, 1974.

Ans88

Luc Anselin. Spatial Econometrics: Methods and Models. Kluwer, Dordrecht, 1988.

Ans11

Luc Anselin. GMM estimation of spatial error autocorrelation with and without heteroskedasticity. Technical Report, GeoDa Center for Geospatial Analysis and Computation, 2011.

ABFY96

Luc Anselin, Anil K Bera, Raymond Florax, and Mann J Yoon. Simple diagnostic tests for spatial dependence. Regional science and urban economics, 26(1):77–104, 1996.

AK97

Luc Anselin and Harry H Kelejian. Testing for spatial error autocorrelation in the presence of endogenous regressors. International Regional Science Review, 20(1-2):153–182, 1997.

ADKP10

Irani Arraiz, David M. Drukker, Harry H. Kelejian, and Ingmar R. Prucha. A spatial Cliff-Ord-type model with heteroskedastic innovations: Small and large sample results. Journal of Regional Science, 50(2):592–614, 2010. doi:10.1111/j.1467-9787.2009.00618.x.

BKW05

David A Belsley, Edwin Kuh, and Roy E Welsch. Regression diagnostics: Identifying influential data and sources of collinearity. Volume 571. John Wiley & Sons, 2005.

BP79

Trevor S Breusch and Adrian R Pagan. A simple test for heteroscedasticity and random coefficient variation. Econometrica: Journal of the Econometric Society, pages 1287–1294, 1979.

DEP13

David M Drukker, Peter Egger, and Ingmar R Prucha. On two-step estimation of a spatial autoregressive model with autoregressive disturbances and endogenous regressors. Econometric Reviews, 32(5-6):686–733, 2013.

DPR13

David M. Drukker, Ingmar R. Prucha, and Rafal Raciborski. A command for estimating spatial-autoregressive models with spatial-autoregressive disturbances and additional endogenous variables. The Stata Journal, 13(2):287–301, 2013. URL: https://journals.sagepub.com/doi/abs/10.1177/1536867X1301300203.

Gre03

William H Greene. Econometric analysis. Pearson Education India, 2003.

JB80

Carlos M Jarque and Anil K Bera. Efficient tests for normality, homoscedasticity and serial independence of regression residuals. Economics letters, 6(3):255–259, 1980.

KP99

H H Kelejian and I R Prucha. A generalized moments estimator for the autoregressive parameter in a spatial model. Int. Econ. Rev., 40:509–534, 1999.

KP98

Harry H Kelejian and Ingmar R Prucha. A generalized spatial two-stage least squares procedure for estimating a spatial autoregressive model with autoregressive disturbances. J. Real Estate Fin. Econ., 17(1):99–121, 1998.

KBJ82

Roger Koenker and Gilbert Bassett Jr. Robust tests for heteroscedasticity based on regression quantiles. Econometrica: Journal of the Econometric Society, pages 43–61, 1982.

S+78

Gideon Schwarz and others. Estimating the dimension of a model. The annals of statistics, 6(2):461–464, 1978.

Whi80

Halbert White. A heteroskedasticity-consistent covariance matrix estimator and a direct test for heteroskedasticity. Econometrica: Journal of the Econometric Society, pages 817–838, 1980.