Spatial Regression (spreg)
Description:
- spreg, short for “spatial regression”, is a Python package to estimate simultaneous autoregressive spatial regression models. This is part of the refactoring of PySal.
Resources:
- [GitHub] https://github.com/pysal/spreg?tab=readme-ov-file
- [References] https://github.com/pysal/spreg/blob/main/docs/api.rst
- [Examples] https://github.com/pysal/spreg/tree/main/notebooks
- [Modern Spatial Econometrics in Practice: A Guide to GeoDa, GeoDaSpace and PySAL] https://sergerey.org/giasp16/pdfs/anselin_rey_weights.pdf
Example 1
Section titled “Example 1”Basic Spatial 2SLS
import numpyimport libpysalimport spreg
libpysal.examples.explain("baltim")
# Read Baltimore datadb = libpysal.io.open(libpysal.examples.get_path("baltim.dbf"), "r")ds_name = "baltim.dbf"
# Read dependent variabley_name = "PRICE"y = numpy.array(db.by_col(y_name)).Ty = y[:, numpy.newaxis]
# Read exogenous variablesx_names = ["NROOM", "NBATH", "PATIO", "FIREPL", "AC", "GAR", "AGE", "LOTSZ", "SQFT"]x = numpy.array([db.by_col(var) for var in x_names]).T
# Read spatial dataww = libpysal.io.open(libpysal.examples.get_path("baltim_q.gal"))w = ww.read()ww.close()w_name = "baltim_q.gal"w.transform = "r"
model = spreg.GM_Lag( y, x, w=w, name_y=y_name, name_x=x_names, name_w="baltim_q", name_ds="baltim")print(model.summary)ganymede is made by Eugo