API reference

Classic Models

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

Ordinary least squares with results and diagnostics.

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

Two stage least squares with results and diagnostics.

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.GM_Lag(y, x[, yend, q, w, w_lags, ...])

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

spreg.ML_Lag(y, x, w[, slx_lags, slx_vars, ...])

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

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

Wrapper function to call any of the GMM methods for a spatial error model available in spreg

spreg.ML_Error(y, x, w[, slx_lags, ...])

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

spreg.GM_Error(y, x, w[, slx_lags, ...])

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[, slx_lags, ...])

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[, slx_lags, ...])

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[, ...])

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.NSLX(y, x, coords[, params, ...])

Estimation of the nonlinear SLX model - inverse distance power function and negative exponential distance function supported Includes output of all results.

Discrete Choice Models

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

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.TSLS_Regimes(y, x, yend, q, regimes[, ...])

Two stage least squares (2SLS) with regimes.

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].

spreg.OLS_Endog_Regimes(y, x, w[, ...])

Ordinary least squares with endogenous regimes.

spreg.GM_Lag_Endog_Regimes(y, x, w[, ...])

Spatial two stage least squares (S2SLS) with endogenous regimes.

spreg.Skater_reg([dissimilarity, affinity, ...])

Initialize the Skater_reg algorithm based on [AA24].

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[, df, w, regimes, ...])

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

spreg.SURerrorGM(bigy, bigX, w[, df, ...])

User class for SUR Error estimation by Generalized Moments

spreg.SURerrorML(bigy, bigX, w[, df, ...])

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

Spatial Panel Models

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

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].

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].

Diagnostics

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

spreg.f_stat(reg[, df])

Calculates the f-statistic and associated p-value for multiple coefficient constraints [Gre03].

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.dwh(reg)

Durbin-Wu-Hausman test on endogeneity of variables

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.

spreg.panel_LMlag(y, x, w)

Lagrange Multiplier test on lag spatial autocorrelation in panel data.

spreg.panel_LMerror(y, x, w)

Lagrange Multiplier test on error spatial autocorrelation in panel data.

spreg.panel_rLMlag(y, x, w)

Robust Lagrange Multiplier test on lag spatial autocorrelation in panel data.

spreg.panel_rLMerror(y, x, w)

Robust Lagrange Multiplier test on error spatial autocorrelation in panel data.

spreg.panel_Hausman(panel_fe, panel_re[, sp_lag])

Hausman test on panel data with spatial interactions.

DGP

Tools for simulating synthetic data according to data-generating processes implied by different spatial model specifications

spreg.dgp.make_error(rng, n[, mu, varu, method])

make_error: generate error term for a given distribution

spreg.dgp.make_x(rng, n[, mu, varu, cor, method])

make_x: generate a matrix of k columns of x for a given distribution

spreg.dgp.make_wx(x, w[, o])

make_wx: generate a matrix spatially lagged x given matrix x

spreg.dgp.make_xb(x, beta)

make_xb: generate a column xb as matrix x (constant added)

spreg.dgp.make_wxg(wx, gamma)

make_wxg: generate a column wxg as matrix wx (no constant)

spreg.dgp.dgp_errproc(u, w[, lam, model, ...])

dgp_errproc: generates pure spatial error process

spreg.dgp.dgp_ols(u, xb)

dgp_ols: generates y for non-spatial process with given xb and error term u

spreg.dgp.dgp_slx(u, xb, wxg[, ybin])

dgp_slx: generates y for SLX with given xb, wxg, and error term u

spreg.dgp.dgp_sperror(u, xb, w[, lam, ...])

dgp_sperror: generates y for spatial error model with given xb, weights,

spreg.dgp.dgp_slxerror(u, xb, wxg, w[, lam, ...])

dgp_slxerror: generates y for SLX spatial error model with xb, wxg, weights,

spreg.dgp.dgp_lag(u, xb, w[, rho, imethod, ybin])

dgp_lag: generates y for spatial lag model with xb, weights,

spreg.dgp.dgp_spdurbin(u, xb, wxg, w[, rho, ...])

dgp_spdurbin: generates y for spatial Durbin model with xb, wxg, weights,

spreg.dgp.dgp_lagerr(u, xb, w[, rho, lam, ...])

dgp_lagerr: generates y for spatial lag model with sar or ma errors

spreg.dgp.dgp_gns(u, xb, wxg, w[, rho, lam, ...])

dgp_gns: generates y for general nested model with sar or ma errors

spreg.dgp.dgp_mess(u, xb, w[, rho])

dgp_mess: generates y for MESS spatial lag model with xb, weights,

spreg.dgp.dgp_probit(u, xb)

dgp_probit: generates y for non-spatial probit process with given xb

spreg.dgp.make_bin(yy)

make_bin: generates y as 0-1 variable for y > mean of y,

spreg.dgp.make_heterror(u, v)

make_heterror: transforms constant variance error term into

spreg.dgp.make_vmult(n[, method, vlow, vup, rng])

make_vmult : helper function to create variance multiplier