statsmodels.tsa.arima.model.ARIMAResults.apply

ARIMAResults.apply(endog, exog=None, refit=False, fit_kwargs=None, copy_initialization=False, **kwargs)

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).

copy_initializationbool, optional

Whether or not to copy the initialization from the current results set to the new model. Default is False

fit_kwargsdict, optional

Keyword arguments to pass to fit (if refit=True) or filter / smooth.

**kwargs

Keyword arguments may be used to modify model specification arguments when created the new model object.

Returns:
results

Updated Results object, that includes results only 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. For observations that continue that original dataset by follow directly after its last element, see the append and extend methods.

Examples

>>> index = pd.period_range(start='2000', periods=2, freq='Y')
>>> original_observations = pd.Series([1.2, 1.5], index=index)
>>> mod = sm.tsa.SARIMAX(original_observations)
>>> res = mod.fit()
>>> print(res.params)
ar.L1     0.9756
sigma2    0.0889
dtype: float64
>>> print(res.fittedvalues)
2000    0.0000
2001    1.1707
Freq: A-DEC, dtype: float64
>>> print(res.forecast(1))
2002    1.4634
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)
ar.L1     0.9756
sigma2    0.0889
dtype: float64
>>> print(new_res.fittedvalues)
1980    1.1707
1981    1.3659
1982    0.2927
Freq: A-DEC, dtype: float64
Freq: A-DEC, dtype: float64
>>> print(new_res.forecast(1))
1983    1.1707
Freq: A-DEC, dtype: float64

Last update: Nov 14, 2024