Пример #1
0
    def __init__(self, y, x, regimes,
                 w=None, robust=None, gwk=None, sig2n_k=True,
                 nonspat_diag=True, spat_diag=False, moran=False, white_test=False,
                 vm=False, constant_regi='many', cols2regi='all',
                 regime_err_sep=True, cores=None,
                 name_y=None, name_x=None, name_regimes=None,
                 name_w=None, name_gwk=None, name_ds=None):

        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        self.name_x_r = USER.set_name_x(name_x, x)
        self.constant_regi = constant_regi
        self.cols2regi = cols2regi
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_y = USER.set_name_y(name_y)
        self.name_regimes = USER.set_name_ds(name_regimes)
        self.n = n
        cols2regi = REGI.check_cols2regi(
            constant_regi, cols2regi, x, add_cons=False)
        self.regimes_set = REGI._get_regimes_set(regimes)
        self.regimes = regimes
        USER.check_regimes(self.regimes_set, self.n, x.shape[1])
        if regime_err_sep == True and robust == 'hac':
            set_warn(
                self, "Error by regimes is incompatible with HAC estimation. Hence, error by regimes has been disabled for this model.")
            regime_err_sep = False
        self.regime_err_sep = regime_err_sep
        if regime_err_sep == True and set(cols2regi) == set([True]) and constant_regi == 'many':
            self.y = y
            name_x = USER.set_name_x(name_x, x)
            regi_ids = dict((r, list(np.where(np.array(regimes) == r)[0]))
                            for r in self.regimes_set)
            self._ols_regimes_multi(x, w, regi_ids, cores,
                                    gwk, sig2n_k, robust, nonspat_diag, spat_diag, vm, name_x, moran, white_test)
        else:
            name_x = USER.set_name_x(name_x, x, constant=True)
            x, self.name_x = REGI.Regimes_Frame.__init__(self, x,
                                                         regimes, constant_regi, cols2regi, name_x)
            BaseOLS.__init__(self, y=y, x=x, robust=robust,
                             gwk=gwk, sig2n_k=sig2n_k)
            if regime_err_sep == True and robust == None:
                y2, x2 = REGI._get_weighted_var(
                    regimes, self.regimes_set, sig2n_k, self.u, y, x)
                ols2 = BaseOLS(y=y2, x=x2, sig2n_k=sig2n_k)
                RegressionProps_basic(self, betas=ols2.betas, vm=ols2.vm)
                self.title = "ORDINARY LEAST SQUARES - REGIMES (Group-wise heteroskedasticity)"
                nonspat_diag = None
                set_warn(
                    self, "Residuals treated as homoskedastic for the purpose of diagnostics.")
            else:
                self.title = "ORDINARY LEAST SQUARES - REGIMES"
            self.robust = USER.set_robust(robust)
            self.chow = REGI.Chow(self)
            SUMMARY.OLS(reg=self, vm=vm, w=w, nonspat_diag=nonspat_diag,
                        spat_diag=spat_diag, moran=moran, white_test=white_test, regimes=True)
