Skip to content

Commit

Permalink
TST: Remove yield tests from vector ar testing
Browse files Browse the repository at this point in the history
Remove pending deprecation tests from vector ar tests

xref statsmodels#4000
  • Loading branch information
bashtage committed Oct 31, 2017
1 parent bf593d6 commit a86ad43
Show file tree
Hide file tree
Showing 2 changed files with 285 additions and 454 deletions.
145 changes: 55 additions & 90 deletions statsmodels/tsa/vector_ar/tests/test_var_jmulti.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,25 +162,21 @@ def test_ols_coefs():
err_msg = build_err_msg(ds, dt_s, "PARAMETER MATRICES ENDOG")
obtained = np.hstack(results_sm[ds][dt_s].coefs)
desired = results_ref[ds][dt_s]["est"]["Lagged endogenous term"]
yield assert_allclose, obtained, desired, rtol, atol, False, \
err_msg
assert_allclose(obtained, desired, rtol, atol, False, err_msg)
if debug_mode and dont_test_se_t_p:
continue
# standard errors
obt = results_sm[ds][dt_s].stderr_endog_lagged
des = results_ref[ds][dt_s]["se"]["Lagged endogenous term"].T
yield assert_allclose, obt, des, rtol, atol, False, \
"STANDARD ERRORS\n"+err_msg
assert_allclose(obt, des, rtol, atol, False, "STANDARD ERRORS\n" + err_msg)
# t-values
obt = results_sm[ds][dt_s].tvalues_endog_lagged
des = results_ref[ds][dt_s]["t"]["Lagged endogenous term"].T
yield assert_allclose, obt, des, rtol, atol, False, \
"t-VALUES\n"+err_msg
assert_allclose(obt, des, rtol, atol, False, "t-VALUES\n" + err_msg)
# p-values
obt = results_sm[ds][dt_s].pvalues_endog_lagged
des = results_ref[ds][dt_s]["p"]["Lagged endogenous term"].T
yield assert_allclose, obt, des, rtol, atol, False, \
"p-VALUES\n"+err_msg
assert_allclose(obt, des, rtol, atol, False, "p-VALUES\n" + err_msg)


def test_ols_det_terms():
Expand All @@ -197,42 +193,36 @@ def test_ols_det_terms():
det_key_ref = "Deterministic term"
# If there are no det. terms, just make sure we don't compute any:
if det_key_ref not in results_ref[ds][dt_s]["est"].keys():
yield assert_, \
(results_sm[ds][dt_s].coefs_exog.size == 0 and
results_sm[ds][dt_s].stderr_dt.size == 0 and
results_sm[ds][dt_s].tvalues_dt.size == 0 and
results_sm[ds][dt_s].pvalues_dt.size == 0), \
err_msg
assert_((results_sm[ds][dt_s].coefs_exog.size == 0 and
results_sm[ds][dt_s].stderr_dt.size == 0 and
results_sm[ds][dt_s].tvalues_dt.size == 0 and
results_sm[ds][dt_s].pvalues_dt.size == 0), err_msg)
continue
obtained = results_sm[ds][dt_s].coefs_exog
desired = results_ref[ds][dt_s]["est"][det_key_ref]
desired = reorder_jmultis_det_terms(
desired, dt_s[0].startswith("c"), dt_s[1])
yield assert_allclose, obtained, desired, rtol, atol, False, \
err_msg
assert_allclose(obtained, desired, rtol, atol, False, err_msg)
if debug_mode and dont_test_se_t_p:
continue
# standard errors
obt = results_sm[ds][dt_s].stderr_dt
des = results_ref[ds][dt_s]["se"][det_key_ref]
des = reorder_jmultis_det_terms(des, dt_s[0].startswith("c"),
dt_s[1]).T
yield assert_allclose, obt, des, rtol, atol, False, \
"STANDARD ERRORS\n"+err_msg
assert_allclose(obt, des, rtol, atol, False, "STANDARD ERRORS\n" + err_msg)
# t-values
obt = results_sm[ds][dt_s].tvalues_dt
des = results_ref[ds][dt_s]["t"][det_key_ref]
des = reorder_jmultis_det_terms(des, dt_s[0].startswith("c"),
dt_s[1]).T
yield assert_allclose, obt, des, rtol, atol, False, \
"t-VALUES\n"+err_msg
assert_allclose(obt, des, rtol, atol, False, "t-VALUES\n" + err_msg)
# p-values
obt = results_sm[ds][dt_s].pvalues_dt
des = results_ref[ds][dt_s]["p"][det_key_ref]
des = reorder_jmultis_det_terms(des, dt_s[0].startswith("c"),
dt_s[1]).T
yield assert_allclose, obt, des, rtol, atol, False, \
"p-VALUES\n"+err_msg
assert_allclose(obt, des, rtol, atol, False, "p-VALUES\n" + err_msg)


