statsmodels.tsa.deterministic.DeterministicProcess

class statsmodels.tsa.deterministic.DeterministicProcess(index, *, period=None, constant=False, order=0, seasonal=False, fourier=0, additional_terms=(), drop=False)[source]

Container class for deterministic terms.

Directly supports constants, time trends, and either seasonal dummies or fourier terms for a single cycle. Additional deterministic terms beyond the set that can be directly initialized through the constructor can be added.

Parameters:
index{Sequence[Hashable], pd.Index}

The index of the process. Should usually be the “in-sample” index when used in forecasting applications.

period{float, int}, default None

The period of the seasonal or fourier components. Must be an int for seasonal dummies. If not provided, freq is read from index if available.

constantbool, default False

Whether to include a constant.

orderint, default 0

The order of the tim trend to include. For example, 2 will include both linear and quadratic terms. 0 exclude time trend terms.

seasonalbool = False

Whether to include seasonal dummies

fourierint = 0

The order of the fourier terms to included.

additional_termsSequence[DeterministicTerm]

A sequence of additional deterministic terms to include in the process.

dropbool, default False

A flag indicating to check for perfect collinearity and to drop any linearly dependent terms.

Attributes:
index

The index of the process

terms

The deterministic terms included in the process

Notes

See the notebook Deterministic Terms in Time Series Models for an overview.

Examples

>>> from statsmodels.tsa.deterministic import DeterministicProcess
>>> from pandas import date_range
>>> index = date_range("2000-1-1", freq="M", periods=240)

First a determinstic process with a constant and quadratic time trend.

>>> dp = DeterministicProcess(index, constant=True, order=2)
>>> dp.in_sample().head(3)
            const  trend  trend_squared
2000-01-31    1.0    1.0            1.0
2000-02-29    1.0    2.0            4.0
2000-03-31    1.0    3.0            9.0

Seasonal dummies are included by setting seasonal to True.

>>> dp = DeterministicProcess(index, constant=True, seasonal=True)
>>> dp.in_sample().iloc[:3,:5]
            const  s(2,12)  s(3,12)  s(4,12)  s(5,12)
2000-01-31    1.0      0.0      0.0      0.0      0.0
2000-02-29    1.0      1.0      0.0      0.0      0.0
2000-03-31    1.0      0.0      1.0      0.0      0.0

Fourier components can be used to alternatively capture seasonal patterns,

>>> dp = DeterministicProcess(index, constant=True, fourier=2)
>>> dp.in_sample().head(3)
            const  sin(1,12)  cos(1,12)  sin(2,12)  cos(2,12)
2000-01-31    1.0   0.000000   1.000000   0.000000        1.0
2000-02-29    1.0   0.500000   0.866025   0.866025        0.5
2000-03-31    1.0   0.866025   0.500000   0.866025       -0.5

Multiple Seasonalities can be captured using additional terms.

>>> from statsmodels.tsa.deterministic import Fourier
>>> index = date_range("2000-1-1", freq="D", periods=5000)
>>> fourier = Fourier(period=365.25, order=1)
>>> dp = DeterministicProcess(index, period=3, constant=True,
...                           seasonal=True, additional_terms=[fourier])
>>> dp.in_sample().head(3)
            const  s(2,3)  s(3,3)  sin(1,365.25)  cos(1,365.25)
2000-01-01    1.0     0.0     0.0       0.000000       1.000000
2000-01-02    1.0     1.0     0.0       0.017202       0.999852
2000-01-03    1.0     0.0     1.0       0.034398       0.999408

Methods

apply(index)

Create an identical determinstic process with a different index

in_sample()

Produce deterministic trends for in-sample fitting.

out_of_sample(steps[, forecast_index])

Produce deterministic trends for out-of-sample forecasts

range(start, stop)

Deterministic terms spanning a range of observations

Properties

index

The index of the process

terms

The deterministic terms included in the process


Last update: Nov 14, 2024