Example #1
0
def ols(dependent, independent, w=None, gwk=None, regime=False, regimes=None):
    dependent1, independent1, spatial, robust, foo, bar = optionsDecider(
        dependent, independent, w, gwk)
    if regime == False:
        ols = pysal.spreg.ols.OLS(y=dependent1,
                                  x=independent1,
                                  w=w,
                                  spat_diag=spatial,
                                  moran=spatial,
                                  robust=robust,
                                  gwk=gwk)
    else:
        if regimes == None:
            regimes = Regionalization.generateRegimes(w, dependent,
                                                      independent)
        ols = pysal.spreg.ols_regimes.OLS_Regimes(y=dependent1,
                                                  x=independent1,
                                                  regimes=regimes,
                                                  w=w,
                                                  spat_diag=spatial,
                                                  moran=spatial,
                                                  robust=robust,
                                                  gwk=gwk)

    # print(ols.summary)
    return ols.betas, ols.r2
Example #2
0
def tsls(dependent,
         independent,
         endogeneous,
         instrument,
         w=None,
         gwk=None,
         regime=False,
         regimes=None):
    dependent1, independent1, spatial, robust, endogeneous1, instrument1 = optionsDecider(
        dependent, independent, w, gwk)
    if regime == False:
        tsls = pysal.spreg.TSLS(dependent1,
                                independent1,
                                endogeneous1,
                                instrument1,
                                w=w,
                                spat_diag=spatial,
                                robust=robust,
                                gwk=gwk)
    else:
        if regimes == None:
            regimes = Regionalization.generateRegimes(w, dependent,
                                                      independent, endogeneous,
                                                      instrument)
        tsls = pysal.spreg.TSLS_Regimes(dependent1,
                                        independent1,
                                        endogeneous1,
                                        instrument1,
                                        regimes=regimes,
                                        spat_diag=spatial,
                                        robust=robust,
                                        gwk=gwk)

    return tsls.betas, tsls.pr2
Example #3
0
def gmCombo(dependent,
            independent,
            w,
            endogeneous,
            instrument,
            regime=False,
            regimes=None):
    dependent1, independent1, foo1, foo2, endogeneous1, instrument1 = optionsDecider(
        dependent,
        independent,
        w,
        endogeneous=endogeneous,
        instrument=instrument)
    qlag = (endogeneous != None)
    if regime == False:
        reg = pysal.spreg.GM_Combo_Het(y=dependent1,
                                       x=independent1,
                                       w=w,
                                       yend=endogeneous1,
                                       q=instrument1,
                                       lag_q=qlag)
    else:
        if regimes == None:
            retimes = Regionalization.generateRegimes(w, dependent,
                                                      independent, endogeneous,
                                                      instrument)
        reg = pysal.spreg.GM_Combo_Het_Regimes(y=dependent1,
                                               x=independent1,
                                               w=w,
                                               yend=endogeneous1,
                                               q=instrument1,
                                               lag_q=qlag,
                                               regimes=regimes)

    return reg.betas, reg.pr2
Example #4
0
def gmErrorEnd(dependent,
               independent,
               w,
               endogeneous,
               instrument,
               regime=False,
               regimes=None):
    dependent1, independent1, foo1, foo2, endogeneous1, instrument1 = optionsDecider(
        dependent,
        independent,
        w,
        endogeneous=endogeneous,
        instrument=instrument)

    if regime == False:
        reg = pysal.spreg.GM_Endog_Error_Het(y=dependent1,
                                             x=independent1,
                                             yend=endogeneous1,
                                             q=instrument1)
    else:
        if regimes == None:
            regimes = Regionalization.generateRegimes(w, dependent,
                                                      independent, endogeneous,
                                                      instrument)
        reg = pysal.spreg.GM_Endog_Error_Het_Regimes(y=dependent1,
                                                     x=independent1,
                                                     yend=endogeneous1,
                                                     q=instrument1,
                                                     regimes=regimes)

    return reg.betas, reg.pr2
Example #5
0
def gm(dependent,
       independent,
       w,
       endogeneous=None,
       instrument=None,
       gwk=None,
       regime=False,
       regimes=None):
    dependent1, independent1, spatial, robust, endogeneous1, instrument1 = optionsDecider(
        dependent,
        independent,
        w,
        gwk=gwk,
        endogeneous=endogeneous,
        instrument=instrument)
    qlag = (endogeneous != None)
    if regime == False:
        reg = pysal.spreg.GM_Lag(dependent1,
                                 independent1,
                                 yend=endogeneous1,
                                 q=instrument1,
                                 lag_q=qlag,
                                 spat_diag=spatial,
                                 robust=robust,
                                 gwk=gwk)

    else:
        if regimes == None:
            regimes = Regionalization.generateRegimes(w, dependent,
                                                      independent, endogeneous,
                                                      instrument)
        reg = pysal.spreg.GM_Lag_Regimes(w=w,
                                         y=dependent1,
                                         x=independent1,
                                         yend=endogeneous1,
                                         q=instrument1,
                                         regimes=regimes,
                                         lag_q=qlag,
                                         spat_diag=spatial,
                                         robust=robust,
                                         gwk=gwk)

    return reg.betas, reg.pr2
Example #6
0
def gmError(dependent, independent, w, regime=False, regimes=None):
    dependent1, independent1, foo0, foo1, foo2, foo3 = optionsDecider(
        dependent, independent, w)

    if regime == False:
        reg = pysal.spreg.GM_Error_Het(
            y=dependent1,
            x=independent1,
            w=w,
        )
    else:
        if regimes == None:
            regimes = Regionalization.generateRegimes(w, dependent,
                                                      independent)
        reg = pysal.spreg.GM_Error_Het_Regimes(w=w,
                                               y=dependent1,
                                               x=independent1,
                                               regimes=regimes)

    return reg.betas, reg.pr2
Example #7
0
def ml(dependent, independent, w, regime=False, regimes=None):
    dependent1, independent1, spatial, foo1, foo2, foo3 = optionsDecider(
        dependent, independent, w)

    if regime == False:
        reg = pysal.spreg.ML_Lag(y=dependent1,
                                 x=independent1,
                                 w=w,
                                 method='ord',
                                 spat_diag=spatial)
    else:
        if regimes == None:
            regimes = Regionalization.generateRegimes(w, dependent,
                                                      independent)
        reg = pysal.spreg.ML_Lag_Regimes(y=dependent1,
                                         x=independent1,
                                         w=w,
                                         regimes=regimes,
                                         method='ord',
                                         spat_diag=spatial)

    return reg.betas, reg.pr2
Example #8
0
def rank(observations, w=None, regimes=None, method="tau"):
    originalObs = observations
    observations = observations.transpose()
    w = None
    a = None
    if regimes == None:  # generate regimes endogeneously.
        from GSA import Regionalization
        #TODO fix double transpose issue. fixed
        a = Regionalization.generateRegimes(w, originalObs)
        w = pysal.block_weights(a)
    else:  # regimes provided by user.
        w = pysal.block_weights(regimes)
    if method == "tau":
        result = [pysal.SpatialTau(observations[:, i], observations[:, i + 1], w, 100) for i in
                  range(0, len(w.id_order))]
        ret = [(r.tau_spatial, r.taus.mean(), r.tau_spatial_psim) for r in result]

    else:  # method == "theta"
        if regimes == None:
            result = pysal.Theta(regime=a, y=observations)
        else:
            result = pysal.Theta(regime=regimes, y=observations)
        ret = [(r.theta, r.pvalue_left, r.pvalue_right) for r in result]
    return ret