def test_ols_sigma():
Expand All @@ -248,8 +238,7 @@ def test_ols_sigma():
err_msg = build_err_msg(ds, dt, "Sigma_u")
obtained = results_sm[ds][dt].sigma_u
desired = results_ref[ds][dt]["est"]["Sigma_u"]
yield assert_allclose, obtained, desired, rtol, atol, False, \
err_msg
assert_allclose(obtained, desired, rtol, atol, False, err_msg)


def test_log_like():
Expand All @@ -266,8 +255,7 @@ def test_log_like():
err_msg = build_err_msg(ds, dt, "Log Likelihood")
obtained = results_sm[ds][dt].llf
desired = results_ref[ds][dt]["log_like"]
yield assert_allclose, obtained, desired, rtol, atol, False, \
err_msg
assert_allclose(obtained, desired, rtol, atol, False, err_msg)


def test_fc():
Expand Down Expand Up @@ -297,8 +285,7 @@ def test_fc():
obtained = results_sm[ds][dt].forecast(
y=last_observations, steps=steps, exog_future=exog_future)
desired = results_ref[ds][dt]["fc"]["fc"]
yield assert_allclose, obtained, desired, rtol, atol, False, \
err_msg
assert_allclose(obtained, desired, rtol, atol, False, err_msg)

# test forecast method with confidence interval calculation
err_msg = build_err_msg(ds, dt, "FORECAST WITH INTERVALS")
Expand All @@ -311,12 +298,9 @@ def test_fc():
des = results_ref[ds][dt]["fc"]["fc"]
des_l = results_ref[ds][dt]["fc"]["lower"]
des_u = results_ref[ds][dt]["fc"]["upper"]
yield assert_allclose, obt, des, rtol, atol, False, \
err_msg
yield assert_allclose, obt_l, des_l, rtol, atol, False, \
err_msg
yield assert_allclose, obt_u, des_u, rtol, atol, False, \
err_msg
assert_allclose(obt, des, rtol, atol, False, err_msg)
assert_allclose(obt_l, des_l, rtol, atol, False, err_msg)
assert_allclose(obt_u, des_u, rtol, atol, False, err_msg)


def test_causality(): # test Granger- and instantaneous causality
Expand Down Expand Up @@ -353,13 +337,12 @@ def test_causality(): # test Granger- and instantaneous causality
g_t_obt = granger_sm_ind.test_statistic
g_t_des = results_ref[ds][dt]["granger_caus"][
"test_stat"][(causing_key, caused_key)]
yield assert_allclose, g_t_obt, g_t_des, rtol, atol, \
False, err_msg_g_t
assert_allclose(g_t_obt, g_t_des, rtol, atol, False, err_msg_g_t)
# check whether string sequences as args work in the same way:
g_t_obt_str = granger_sm_str.test_statistic
yield assert_allclose, g_t_obt_str, g_t_obt, 1e-07, 0, False, \
err_msg_g_t + " - sequences of integers and ".upper() + \
"strings as arguments don't yield the same result!".upper()
assert_allclose(g_t_obt_str, g_t_obt, 1e-07, 0, False,
err_msg_g_t + " - sequences of integers and ".upper() +
"strings as arguments don't yield the same result!".upper())
# check if int (e.g. 0) as index and list of int ([0]) yield
# the same result:
if len(causing_ind) == 1 or len(caused_ind) == 1:
Expand All @@ -368,30 +351,27 @@ def test_causality(): # test Granger- and instantaneous causality
granger_sm_single_ind = results_sm[ds][
dt].test_causality(ce, ci)
g_t_obt_single = granger_sm_single_ind.test_statistic
yield assert_allclose, g_t_obt_single, g_t_obt, 1e-07, 0, \
False, \
err_msg_g_t + " - list of int and int as ".upper() + \
"argument don't yield the same result!".upper()
assert_allclose(g_t_obt_single, g_t_obt, 1e-07, 0, False,
err_msg_g_t + " - list of int and int as ".upper() +
"argument don't yield the same result!".upper())

