> Every page of the ganymede website is listed in https://eugo.io/docs/ganymede/llms.txt.

# Spatial Regression (spreg)

> Spatial Regression (spreg): spreg, short for “spatial regression”, is a Python package to estimate simultaneous autoregressive spatial regression models.

Web page: https://eugo.io/docs/ganymede/demo_notebooks/geospatial/pysal/spreg/
Notebook: https://eugo.io/docs/ganymede/demo_notebooks/geospatial/pysal/spreg/spreg.ipynb (source: https://github.com/eugo-inc/ganymede/blob/main/demo_notebooks/geospatial/pysal/spreg.ipynb)

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

Basic Spatial 2SLS

```python
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)
```
