예제 #1
0
 def test_init_hac_(self):
     X = []
     X.append(self.db.by_col("INC"))
     X.append(self.db.by_col("CRIME"))
     self.X = np.array(X).T
     yd2, q2 = pysal.spreg.utils.set_endog(self.y, self.X, self.w, None,
                                           None, 2, True)
     self.X = np.hstack((np.ones(self.y.shape), self.X))
     self.X = SP.csr_matrix(self.X)
     gwk = pysal.kernelW_from_shapefile(
         pysal.examples.get_path('columbus.shp'),
         k=15,
         function='triangular',
         fixed=False)
     base_gm_lag = BaseGM_Lag(self.y,
                              self.X,
                              yend=yd2,
                              q=q2,
                              w=self.w,
                              w_lags=2,
                              robust='hac',
                              gwk=gwk)
     tbetas = np.array([[4.53017056e+01], [6.20888617e-01],
                        [-4.80723451e-01], [2.83622122e-02]])
     np.testing.assert_allclose(base_gm_lag.betas, tbetas)
     dbetas = D.se_betas(base_gm_lag)
     se_betas = np.array([19.08513569, 0.51769543, 0.18244862, 0.35460553])
     np.testing.assert_allclose(dbetas, se_betas)
예제 #2
0
 def test_init_white_(self):
     X = []
     X.append(self.db.by_col("INC"))
     X.append(self.db.by_col("CRIME"))
     self.X = np.array(X).T
     base_gm_lag = GM_Lag(self.y, self.X, w=self.w, w_lags=2, robust='white')
     tbetas = np.array([[  4.53017056e+01], [  6.20888617e-01], [ -4.80723451e-01], [  2.83622122e-02]])
     np.testing.assert_array_almost_equal(base_gm_lag.betas, tbetas) 
     dbetas = D.se_betas(base_gm_lag)
     se_betas = np.array([ 20.47077481, 0.50613931, 0.20138425, 0.38028295 ])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
예제 #3
0
 def test_init_hac_(self):
     X = []
     X.append(self.db.by_col("INC"))
     X.append(self.db.by_col("CRIME"))
     self.X = np.array(X).T
     gwk = pysal.kernelW_from_shapefile(pysal.examples.get_path('columbus.shp'),k=15,function='triangular', fixed=False)        
     base_gm_lag = GM_Lag(self.y, self.X, w=self.w, w_lags=2, robust='hac', gwk=gwk)
     tbetas = np.array([[  4.53017056e+01], [  6.20888617e-01], [ -4.80723451e-01], [  2.83622122e-02]])
     np.testing.assert_array_almost_equal(base_gm_lag.betas, tbetas) 
     dbetas = D.se_betas(base_gm_lag)
     se_betas = np.array([ 19.08513569,   0.51769543,   0.18244862,   0.35460553])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
예제 #4
0
 def test_init_discbd(self):
     X = np.array(self.db.by_col("INC"))
     X = np.reshape(X, (49,1))
     yd = np.array(self.db.by_col("CRIME"))
     yd = np.reshape(yd, (49,1))
     q = np.array(self.db.by_col("DISCBD"))
     q = np.reshape(q, (49,1))
     reg = GM_Lag(self.y, X, w=self.w, yend=yd, q=q, w_lags=2)
     tbetas = np.array([[ 100.79359082], [  -0.50215501], [  -1.14881711], [  -0.38235022]])
     np.testing.assert_array_almost_equal(tbetas, reg.betas)
     dbetas = D.se_betas(reg)
     se_betas = np.array([ 53.0829123 ,   1.02511494,   0.57589064,   0.59891744 ])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
예제 #5
0
 def test_lag_q(self):
     X = np.array(self.db.by_col("INC"))
     X = np.reshape(X, (49,1))
     yd = np.array(self.db.by_col("CRIME"))
     yd = np.reshape(yd, (49,1))
     q = np.array(self.db.by_col("DISCBD"))
     q = np.reshape(q, (49,1))
     reg = GM_Lag(self.y, X, w=self.w, yend=yd, q=q, w_lags=2, lag_q=False)
     tbetas = np.array( [[ 108.83261383], [  -0.48041099], [  -1.18950006], [  -0.56140186]])
     np.testing.assert_array_almost_equal(tbetas, reg.betas)
     dbetas = D.se_betas(reg)
     se_betas = np.array([ 58.33203837,   1.09100446,   0.62315167,   0.68088777])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
 def test_init_white_(self):
     X = []
     X.append(self.db.by_col("INC"))
     X.append(self.db.by_col("CRIME"))
     self.X = np.array(X).T
     yd2, q2 = utils.set_endog(self.y, self.X, self.w, None, None, 2, True)
     self.X = np.hstack((np.ones(self.y.shape),self.X))
     self.X = SP.csr_matrix(self.X)
     base_gm_lag = BaseGM_Lag(self.y, self.X, yend=yd2, q=q2, w=self.w, w_lags=2, robust='white')
     tbetas = np.array([[  4.53017056e+01], [  6.20888617e-01], [ -4.80723451e-01], [  2.83622122e-02]])
     np.testing.assert_array_almost_equal(base_gm_lag.betas, tbetas) 
     dbetas = D.se_betas(base_gm_lag)
     se_betas = np.array([ 20.47077481, 0.50613931, 0.20138425, 0.38028295 ])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
