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, vm, …])

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. (2013) [DEP13], following Anselin (2011) [Ans11].

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. (2013) [DEP13], following Anselin (2011) [Ans11].

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. (2013) [DEP13], following Anselin (2011) [Ans11].

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

Discrete Choice Models

spreg.Probit(y, x[, w, optim, scalem, …])

Classic non-spatial Probit and spatial diagnostics.

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); [Ans88]

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. (2013) [DEP13], following Anselin (2011) [Ans11].

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. (2013) [DEP13], following Anselin (2011) [Ans11].

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

Seemingly-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: spatial 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

Panel Models

spreg.Panel_FE_Lag(y, x, w[, epsilon, vm, …])

ML estimation of the fixed effects spatial lag model with all results and diagnostics [Elh03].

spreg.Panel_FE_Error(y, x, w[, epsilon, vm, …])

ML estimation of the fixed effects spatial error model with all results and diagnostics [Elh03].

spreg.Panel_RE_Lag(y, x, w[, epsilon, vm, …])

ML estimation of the random effects spatial lag model with all results and diagnostics [Elh03].

spreg.Panel_RE_Error(y, x, w[, epsilon, vm, …])

ML estimation of the random effects spatial error model with all results and diagnostics [Elh03].

Spatial Panel Models

Spatial panel models allow for evaluating correlation in both spatial and time dimensions.

spreg.GM_KKP(y, x, w[, full_weights, …])

GMM method for a spatial random effects panel model based on Kapoor, Kelejian and Prucha (2007) [KKP07]. Parameters ———- y : array n*tx1 or nxt array for dependent variable x : array Two dimensional array with n*t rows and k columns for independent (exogenous) variable or n rows and k*t columns (note, must not include a constant term) w : spatial weights object Spatial weights matrix, nxn full_weights: boolean Considers different weights for each of the 6 moment conditions if True or only 2 sets of weights for the first 3 and the last 3 moment conditions if False (default) regimes : list List of n values with the mapping of each observation to a regime. Assumed to be aligned with ‘y’. vm : boolean If True, include variance-covariance matrix in summary results name_y : string or list of strings Name of dependent variable for use in output name_x : list of strings Names of independent variables for use in output name_w : string Name of weights matrix for use in output name_ds : string Name of dataset for use in output name_regimes : string Name of regime variable for use in the output.

Diagnostics

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

spreg.f_stat(reg)

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

spreg.t_stat(reg[, z_stat])

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

spreg.r2(reg)

Calculates the R^2 value for the regression.

spreg.ar2(reg)

Calculates the adjusted R^2 value for the regression.

spreg.se_betas(reg)

Calculates the standard error of the regression coefficients.

spreg.log_likelihood(reg)

Calculates the log-likelihood value for the regression.

spreg.akaike(reg)

Calculates the Akaike Information Criterion.

spreg.schwarz(reg)

Calculates the Schwarz Information Criterion.

spreg.condition_index(reg)

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

spreg.jarque_bera(reg)

Jarque-Bera test for normality in the residuals.

spreg.breusch_pagan(reg[, z])

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

spreg.white(reg)

Calculates the White test to check for heteroscedasticity.

spreg.koenker_bassett(reg[, z])

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

spreg.vif(reg)

Calculates the variance inflation factor for each independent variable.

spreg.likratiotest(reg0, reg1)

Likelihood ratio test statistic [Gre03]

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

Lagrange Multiplier tests.

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

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

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

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

spreg.sur_setp(bigB, varb)

Utility to compute standard error, t and p-value

spreg.sur_lrtest(n, n_eq, ldetS0, ldetS1)

Likelihood Ratio test on off-diagonal elements of Sigma

spreg.sur_lmtest(n, n_eq, sig)

Lagrange Multiplier test on off-diagonal elements of Sigma

spreg.lam_setp(lam, vm)

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

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

Lagrange Multiplier test on error spatial autocorrelation in SUR

spreg.surLMlag(n_eq, WS, bigy, bigX, bigE, …)

Lagrange Multiplier test on lag spatial autocorrelation in SUR

spreg.constant_check(array)

Checks to see numpy array includes a constant.