Skip to content

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:

Basic Spatial 2SLS

import numpy
import libpysal
import spreg
libpysal.examples.explain("baltim")
# Read Baltimore data
db = libpysal.io.open(libpysal.examples.get_path("baltim.dbf"), "r")
ds_name = "baltim.dbf"
# Read dependent variable
y_name = "PRICE"
y = numpy.array(db.by_col(y_name)).T
y = y[:, numpy.newaxis]
# Read exogenous variables
x_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 data
ww = 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