or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

diagnostics.mdindex.mdml-models.mdols-models.mdpanel-models.mdprobit-models.mdregime-models.mdspatial-error-models.mdsur-models.mdtsls-models.mdutilities.md

ml-models.mddocs/

0

# Maximum Likelihood Models

1

2

Full information maximum likelihood estimation for spatial lag and error models with analytical derivatives and concentrated log-likelihood functions.

3

4

## Capabilities

5

6

### Spatial Error ML Models

7

8

```python { .api }

9

class ML_Error:

10

def __init__(self, y, x, w, epsilon=0.0000001, hard_bound=False, vm=False,

11

name_y=None, name_x=None, name_w=None, name_ds=None, latex=False):

12

"""

13

Maximum likelihood spatial error model.

14

15

Parameters:

16

- y (array): nx1 dependent variable

17

- x (array): nxk independent variables

18

- w (sparse matrix): Spatial weights matrix

19

- epsilon (float): Convergence criterion

20

- hard_bound (bool): Constrain lambda to [-1,1]

21

- vm (bool): Include variance-covariance matrix

22

"""

23

24

class ML_Error_Regimes:

25

def __init__(self, y, x, regimes, w, constant_regi='many', cols2regi='all',

26

regime_err_sep=False, cores=False, epsilon=0.0000001,

27

hard_bound=False, vm=False, name_y=None, name_x=None,

28

name_regimes=None, name_w=None, name_ds=None, latex=False):

29

"""ML spatial error model with regimes."""

30

```

31

32

### Spatial Lag ML Models

33

34

```python { .api }

35

class ML_Lag:

36

def __init__(self, y, x, w, epsilon=0.0000001, hard_bound=False, vm=False,

37

name_y=None, name_x=None, name_w=None, name_ds=None, latex=False):

38

"""

39

Maximum likelihood spatial lag model.

40

41

Parameters:

42

- y (array): nx1 dependent variable

43

- x (array): nxk independent variables

44

- w (sparse matrix): Spatial weights matrix

45

- epsilon (float): Convergence criterion

46

- hard_bound (bool): Constrain rho to [-1,1]

47

- vm (bool): Include variance-covariance matrix

48

"""

49

50

class ML_Lag_Regimes:

51

def __init__(self, y, x, regimes, w, constant_regi='many', cols2regi='all',

52

regime_lag_sep=False, cores=False, epsilon=0.0000001,

53

hard_bound=False, vm=False, name_y=None, name_x=None,

54

name_regimes=None, name_w=None, name_ds=None, latex=False):

55

"""ML spatial lag model with regimes."""

56

```

57

58

## Usage Examples

59

60

### Basic ML Spatial Error

61

62

```python

63

import numpy as np

64

import spreg

65

from libpysal import weights

66

67

# Data setup

68

n = 49

69

x = np.random.randn(n, 2)

70

y = np.random.randn(n, 1)

71

w = weights.lat2W(7, 7)

72

73

# ML spatial error estimation

74

ml_error = spreg.ML_Error(y, x, w.sparse, name_y='y', name_x=['x1', 'x2'])

75

print(ml_error.summary)

76

```

77

78

### ML Spatial Lag Model

79

80

```python

81

# ML spatial lag estimation

82

ml_lag = spreg.ML_Lag(y, x, w.sparse, name_y='y', name_x=['x1', 'x2'])

83

print(ml_lag.summary)

84

print(f"Spatial lag parameter (rho): {ml_lag.rho}")

85

```