예제 #7
0
 def test_init_white_(self):
     X = []
     X.append(self.db.by_col("INC"))
     X.append(self.db.by_col("CRIME"))
     self.X = np.array(X).T
     yd2, q2 = pysal.spreg.utils.set_endog(self.y, self.X, self.w, None, None, 2, True)
     self.X = np.hstack((np.ones(self.y.shape), self.X))
     self.X = SP.csr_matrix(self.X)
     base_gm_lag = BaseGM_Lag(self.y, self.X, yend=yd2, q=q2, w=self.w, w_lags=2, robust="white")
     tbetas = np.array([[4.53017056e01], [6.20888617e-01], [-4.80723451e-01], [2.83622122e-02]])
     np.testing.assert_array_almost_equal(base_gm_lag.betas, tbetas)
     dbetas = D.se_betas(base_gm_lag)
     se_betas = np.array([20.47077481, 0.50613931, 0.20138425, 0.38028295])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
예제 #8
0
 def test_init_hac_(self):
     w_lags = 2
     X = []
     X.append(self.db.by_col("INC"))
     X.append(self.db.by_col("CRIME"))
     self.X = np.array(X).T
     yd2, q2 = pysal.spreg.utils.set_endog(self.y, self.X, self.w, None, None, w_lags, True)
     self.X = np.hstack((np.ones(self.y.shape),self.X))
     gwk = pysal.kernelW_from_shapefile(pysal.examples.get_path('columbus.shp'),k=15,function='triangular', fixed=False)        
     base_gm_lag = BaseGM_Lag(self.y, self.X, yend=yd2, q=q2, w=self.w.sparse, w_lags=w_lags, robust='hac', gwk=gwk)
     tbetas = np.array([[  4.53017056e+01], [  6.20888617e-01], [ -4.80723451e-01], [  2.83622122e-02]])
     np.testing.assert_array_almost_equal(base_gm_lag.betas, tbetas) 
     dbetas = D.se_betas(base_gm_lag)
     se_betas = np.array([ 19.08513569,   0.51769543,   0.18244862,   0.35460553])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
 def test_init_discbd(self):
     X = np.array(self.db.by_col("INC"))
     self.X = np.reshape(X, (49,1))
     yd = np.array(self.db.by_col("CRIME"))
     yd = np.reshape(yd, (49,1))
     q = np.array(self.db.by_col("DISCBD"))
     q = np.reshape(q, (49,1))
     yd2, q2 = utils.set_endog(self.y, self.X, self.w, yd, q, 2, True)
     self.X = np.hstack((np.ones(self.y.shape),self.X))
     self.X = SP.csr_matrix(self.X)
     reg = BaseGM_Lag(self.y, self.X, yend=yd2, q=q2, w=self.w, w_lags=2)
     tbetas = np.array([[ 100.79359082], [  -0.50215501], [  -1.14881711], [  -0.38235022]])
     np.testing.assert_array_almost_equal(tbetas, reg.betas)
     dbetas = D.se_betas(reg)
     se_betas = np.array([ 53.0829123 ,   1.02511494,   0.57589064,   0.59891744 ])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
예제 #10
0
 def test_lag_q(self):
     X = np.array(self.db.by_col("INC"))
     self.X = np.reshape(X, (49,1))
     yd = np.array(self.db.by_col("CRIME"))
     yd = np.reshape(yd, (49,1))
     q = np.array(self.db.by_col("DISCBD"))
     q = np.reshape(q, (49,1))
     yd2, q2 = utils.set_endog(self.y, self.X, self.w, yd, q, 2, False)
     self.X = np.hstack((np.ones(self.y.shape),self.X))
     self.X = SP.csr_matrix(self.X)
     reg = BaseGM_Lag(self.y, self.X, yend=yd2, q=q2, w=self.w, w_lags=2, lag_q=False)
     tbetas = np.array( [[ 108.83261383], [  -0.48041099], [  -1.18950006], [  -0.56140186]])
     np.testing.assert_array_almost_equal(tbetas, reg.betas)
     dbetas = D.se_betas(reg)
     se_betas = np.array([ 58.33203837,   1.09100446,   0.62315167,   0.68088777])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