# test p-value for Granger non-causality:
g_p_obt = granger_sm_ind.pvalue
g_p_des = results_ref[ds][dt]["granger_caus"]["p"][(
causing_key, caused_key)]
yield assert_allclose, g_p_obt, g_p_des, rtol, atol, \
False, err_msg_g_p
assert_allclose(g_p_obt, g_p_des, rtol, atol, False, err_msg_g_p)
# check whether string sequences as args work in the same way:
g_p_obt_str = granger_sm_str.pvalue
yield assert_allclose, g_p_obt_str, g_p_obt, 1e-07, 0, False, \
err_msg_g_t + " - sequences of integers and ".upper() + \
"strings as arguments don't yield the same result!".upper()
assert_allclose(g_p_obt_str, g_p_obt, 1e-07, 0, False,
err_msg_g_t + " - sequences of integers and ".upper() +
"strings as arguments don't yield the same result!".upper())
# check if int (e.g. 0) as index and list of int ([0]) yield
# the same result:
if len(causing_ind) == 1:
g_p_obt_single = granger_sm_single_ind.pvalue
yield assert_allclose, g_p_obt_single, g_p_obt, 1e-07, 0, \
False, \
assert_allclose(g_p_obt_single, g_p_obt, 1e-07, 0, False,
err_msg_g_t + " - list of int and int as ".upper() + \
"argument don't yield the same result!".upper()
"argument don't yield the same result!".upper())

# test instantaneous causality ################################
inst_sm_ind = results_sm[ds][dt].test_inst_causality(
Expand All @@ -402,46 +382,42 @@ def test_causality(): # test Granger- and instantaneous causality
t_obt = inst_sm_ind.test_statistic
t_des = results_ref[ds][dt]["inst_caus"][
"test_stat"][(causing_key, caused_key)]
yield assert_allclose, t_obt, t_des, rtol, atol, False, \
err_msg_i_t
assert_allclose(t_obt, t_des, rtol, atol, False, err_msg_i_t)
# check whether string sequences as args work in the same way:
t_obt_str = inst_sm_str.test_statistic
yield assert_allclose, t_obt_str, t_obt, 1e-07, 0, False, \
err_msg_i_t + " - sequences of integers and ".upper() + \
"strings as arguments don't yield the same result!".upper()
assert_allclose(t_obt_str, t_obt, 1e-07, 0, False,
err_msg_i_t + " - sequences of integers and ".upper() +
"strings as arguments don't yield the same result!".upper())
# check if int (e.g. 0) as index and list of int ([0]) yield
# the same result:
if len(causing_ind) == 1:
inst_sm_single_ind = results_sm[ds][
dt].test_inst_causality(causing_ind[0])
t_obt_single = inst_sm_single_ind.test_statistic
yield assert_allclose, t_obt_single, t_obt, 1e-07, 0, \
False, \
err_msg_i_t + " - list of int and int as ".upper() + \
"argument don't yield the same result!".upper()
assert_allclose(t_obt_single, t_obt, 1e-07, 0, False,
err_msg_i_t + " - list of int and int as ".upper() +
"argument don't yield the same result!".upper())

# test p-value for instantaneous non-causality
p_obt = results_sm[ds][dt].test_inst_causality(
causing_ind).pvalue
p_des = results_ref[ds][dt]["inst_caus"]["p"][(
causing_key, caused_key)]
yield assert_allclose, p_obt, p_des, rtol, atol, False, \
err_msg_i_p
assert_allclose(p_obt, p_des, rtol, atol, False, err_msg_i_p)
# check whether string sequences as args work in the same way:
p_obt_str = inst_sm_str.pvalue
yield assert_allclose, p_obt_str, p_obt, 1e-07, 0, False, \
err_msg_i_p + " - sequences of integers and ".upper() + \
"strings as arguments don't yield the same result!".upper()
assert_allclose(p_obt_str, p_obt, 1e-07, 0, False,
err_msg_i_p + " - sequences of integers and ".upper() +
"strings as arguments don't yield the same result!".upper())
# check if int (e.g. 0) as index and list of int ([0]) yield
# the same result:
if len(causing_ind) == 1:
inst_sm_single_ind = results_sm[ds][
dt].test_inst_causality(causing_ind[0])
p_obt_single = inst_sm_single_ind.pvalue
yield assert_allclose, p_obt_single, p_obt, 1e-07, 0, \
False, \
err_msg_i_p + " - list of int and int as ".upper() + \
"argument don't yield the same result!".upper()
assert_allclose(p_obt_single, p_obt, 1e-07, 0, False,
err_msg_i_p + " - list of int and int as ".upper() +
"argument don't yield the same result!".upper())


def test_impulse_response():
Expand All @@ -460,8 +436,7 @@ def test_impulse_response():
# flatten inner arrays to make them comparable to parsed results:
obtained_all = obtained_all.reshape(periods+1, -1)
desired_all = results_ref[ds][dt]["ir"]
yield assert_allclose, obtained_all, desired_all, rtol, atol, \
False, err_msg
assert_allclose(obtained_all, desired_all, rtol, atol, False, err_msg)


def test_lag_order_selection():
Expand All @@ -483,8 +458,7 @@ def test_lag_order_selection():
"LAG ORDER SELECTION - " + ic.upper())
obtained = getattr(obtained_all, ic)
desired = results_ref[ds][dt]["lagorder"][ic]
yield assert_allclose, obtained, desired, rtol, atol, False, \
err_msg
assert_allclose(obtained, desired, rtol, atol, False, err_msg)


