def test_acf_fft_dataframe(): # regression test #322 result = acf(sunspots.load_pandas().data[["SUNACTIVITY"]], fft=True, nlags=20) assert_equal(result.ndim, 1)
def test_acovf2d(): dta = sunspots.load_pandas().data dta.index = DatetimeIndex(start='1700', end='2009', freq='A')[:309] del dta["YEAR"] res = acovf(dta) assert_equal(res, acovf(dta.values)) X = np.random.random((10,2)) assert_raises(ValueError, acovf, X)
def test_acovf2d(): dta = sunspots.load_pandas().data dta.index = Index(dates_from_range('1700', '2008')) del dta["YEAR"] res = acovf(dta) assert_equal(res, acovf(dta.values)) X = np.random.random((10,2)) assert_raises(ValueError, acovf, X)
def test_acovf2d(): dta = sunspots.load_pandas().data dta.index = DatetimeIndex(start='1700', end='2009', freq='A') del dta["YEAR"] res = acovf(dta) assert_equal(res, acovf(dta.values)) X = np.random.random((10, 2)) assert_raises(ValueError, acovf, X)
def test_autoreg_score(): data = sunspots.load_pandas() ar = AutoReg(np.asarray(data.endog), 3) res = ar.fit() score = ar.score(res.params) assert isinstance(score, np.ndarray) assert score.shape == (4, ) assert ar.information(res.params).shape == (4, 4)
def test_acovf2d(): dta = sunspots.load_pandas().data dta.index = Index(dates_from_range('1700', '2008')) del dta["YEAR"] res = acovf(dta) assert_equal(res, acovf(dta.values)) X = np.random.random((10, 2)) assert_raises(ValueError, acovf, X)
def test_acovf2d(reset_randomstate): dta = sunspots.load_pandas().data dta.index = date_range(start='1700', end='2009', freq='A')[:309] del dta["YEAR"] res = acovf(dta, fft=False) assert_equal(res, acovf(dta.values, fft=False)) x = np.random.random((10, 2)) with pytest.raises(ValueError): acovf(x, fft=False)
def test_ljungbox_dof_adj(): data = sunspots.load_pandas().data['SUNACTIVITY'] res = AR(data).fit(maxlag=4) resid = res.resid res1 = smsdia.acorr_ljungbox(resid, lags=10) res2 = smsdia.acorr_ljungbox(resid, lags=10, model_df=res.k_ar) assert_allclose(res1[0], res2[0]) assert np.all(np.isnan(res2[1][:4])) assert np.all(res2[1][4:] <= res1[1][4:])
def test_ljungbox_dof_adj(): data = sunspots.load_pandas().data['SUNACTIVITY'] res = AutoReg(data, 4).fit() resid = res.resid res1 = smsdia.acorr_ljungbox(resid, lags=10, return_df=False) res2 = smsdia.acorr_ljungbox(resid, lags=10, model_df=4, return_df=False) assert_allclose(res1[0], res2[0]) assert np.all(np.isnan(res2[1][:4])) assert np.all(res2[1][4:] <= res1[1][4:])
def test_ljungbox_errors(): data = sunspots.load_pandas().data['SUNACTIVITY'] with pytest.raises(ValueError, match="model_df must"): smsdia.acorr_ljungbox(data, model_df=-1) with pytest.raises(ValueError, match="period must"): smsdia.acorr_ljungbox(data, model_df=-1, period=1) with pytest.raises(ValueError, match="period must"): smsdia.acorr_ljungbox(data, model_df=-1, period=-2) with pytest.warns(FutureWarning, match="The default value of lags"): smsdia.acorr_ljungbox(data, return_df=False)
def test_get_prediction(): # GH7309 df = sunspots.load_pandas().data df.index = np.arange(df.shape[0]) y = df.iloc[:, 0] stlf_model = STLForecast( y, model=ARIMA, model_kwargs={"order": (2, 2, 0)}, period=11 ) stlf_res = stlf_model.fit() pred = stlf_res.get_prediction() assert pred.predicted_mean.shape == (309,) assert pred.var_pred_mean.shape == (309,)
def test_pandas_nodates_index(): from statsmodels.datasets import sunspots y = sunspots.load_pandas().data.SUNACTIVITY npt.assert_raises(ValueError, TimeSeriesModel, y)
def test_autoreg_roots(): data = sunspots.load_pandas() ar = AutoReg(np.asarray(data.endog), lags=1) res = ar.fit() assert_almost_equal(res.roots, np.array([1.0 / res.params[-1]]))
def test_ljungbox_period(): data = sunspots.load_pandas().data['SUNACTIVITY'] ar_res = AutoReg(data, 4).fit() res = smsdia.acorr_ljungbox(ar_res.resid, period=13, return_df=True) res2 = smsdia.acorr_ljungbox(ar_res.resid, lags=26, return_df=True) assert_frame_equal(res, res2)
def test_acf_fft_dataframe(): # regression test #322 result = acf(sunspots.load_pandas().data[['SUNACTIVITY']], fft=True) assert_equal(result.ndim, 1)