Пример #2
0
    def __init__(self, y, x, regimes,
                 w=None, robust=None, gwk=None, sig2n_k=True,
                 nonspat_diag=True, spat_diag=False, moran=False, white_test=False,
                 vm=False, constant_regi='many', cols2regi='all',
                 regime_err_sep=True, cores=False,
                 name_y=None, name_x=None, name_regimes=None,
                 name_w=None, name_gwk=None, name_ds=None):

        n = USER.check_arrays(y, x)
        USER.check_y(y, n)
        USER.check_weights(w, y)
        USER.check_robust(robust, gwk)
        USER.check_spat_diag(spat_diag, w)
        self.name_x_r = USER.set_name_x(name_x, x)
        self.constant_regi = constant_regi
        self.cols2regi = cols2regi
        self.name_w = USER.set_name_w(name_w, w)
        self.name_gwk = USER.set_name_w(name_gwk, gwk)
        self.name_ds = USER.set_name_ds(name_ds)
        self.name_y = USER.set_name_y(name_y)
        self.name_regimes = USER.set_name_ds(name_regimes)
        self.n = n
        cols2regi = REGI.check_cols2regi(
            constant_regi, cols2regi, x, add_cons=False)
        self.regimes_set = REGI._get_regimes_set(regimes)
        self.regimes = regimes
        USER.check_regimes(self.regimes_set, self.n, x.shape[1])
        if regime_err_sep == True and robust == 'hac':
            set_warn(
                self, "Error by regimes is incompatible with HAC estimation. Hence, error by regimes has been disabled for this model.")
            regime_err_sep = False
        self.regime_err_sep = regime_err_sep
        if regime_err_sep == True and set(cols2regi) == set([True]) and constant_regi == 'many':
            self.y = y
            name_x = USER.set_name_x(name_x, x)
            regi_ids = dict(
                (r, list(np.where(np.array(regimes) == r)[0])) for r in self.regimes_set)
            self._ols_regimes_multi(x, w, regi_ids, cores,
                                    gwk, sig2n_k, robust, nonspat_diag, spat_diag, vm, name_x, moran, white_test)
        else:
            name_x = USER.set_name_x(name_x, x, constant=True)
            x, self.name_x = REGI.Regimes_Frame.__init__(self, x,
                                                         regimes, constant_regi, cols2regi, name_x)
            BaseOLS.__init__(
                self, y=y, x=x, robust=robust, gwk=gwk, sig2n_k=sig2n_k)
            if regime_err_sep == True and robust == None:
                y2, x2 = REGI._get_weighted_var(
                    regimes, self.regimes_set, sig2n_k, self.u, y, x)
                ols2 = BaseOLS(y=y2, x=x2, sig2n_k=sig2n_k)
                RegressionProps_basic(self, betas=ols2.betas, vm=ols2.vm)
                self.title = "ORDINARY LEAST SQUARES - REGIMES (Group-wise heteroskedasticity)"
                nonspat_diag = None
                set_warn(
                    self, "Residuals treated as homoskedastic for the purpose of diagnostics.")
            else:
                self.title = "ORDINARY LEAST SQUARES - REGIMES"
            self.robust = USER.set_robust(robust)
            self.chow = REGI.Chow(self)
            SUMMARY.OLS(reg=self, vm=vm, w=w, nonspat_diag=nonspat_diag,
                        spat_diag=spat_diag, moran=moran, white_test=white_test, regimes=True)
Пример #3
0
 def __init__(self, y, x, regimes,\
              w=None, robust=None, gwk=None, sig2n_k=True,\
              nonspat_diag=True, spat_diag=False, moran=False,\
              vm=False, constant_regi='many', cols2regi='all',\
              regime_err_sep=False, cores=None,\
              name_y=None, name_x=None, name_regimes=None,\
              name_w=None, name_gwk=None, name_ds=None):         
     
     n = USER.check_arrays(y, x)
     USER.check_y(y, n)
     USER.check_weights(w, y)
     USER.check_robust(robust, gwk)
     USER.check_spat_diag(spat_diag, w)
     self.name_x_r = USER.set_name_x(name_x, x)
     self.constant_regi = constant_regi
     self.cols2regi = cols2regi        
     self.name_w = USER.set_name_w(name_w, w)
     self.name_gwk = USER.set_name_w(name_gwk, gwk)
     self.name_ds = USER.set_name_ds(name_ds)
     self.name_y = USER.set_name_y(name_y)
     self.name_regimes = USER.set_name_ds(name_regimes)
     self.n = n        
     if regime_err_sep == True:
         name_x = USER.set_name_x(name_x, x)
         self.y = y
         if cols2regi == 'all':
             cols2regi = [True] * (x.shape[1])
         self.regimes_set = list(set(regimes))
         self.regimes_set.sort()
         if w:
             w_i,regi_ids,warn = REGI.w_regimes(w, regimes, self.regimes_set, transform=True, get_ids=True, min_n=len(self.cols2regi)+1)
             set_warn(self,warn)
         else:
             regi_ids = dict((r, list(np.where(np.array(regimes) == r)[0])) for r in self.regimes_set)
             w_i = None
         if set(cols2regi) == set([True]):
             self._ols_regimes_multi(x, w_i, regi_ids, cores,\
              gwk, sig2n_k, robust, nonspat_diag, spat_diag, vm, name_x, moran)
         else:
             raise Exception, "All coefficients must vary accross regimes if regime_err_sep = True."
     else:
         name_x = USER.set_name_x(name_x, x,constant=True)
         x, self.name_x = REGI.Regimes_Frame.__init__(self, x,\
                 regimes, constant_regi, cols2regi, name_x)
         BaseOLS.__init__(self, y=y, x=x, robust=robust, gwk=gwk, \
                 sig2n_k=sig2n_k)
         self.title = "ORDINARY LEAST SQUARES - REGIMES"
         self.robust = USER.set_robust(robust)
         self.chow = REGI.Chow(self)
         SUMMARY.OLS(reg=self, vm=vm, w=w, nonspat_diag=nonspat_diag,\
                     spat_diag=spat_diag, moran=moran, regimes=True)