예제 #11
0
 def test_lag_q(self):
     X = np.array(self.db.by_col("INC"))
     self.X = np.reshape(X, (49, 1))
     yd = np.array(self.db.by_col("CRIME"))
     yd = np.reshape(yd, (49, 1))
     q = np.array(self.db.by_col("DISCBD"))
     q = np.reshape(q, (49, 1))
     yd2, q2 = pysal.spreg.utils.set_endog(self.y, self.X, self.w, yd, q, 2, False)
     self.X = np.hstack((np.ones(self.y.shape), self.X))
     self.X = SP.csr_matrix(self.X)
     reg = BaseGM_Lag(self.y, self.X, yend=yd2, q=q2, w=self.w, w_lags=2, lag_q=False)
     tbetas = np.array([[108.83261383], [-0.48041099], [-1.18950006], [-0.56140186]])
     np.testing.assert_array_almost_equal(tbetas, reg.betas)
     dbetas = D.se_betas(reg)
     se_betas = np.array([58.33203837, 1.09100446, 0.62315167, 0.68088777])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
예제 #12
0
 def test_init_discbd(self):
     X = np.array(self.db.by_col("INC"))
     self.X = np.reshape(X, (49, 1))
     yd = np.array(self.db.by_col("CRIME"))
     yd = np.reshape(yd, (49, 1))
     q = np.array(self.db.by_col("DISCBD"))
     q = np.reshape(q, (49, 1))
     yd2, q2 = pysal.spreg.utils.set_endog(self.y, self.X, self.w, yd, q, 2, True)
     self.X = np.hstack((np.ones(self.y.shape), self.X))
     self.X = SP.csr_matrix(self.X)
     reg = BaseGM_Lag(self.y, self.X, yend=yd2, q=q2, w=self.w, w_lags=2)
     tbetas = np.array([[100.79359082], [-0.50215501], [-1.14881711], [-0.38235022]])
     np.testing.assert_array_almost_equal(tbetas, reg.betas)
     dbetas = D.se_betas(reg)
     se_betas = np.array([53.0829123, 1.02511494, 0.57589064, 0.59891744])
     np.testing.assert_array_almost_equal(dbetas, se_betas)
예제 #13
0
def regimes_printout(model):
    stds = diagnostics.se_betas(model)
    tp = np.array(diagnostics.t_stat(model))
    res = pd.DataFrame({'Coefficient': pd.Series(model.betas.flatten()), \
            'Std. Error': pd.Series(stds) , \
            'T-Stat': pd.Series(tp[:, 0].flatten()), \
            'P-value': pd.Series(tp[:, 1].flatten())})
    res = res.reindex(columns = ['Coefficient', 'Std. Error', 'T-Stat', 'P-value'])
    inds = []
    for lbl in model.name_x:
        r, v = lbl.split('_-_')
        inds.append((r, v))
    inds = np.array(inds)
    res['Regime'] = inds[:, 0]
    res['Variable'] = inds[:, 1]
    res = res.set_index(['Regime', 'Variable'])
    res[''] = res['P-value'].apply(star_significance)
    return res
예제 #14
0
def regimes_printout(model):
    stds = diagnostics.se_betas(model)
    tp = np.array(diagnostics.t_stat(model))
    res = pd.DataFrame({'Coefficient': pd.Series(model.betas.flatten()), \
            'Std. Error': pd.Series(stds) , \
            'T-Stat': pd.Series(tp[:, 0].flatten()), \
            'P-value': pd.Series(tp[:, 1].flatten())})
    res = res.reindex(
        columns=['Coefficient', 'Std. Error', 'T-Stat', 'P-value'])
    inds = []
    for lbl in model.name_x:
        r, v = lbl.split('_-_')
        inds.append((r, v))
    inds = np.array(inds)
    res['Regime'] = inds[:, 0]
    res['Variable'] = inds[:, 1]
    res = res.set_index(['Regime', 'Variable'])
    res[''] = res['P-value'].apply(star_significance)
    return res
예제 #15
0
 def test_se_betas(self):
     obs = diagnostics.se_betas(reg)
     exp = np.array([4.73548613, 0.33413076, 0.10319868])
     np.testing.assert_allclose(obs, exp, RTOL)
예제 #16
0
 def test_se_betas(self):
     obs = diagnostics.se_betas(reg)
     exp = np.array([4.73548613, 0.33413076, 0.10319868])
     np.testing.assert_array_almost_equal(obs, exp)
예제 #17
0
 def test_se_betas(self):
     obs = diagnostics.se_betas(reg)
     exp = np.array([4.73548613, 0.33413076, 0.10319868])
     np.testing.assert_allclose(obs,exp, RTOL)
예제 #18
0
 def test_se_betas(self):
     obs = diagnostics.se_betas(reg)
     exp = np.array([4.73548613, 0.33413076, 0.10319868])
     np.testing.assert_array_almost_equal(obs,exp)