Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

branch "panel" for gsoc 2020 #39

Merged
merged 16 commits into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sudo: true
branches:
only:
- master
- panel

python:
- 3.6
Expand Down
8 changes: 8 additions & 0 deletions doc/_static/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,14 @@ @article{Kelejian1999
Volume = {40},
Year = {1999}}

@article{KKP2007,
Author = {Kapoor, M and Kelejian, H H and Prucha, I R},
Journal = {Journal of Econometrics},
Pages = {97--130},
Title = {Panel data models with spatially correlated error components},
Volume = {140},
Year = {2007}}

@book{Greene2003,
Author = {Greene, William H},
Publisher = {Pearson Education India},
Expand Down
12 changes: 11 additions & 1 deletion doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Regimes models are variants of spatial regression models which allow for structu
Seemingly-Unrelated Regressions
--------------------------------

Seeimingly-unrelated regression models are a generalization of linear regression. These models (and their spatial generalizations) allow for correlation in the residual terms between groups that use the same model. In spatial Seeimingly-Unrelated Regressions, the error terms across groups are allowed to exhibit a structured type of correlation: spatail correlation.
Seemingly-unrelated regression models are a generalization of linear regression. These models (and their spatial generalizations) allow for correlation in the residual terms between groups that use the same model. In spatial Seeimingly-Unrelated Regressions, the error terms across groups are allowed to exhibit a structured type of correlation: spatial correlation.

.. autosummary::
:toctree: generated/
Expand All @@ -74,6 +74,16 @@ Seeimingly-unrelated regression models are a generalization of linear regression
spreg.SURlagIV
spreg.ThreeSLS

Spatial Panel Models
--------------------

Spatial panel models allow for evaluating correlation in both spatial and time dimensions.

.. autosummary::
:toctree: generated/

spreg.GM_KKP

Diagnostics
-----------

Expand Down
3 changes: 2 additions & 1 deletion spreg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
from .sur_utils import *
from .utils import *
from .regimes import *
from .sputils import *
from .sputils import *
from .sp_panels import *
6 changes: 3 additions & 3 deletions spreg/error_sp.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def __init__(self, y, x, w,
name_w=None, name_ds=None):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
x_constant = USER.check_constant(x)
BaseGM_Error.__init__(self, y=y, x=x_constant, w=w.sparse)
Expand Down Expand Up @@ -609,7 +609,7 @@ def __init__(self, y, x, yend, q, w,
name_w=None, name_ds=None):

n = USER.check_arrays(y, x, yend, q)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
x_constant = USER.check_constant(x)
BaseGM_Endog_Error.__init__(
Expand Down Expand Up @@ -995,7 +995,7 @@ def __init__(self, y, x, yend=None, q=None,
name_w=None, name_ds=None):

n = USER.check_arrays(y, x, yend, q)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
yend2, q2 = set_endog(y, x, w, yend, q, w_lags, lag_q)
x_constant = USER.check_constant(x)
Expand Down
10 changes: 7 additions & 3 deletions spreg/error_sp_het.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ class GM_Error_Het(BaseGM_Error_Het):
[ 0.7105 0.3681]
[-0.5588 0.1616]
[ 0.4118 0.168 ]]

Alternatively, we can have a summary of the output by typing:
print(reg.summary)

"""

def __init__(self, y, x, w,
Expand All @@ -334,7 +338,7 @@ def __init__(self, y, x, w,
name_w=None, name_ds=None):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
x_constant = USER.check_constant(x)
BaseGM_Error_Het.__init__(
Expand Down Expand Up @@ -747,7 +751,7 @@ def __init__(self, y, x, yend, q, w,
name_w=None, name_ds=None):

n = USER.check_arrays(y, x, yend, q)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
x_constant = USER.check_constant(x)
BaseGM_Endog_Error_Het.__init__(self, y=y, x=x_constant, yend=yend,
Expand Down Expand Up @@ -1172,7 +1176,7 @@ def __init__(self, y, x, yend=None, q=None,
name_w=None, name_ds=None):

n = USER.check_arrays(y, x, yend, q)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
yend2, q2 = set_endog(y, x, w, yend, q, w_lags, lag_q)
x_constant = USER.check_constant(x)
Expand Down
6 changes: 3 additions & 3 deletions spreg/error_sp_het_regimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def __init__(self, y, x, regimes, w, max_iter=1, epsilon=0.00001, step1c=False,
name_ds=None, name_regimes=None):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
self.constant_regi = constant_regi
self.cols2regi = cols2regi
Expand Down Expand Up @@ -773,7 +773,7 @@ def __init__(self, y, x, yend, q, regimes, w,
name_regimes=None, summ=True, add_lag=False):

n = USER.check_arrays(y, x, yend, q)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
self.constant_regi = constant_regi
self.cols2regi = cols2regi
Expand Down Expand Up @@ -1346,7 +1346,7 @@ def __init__(self, y, x, regimes, yend=None, q=None,

n = USER.check_arrays(y, x)
self.step1c = step1c
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
name_x = USER.set_name_x(name_x, x, constant=True)
self.name_y = USER.set_name_y(name_y)
Expand Down
6 changes: 3 additions & 3 deletions spreg/error_sp_hom.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def __init__(self, y, x, w,
name_w=None, name_ds=None):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
x_constant = USER.check_constant(x)
BaseGM_Error_Hom.__init__(self, y=y, x=x_constant, w=w.sparse, A1=A1,
Expand Down Expand Up @@ -749,7 +749,7 @@ def __init__(self, y, x, yend, q, w,
name_w=None, name_ds=None):

n = USER.check_arrays(y, x, yend, q)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
x_constant = USER.check_constant(x)
BaseGM_Endog_Error_Hom.__init__(
Expand Down Expand Up @@ -1172,7 +1172,7 @@ def __init__(self, y, x, yend=None, q=None,
name_w=None, name_ds=None):

n = USER.check_arrays(y, x, yend, q)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
yend2, q2 = set_endog(y, x, w, yend, q, w_lags, lag_q)
x_constant = USER.check_constant(x)
Expand Down
6 changes: 3 additions & 3 deletions spreg/error_sp_hom_regimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def __init__(self, y, x, regimes, w,
name_w=None, name_ds=None, name_regimes=None):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
self.constant_regi = constant_regi
self.cols2regi = cols2regi
Expand Down Expand Up @@ -791,7 +791,7 @@ def __init__(self, y, x, yend, q, regimes, w,
name_ds=None, name_regimes=None, summ=True, add_lag=False):

n = USER.check_arrays(y, x, yend, q)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
self.constant_regi = constant_regi
self.cols2regi = cols2regi
Expand Down Expand Up @@ -1363,7 +1363,7 @@ def __init__(self, y, x, regimes, yend=None, q=None,
name_w=None, name_ds=None, name_regimes=None):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
name_x = USER.set_name_x(name_x, x, constant=True)
self.name_y = USER.set_name_y(name_y)
Expand Down
6 changes: 3 additions & 3 deletions spreg/error_sp_regimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def __init__(self, y, x, regimes, w,
cores=False, name_ds=None, name_regimes=None):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
self.constant_regi = constant_regi
self.cols2regi = cols2regi
Expand Down Expand Up @@ -705,7 +705,7 @@ def __init__(self, y, x, yend, q, regimes, w, cores=False,
name_ds=None, name_regimes=None, summ=True, add_lag=False):

n = USER.check_arrays(y, x, yend, q)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
self.constant_regi = constant_regi
self.cols2regi = cols2regi
Expand Down Expand Up @@ -1223,7 +1223,7 @@ def __init__(self, y, x, regimes, yend=None, q=None,
name_w=None, name_ds=None, name_regimes=None):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
name_x = USER.set_name_x(name_x, x, constant=True)
self.name_y = USER.set_name_y(name_y)
Expand Down
2 changes: 1 addition & 1 deletion spreg/ml_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def __init__(self, y, x, w, method='full', epsilon=0.0000001,
spat_diag=False, vm=False, name_y=None, name_x=None,
name_w=None, name_ds=None):
n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
x_constant = USER.check_constant(x)
method = method.upper()
Expand Down
2 changes: 1 addition & 1 deletion spreg/ml_error_regimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def __init__(self, y, x, regimes, w=None, constant_regi='many',
name_w=None, name_ds=None, name_regimes=None):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
self.constant_regi = constant_regi
self.cols2regi = cols2regi
Expand Down
2 changes: 1 addition & 1 deletion spreg/ml_lag.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def __init__(self, y, x, w, method='full', epsilon=0.0000001,
spat_diag=False, vm=False, name_y=None, name_x=None,
name_w=None, name_ds=None):
n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
x_constant = USER.check_constant(x)
method = method.upper()
Expand Down
2 changes: 1 addition & 1 deletion spreg/ml_lag_regimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def __init__(self, y, x, regimes, w=None, constant_regi='many',
name_w=None, name_ds=None, name_regimes=None):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y, w_required=True)
USER.check_spat_diag(spat_diag, w)
name_y = USER.set_name_y(name_y)
Expand Down
2 changes: 1 addition & 1 deletion spreg/ols.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def __init__(self, y, x,
name_w=None, name_gwk=None, name_ds=None):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y)
USER.check_robust(robust, gwk)
USER.check_spat_diag(spat_diag, w)
Expand Down
2 changes: 1 addition & 1 deletion spreg/ols_regimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def __init__(self, y, x, regimes,
name_w=None, name_gwk=None, name_ds=None):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
USER.check_weights(w, y)
USER.check_robust(robust, gwk)
USER.check_spat_diag(spat_diag, w)
Expand Down
2 changes: 1 addition & 1 deletion spreg/probit.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ def __init__(
spat_diag=False):

n = USER.check_arrays(y, x)
USER.check_y(y, n)
y = USER.check_y(y, n)
if w != None:
USER.check_weights(w, y)
spat_diag = True
Expand Down
4 changes: 2 additions & 2 deletions spreg/regimes.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def __init__(self, reg):
def _chow_run(kr, kf, kryd, nr, betas, vm):
if betas.shape[0] != vm.shape[0]:
if kf > 0:
betas = betas[0:vm.shape[0], :]
kf = kf - 1
kf = kf - (betas.shape[0] - vm.shape[0])
betas = betas[0:vm.shape[0], :]
else:
brange = []
for i in range(nr):
Expand Down
Loading