Пример #4
0
def _run_stp1(y,x,eq_ids,r):
    y_r = y[eq_ids[r]]
    x_r = x[eq_ids[r]]     
    x_constant = USER.check_constant(x_r)
    model = BaseOLS(y_r, x_constant)
    #model.logll = diagnostics.log_likelihood(model) 
    return model            
Пример #5
0
def _work(y,x,regi_ids,r,robust,sig2n_k,name_ds,name_y,name_x,name_w,name_regimes):
    y_r = y[regi_ids[r]]
    x_r = x[regi_ids[r]]
    x_constant = USER.check_constant(x_r)
    if robust == 'hac':
        robust = None
    model = BaseOLS(y_r, x_constant, robust=robust, sig2n_k=sig2n_k)
    model.title = "ORDINARY LEAST SQUARES ESTIMATION - REGIME %s" %r
    model.robust = USER.set_robust(robust)
    model.name_ds = name_ds
    model.name_y = '%s_%s'%(str(r), name_y)
    model.name_x = ['%s_%s'%(str(r), i) for i in name_x]
    model.name_w = name_w
    model.name_regimes = name_regimes
    return model
Пример #6
0
def _work(y,x,regi_ids,r,robust,sig2n_k,name_ds,name_y,name_x,name_w,name_regimes):
    y_r = y[regi_ids[r]]
    x_r = x[regi_ids[r]]
    x_constant = USER.check_constant(x_r)
    if robust == 'hac':
        robust = None
    model = BaseOLS(y_r, x_constant, robust=robust, sig2n_k=sig2n_k)
    model.title = "ORDINARY LEAST SQUARES ESTIMATION - REGIME %s" %r
    model.robust = USER.set_robust(robust)
    model.name_ds = name_ds
    model.name_y = '%s_%s'%(str(r), name_y)
    model.name_x = ['%s_%s'%(str(r), i) for i in name_x]
    model.name_w = name_w
    model.name_regimes = name_regimes
    return model
Пример #7
0
def _run_stp1(y, x, yend, q, eq_ids, r, sig2n_k, w, w_lags, lag_q):
    y_r = y[eq_ids[r]]
    x_r = x[eq_ids[r]]
    yend_r = None
    if yend != None:
        yend_r = yend[eq_ids[r]]
        q_r = q[eq_ids[r]]
    if w_lags:
        yend_r, q_r = set_endog_sparse(y_r, x_r, w, yend_r, q_r, w_lags, lag_q)
    x_constant = USER.check_constant(x_r)
    if yend != None:
        model = BaseTSLS(y_r, x_constant, yend_r, q_r, sig2n_k=sig2n_k)
        model.zhat = np.dot(model.h, np.dot(model.hthi, model.htz))
    else:
        model = BaseOLS(y_r, x_constant, sig2n_k=sig2n_k)
        model.zhat = model.x
        model.z = model.x
    return model