Пример #1
0
def _get_irf_plot_config(names, impcol, rescol):
    nrows = ncols = k = len(names)
    if impcol is not None and rescol is not None:
        # plot one impulse-response pair
        nrows = ncols = 1
        j = util.get_index(names, impcol)
        i = util.get_index(names, rescol)
        to_plot = [(j, i, 0, 0)]
    elif impcol is not None:
        # plot impacts of impulse in one variable
        ncols = 1
        j = util.get_index(names, impcol)
        to_plot = [(j, i, i, 0) for i in range(k)]
    elif rescol is not None:
        # plot only things having impact on particular variable
        ncols = 1
        i = util.get_index(names, rescol)
        to_plot = [(j, i, j, 0) for j in range(k)]
    else:
        # plot everything
        to_plot = [(j, i, i, j) for i in range(k) for j in range(k)]

    return nrows, ncols, to_plot
Пример #2
0
def _get_irf_plot_config(names, impcol, rescol):
    nrows = ncols = k = len(names)
    if impcol is not None and rescol is not None:
        # plot one impulse-response pair
        nrows = ncols = 1
        j = util.get_index(names, impcol)
        i = util.get_index(names, rescol)
        to_plot = [(j, i, 0, 0)]
    elif impcol is not None:
        # plot impacts of impulse in one variable
        ncols = 1
        j = util.get_index(names, impcol)
        to_plot = [(j, i, i, 0) for i in range(k)]
    elif rescol is not None:
        # plot only things having impact on particular variable
        ncols = 1
        i = util.get_index(names, rescol)
        to_plot = [(j, i, j, 0) for j in range(k)]
    else:
        # plot everything
        to_plot = [(j, i, i, j) for i in range(k) for j in range(k)]

    return nrows, ncols, to_plot
Пример #3
0
 def get_eq_index(self, name):
     "Return integer position of requested equation name"
     return util.get_index(self.names, name)
Пример #4
0
def a_test_causality(self, caused, causing=None, kind='f', signif=0.05):
    if not (0 < signif < 1):
        raise ValueError("signif has to be between 0 and 1")

    allowed_types = (string_types, int)

    if isinstance(caused, allowed_types):
        caused = [caused]
    if not all(isinstance(c, allowed_types) for c in caused):
        raise TypeError("caused has to be of type string or int (or a "
                        "sequence of these types).")
    caused = [self.names[c] if type(c) == int else c for c in caused]
    caused_ind = [util.get_index(self.names, c) for c in caused]

    if causing is not None:

        if isinstance(causing, allowed_types):
            causing = [causing]
        if not all(isinstance(c, allowed_types) for c in causing):
            raise TypeError("causing has to be of type string or int (or "
                            "a sequence of these types) or None.")
        causing = [self.names[c] if type(c) == int else c for c in causing]
        causing_ind = [util.get_index(self.names, c) for c in causing]

    if causing is None:
        causing_ind = [i for i in range(self.neqs) if i not in caused_ind]
        causing = [self.names[c] for c in caused_ind]

    k, p = self.neqs, self.k_ar
    # number of restrictions
    num_restr = len(causing) * len(caused) * p
    num_det_terms = self.k_exog

    # Make restriction matrix
    C = np.zeros((num_restr, k * num_det_terms + k ** 2 * p), dtype=float)
    cols_det = k * num_det_terms
    row = 0
    for j in range(p):
        for ing_ind in causing_ind:
            for ed_ind in caused_ind:
                C[row, cols_det + ed_ind + k * ing_ind + k ** 2 * j] = 1
                row += 1

    # Lutkepohl 3.6.5
    Cb = np.dot(C, vec(self.params.T))
    middle = scipy.linalg.inv(chain_dot(C, self.cov_params, C.T))

    # wald statistic
    lam_wald = statistic = chain_dot(Cb, middle, Cb)

    if kind.lower() == 'wald':
        df = num_restr
        dist = stats.chi2(df)
    elif kind.lower() == 'f':
        statistic = lam_wald / num_restr
        df = (num_restr, k * self.df_resid)
        dist = stats.f(*df)
    else:
        raise Exception('kind %s not recognized' % kind)

    pvalue = dist.sf(statistic)
    crit_value = dist.ppf(1 - signif)

    #       print(pvalue)
    #       print("---====--")
    return pvalue, CausalityTestResults(causing, caused, statistic,
                                        crit_value, pvalue, df, signif,
                                        test="granger", method=kind)