def test_predict_missing(self): ex = self.data[:5].copy() ex.iloc[0, 1] = np.nan predicted1 = self.res.predict(ex) predicted2 = self.res.predict(ex[1:]) assert_index_equal(predicted1.index, ex.index) assert_series_equal(predicted1[1:], predicted2) assert_equal(predicted1.values[0], np.nan)
def test_innovations_filter_pandas(reset_randomstate): ma = np.array([-0.9, 0.5]) acovf = np.array([1 + (ma**2).sum(), ma[0] + ma[1] * ma[0], ma[1]]) theta, _ = innovations_algo(acovf, nobs=10) endog = np.random.randn(10) endog_pd = pd.Series(endog, index=pd.date_range('2000-01-01', periods=10)) resid = innovations_filter(endog, theta) resid_pd = innovations_filter(endog_pd, theta) assert_allclose(resid, resid_pd.values) assert_index_equal(endog_pd.index, resid_pd.index)
def test_var_cov_params_pandas(bivariate_var_data): df = pd.DataFrame(bivariate_var_data, columns=['x', 'y']) mod = VAR(df) res = mod.fit(2) cov = res.cov_params() assert isinstance(cov, pd.DataFrame) exog_names = ('const', 'L1.x', 'L1.y', 'L2.x', 'L2.y') index = pd.MultiIndex.from_product((exog_names, ('x', 'y'))) assert_index_equal(cov.index, cov.columns) assert_index_equal(cov.index, index)
def test_innovations_filter_pandas(reset_randomstate): ma = np.array([-0.9, 0.5]) acovf = np.array([1 + (ma ** 2).sum(), ma[0] + ma[1] * ma[0], ma[1]]) theta, _ = innovations_algo(acovf, nobs=10) endog = np.random.randn(10) endog_pd = pd.Series(endog, index=pd.date_range('2000-01-01', periods=10)) resid = innovations_filter(endog, theta) resid_pd = innovations_filter(endog_pd, theta) assert_allclose(resid, resid_pd.values) assert_index_equal(endog_pd.index, resid_pd.index)