Skip to content

Commit

Permalink
Connect UI with SUR GeoDaCenter#4
Browse files Browse the repository at this point in the history
add SUR_endog
  • Loading branch information
lixun910 committed Oct 18, 2018
1 parent 32eac75 commit 46257a1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
22 changes: 13 additions & 9 deletions econometrics/gs_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,23 +876,20 @@ def get_OLS(gui):
return output

def get_SUR(gui):
reg = SUR(gui.y, gui.x, name_bigy=gui.name_y, name_bigX=gui.name_x,
nonspat_diag=gui.ols_diag, spat_diag=False,
name_ds=gui.name_ds)
if gui.predy_resid: # write out predicted values and residuals
gui.pred_res, gui.header_pr, counter = collect_predy_resid(
gui.pred_res, gui.header_pr, reg, 'standard_',
False, 0, 0)
if gui.w_list and gui.spat_diag:
output = []
for w in gui.w_list:
reg = SUR(gui.y, gui.x, w=w, name_bigy=gui.name_y, name_bigX=gui.name_x,
spat_diag=gui.spat_diag, iter=True, name_ds=gui.name_ds)

# add spatial diagnostics for each W
reg_spat = COPY.copy(reg)
reg_spat.name_w = w.name
#SUMMARY.spat_diag_ols(reg=reg_spat, w=w, moran=gui.moran)
#SUMMARY.summary(reg=reg_spat, vm=gui.vc_matrix, instruments=False, nonspat_diag=gui.ols_diag, spat_diag=True)
#output.append(reg_spat)
output.append(reg_spat)
else:
reg = SUR(gui.y, gui.x, name_bigy=gui.name_y, name_bigX=gui.name_x, name_ds=gui.name_ds)
output = [reg]
#robust_regs = get_white_hac_standard(reg, gui)
#for rob_reg in robust_regs:
Expand All @@ -902,6 +899,13 @@ def get_SUR(gui):
#output.extend(robust_regs)
return output

def get_SUR_endog(gui):
reg = ThreeSLS(gui.y, gui.x, gui.ye, gui.h,
name_bigy=gui.name_y, name_bigX=gui.name_x,
name_bigyend=gui.name_ye, name_bigq=gui.name_h, name_ds=gui.name_ds)
output = [reg]
return output


def get_TSLS(gui):
reg = TSLS(y=gui.y, x=gui.x, yend=gui.ye, q=gui.h,
Expand Down Expand Up @@ -1712,7 +1716,7 @@ def get_error_msg(gui):
# SUR: only gmm -- 2TLS 3TLS
# model_getter[(model_type, endog, inf_lambda, regimes, time, method)] = model
model_getter[('Standard', False, '*', False, True, 'gm')] = get_SUR
#model_getter[('Standard', True, '*', False, True, 'gm')] = get_SUR_endog
model_getter[('Standard', True, '*', False, True, 'gm')] = get_SUR_endog
#model_getter[('Standard', False, '*', True, True, 'gm')] = get_SUR_regimes
#model_getter[('Standard', True, '*', True, True, 'gm')] = get_SUR_endog_regimes

Expand Down
4 changes: 4 additions & 0 deletions econometrics/tests/test_sur.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def test_SUR_iter(self): #2 equations, same K in each, iterated estimation, spat
reg = SUR(bigy0,bigX0,w=self.w,nonspat_diag=True,spat_diag=True,iter=True,verbose=False,\
name_bigy=bigyvars0,name_bigX=bigXvars0)

print reg
dict_compare(reg.bOLS,{0: np.array([[ 5.39719146],[ 0.6973813 ],\
[ 0.22566378]]), 1: np.array([[ 1.80829725],[ 1.03504143],[ 0.6582483 ]])},RTOL)
dict_compare(reg.bSUR,{0: np.array([[ 5.18423225],[ 0.67757925],\
Expand Down Expand Up @@ -112,6 +113,9 @@ def test_3SLS(self): # two equations, one endog, one instrument, same k
bigq1,bigqvars1 = sur_dictZ(self.db,q_var1)
reg = ThreeSLS(bigy1,bigX1,bigyend1,bigq1)

print 'test_3SLS'
print reg.summary

dict_compare(reg.b3SLS,{0: np.array([[ 6.92426353e+00],[ 1.42921826e+00],[ 4.94348442e-04],\
[ 3.58292750e+00]]), 1: np.array([[ 7.62385875],[ 1.65031181],[-0.21682974],[ 3.91250428]])},RTOL)
dict_compare(reg.tsls_inf,{0: np.array([[ 2.32208525e-001, 2.98191616e+001, 2.20522747e-195],\
Expand Down
18 changes: 13 additions & 5 deletions geodaspace/regression/M_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import pysal
import numpy as np
from econometrics.gs_dispatcher import Spmodel
from econometrics.sur_utils import sur_dictxy
from econometrics.sur import SUR
from econometrics.sur_utils import sur_dictxy, sur_dictZ
from geodaspace.preferences.model import preferencesModel
from geodaspace.weights.model import GeoDaSpace_W_Obj

Expand Down Expand Up @@ -411,12 +410,21 @@ def run(self, path=None, predy_resid=None):
y_var0 = name_y.split(',')
x_var0 = [ x_name.split(',') for x_name in x_names]
y, x, name_y, x_names = sur_dictxy(db, y_var0, x_var0)

yend_var1 = [ name.split(',') for name in ye_names]
ye, ye_names = sur_dictZ(db,yend_var1)

q_var1 = [ name.split(',') for name in h_names]
h, h_names = sur_dictZ(db,q_var1)

elif len(name_s)>0 and len(name_t) > 0:
y, x, name_y, x_names = sur_dictxy(db, [name_y], [x_names], space_id=[name_s], time_id=[name_t])

#reg0 = SUR(bigy0,bigX0,name_bigy=bigyvars0,name_bigX=bigXvars0)
#print reg0.summary

yend_var1 = [ name.split(',') for name in ye_names]
ye, ye_names = sur_dictZ(db,yend_var1)

q_var1 = [ name.split(',') for name in h_names]
h, h_names = sur_dictZ(db,q_var1)

config = data['config']

Expand Down

0 comments on commit 46257a1

Please sign in to comment.