statsmodels.tsa.ar_model.AutoRegResults.apply

AutoRegResults.apply(endog, exog=None, refit=False, fit_kwargs=None)[source]

Apply the fitted parameters to new data unrelated to the original data

Creates a new result object using the current fitted parameters, applied to a completely new dataset that is assumed to be unrelated to the model’s original data. The new results can then be used for analysis or forecasting.

Parameters:
endogarray_like

New observations from the modeled time-series process.

exogarray_like, optional

New observations of exogenous regressors, if applicable.

refitbool, optional

Whether to re-fit the parameters, using the new dataset. Default is False (so parameters from the current results object are used to create the new results object).

fit_kwargsdict, optional

Keyword arguments to pass to fit (if refit=True).

Returns:
AutoRegResults

Updated results object containing results for the new dataset.

Notes

The endog argument to this method should consist of new observations that are not necessarily related to the original model’s endog dataset.

Care is needed when using deterministic processes with cyclical components such as seasonal dummies or Fourier series. These deterministic components will align to the first observation in the data and so it is essential that any new data have the same initial period.

Examples

>>> import pandas as pd
>>> from statsmodels.tsa.ar_model import AutoReg
>>> index = pd.period_range(start='2000', periods=3, freq='Y')
>>> original_observations = pd.Series([1.2, 1.5, 1.8], index=index)
>>> mod = AutoReg(original_observations, lags=1, trend="n")
>>> res = mod.fit()
>>> print(res.params)
y.L1    1.219512
dtype: float64
>>> print(res.fittedvalues)
2001    1.463415
2002    1.829268
Freq: A-DEC, dtype: float64
>>> print(res.forecast(1))
2003    2.195122
Freq: A-DEC, dtype: float64
>>> new_index = pd.period_range(start='1980', periods=3, freq='Y')
>>> new_observations = pd.Series([1.4, 0.3, 1.2], index=new_index)
>>> new_res = res.apply(new_observations)
>>> print(new_res.params)
y.L1    1.219512
dtype: float64
>>> print(new_res.fittedvalues)
1981    1.707317
1982    0.365854
Freq: A-DEC, dtype: float64
>>> print(new_res.forecast(1))
1983    1.463415
Freq: A-DEC, dtype: float64

Last update: Oct 03, 2024