0
# Regime Models
1
2
Spatial regression models allowing parameters to vary across regimes, with options for separate or joint estimation and extensive regime-specific diagnostics.
3
4
## Capabilities
5
6
### Spatial Error Regime Models
7
8
```python { .api }
9
class GM_Error_Het_Regimes:
10
def __init__(self, y, x, regimes, w, constant_regi='many', cols2regi='all',
11
regime_err_sep=False, regime_lag_sep=False, cores=False,
12
max_iter=1, epsilon=0.0000001, step1c=False,
13
inv_method='power_exp', hard_bound=False, vm=False,
14
name_y=None, name_x=None, name_regimes=None, name_w=None,
15
name_ds=None, latex=False):
16
"""
17
GMM spatial error model with regimes and heteroskedasticity.
18
19
Parameters:
20
- y (array): nx1 dependent variable
21
- x (array): nxk independent variables
22
- regimes (list/Series): Regime identifier for each observation
23
- w (sparse matrix): Spatial weights matrix
24
- constant_regi (str): 'one' (same constant) or 'many' (different per regime)
25
- cols2regi (str/list): Variables that vary by regime ('all' or list)
26
- regime_err_sep (bool): Separate error variance by regime
27
- regime_lag_sep (bool): Separate spatial parameter by regime
28
- cores (bool): Use multiprocessing for regime estimation
29
30
Attributes:
31
- regimes_set (set): Unique regime values
32
- kr (int): Number of regimized variables
33
- nr (int): Number of regimes
34
- multi (dict): Individual regime results (if regime_err_sep=True)
35
- chow (dict): Chow test for regime differences
36
"""
37
38
class GM_Error_Hom_Regimes:
39
def __init__(self, y, x, regimes, w, constant_regi='many', cols2regi='all',
40
regime_err_sep=False, regime_lag_sep=False, cores=False,
41
hard_bound=False, vm=False, name_y=None, name_x=None,
42
name_regimes=None, name_w=None, name_ds=None, latex=False):
43
"""GMM spatial error model with regimes assuming homoskedasticity."""
44
```
45
46
## Usage Examples
47
48
### Basic Regime Model
49
50
```python
51
import numpy as np
52
import spreg
53
from libpysal import weights
54
55
# Data with regimes
56
n = 150
57
x = np.random.randn(n, 2)
58
y = np.random.randn(n, 1)
59
regimes = np.random.choice(['North', 'South', 'East'], n)
60
w = weights.KNN.from_array(np.random.randn(n, 2), k=5)
61
62
# Spatial error model with regimes
63
regime_model = spreg.GM_Error_Het_Regimes(y, x, regimes, w.sparse,
64
constant_regi='many', cols2regi='all',
65
name_y='y', name_x=['x1', 'x2'],
66
name_regimes='region')
67
68
print(regime_model.summary)
69
print(f"Number of regimes: {regime_model.nr}")
70
print("Chow test for regime differences:", regime_model.chow)
71
```