def test_normality():
Expand All @@ -503,13 +477,11 @@ def test_normality():
obt_statistic = obtained.test_statistic
des_statistic = results_ref[ds][dt]["test_norm"][
"joint_test_statistic"]
yield assert_allclose, obt_statistic, des_statistic, rtol, atol, \
False, err_msg
assert_allclose(obt_statistic, des_statistic, rtol, atol, False, err_msg)
err_msg = build_err_msg(ds, dt, "TEST NON-NORMALITY - P-VALUE")
obt_pvalue = obtained.pvalue
des_pvalue = results_ref[ds][dt]["test_norm"]["joint_pvalue"]
yield assert_allclose, obt_pvalue, des_pvalue, rtol, atol, \
False, err_msg
assert_allclose(obt_pvalue, des_pvalue, rtol, atol, False, err_msg)
# call methods to assure they don't raise exceptions
obtained.summary()
str(obtained) # __str__()
Expand All @@ -532,29 +504,25 @@ def test_whiteness():
err_msg = build_err_msg(ds, dt, "WHITENESS OF RESIDUALS - "
"TEST STATISTIC")
desired = results_ref[ds][dt]["whiteness"]["test statistic"]
yield assert_allclose, obtained.test_statistic, desired, \
rtol, atol, False, err_msg
assert_allclose(obtained.test_statistic, desired, rtol, atol, False, err_msg)
# p-value
err_msg = build_err_msg(ds, dt, "WHITENESS OF RESIDUALS - "
"P-VALUE")
desired = results_ref[ds][dt]["whiteness"]["p-value"]
yield assert_allclose, obtained.pvalue, desired, \
rtol, atol, False, err_msg
assert_allclose(obtained.pvalue, desired, rtol, atol, False, err_msg)

obtained = results_sm[ds][dt].test_whiteness_new(nlags=lags,
adjusted=True)
# test statistic (adjusted Portmanteau test)
err_msg = build_err_msg(ds, dt, "WHITENESS OF RESIDUALS - "
"TEST STATISTIC (ADJUSTED TEST)")
desired = results_ref[ds][dt]["whiteness"]["test statistic adj."]
yield assert_allclose, obtained.test_statistic, desired, \
rtol, atol, False, err_msg
assert_allclose(obtained.test_statistic, desired, rtol, atol, False, err_msg)
# p-value (adjusted Portmanteau test)
err_msg = build_err_msg(ds, dt, "WHITENESS OF RESIDUALS - "
"P-VALUE (ADJUSTED TEST)")
desired = results_ref[ds][dt]["whiteness"]["p-value adjusted"]
yield assert_allclose, obtained.pvalue, desired, \
rtol, atol, False, err_msg
assert_allclose(obtained.pvalue, desired, rtol, atol, False, err_msg)


def test_exceptions():
Expand All @@ -570,9 +538,6 @@ def test_exceptions():

# instant causality:
### 0<signif<1
yield assert_raises, ValueError,\
results_sm[ds][dt].test_inst_causality, \
0, 0 # this means signif=0
assert_raises(ValueError, results_sm[ds][dt].test_inst_causality, 0, 0) # this means signif=0
### causing must be int, str or iterable of int or str
yield assert_raises, TypeError,\
results_sm[ds][dt].test_inst_causality, [0.5] # 0.5 not an int
assert_raises(TypeError, results_sm[ds][dt].test_inst_causality, [0.5]) # 0.5 not an int

0 comments on commit a86ad43

Please sign in to comment.