AutoregressiveComponent#

class pymc_experimental.statespace.models.structural.AutoregressiveComponent(order: int = 1, name: str = 'AutoRegressive')[source]#

Autoregressive timeseries component

Parameters:

order (int or sequence of int) – If int, the number of lags to include in the model. If a sequence, an array-like of zeros and ones indicating which lags to include in the model.

Notes

An autoregressive component can be thought of as a way o introducing serially correlated errors into the model. The process is modeled:

\[x_t = \sum_{i=1}^p \rho_i x_{t-i}\]

Where p, the number of autoregressive terms to model, is the order of the process. By default, all lags up to p are included in the model. To disable lags, pass a list of zeros and ones to the order argumnet. For example, order=[1, 1, 0, 1] would become:

\[x_t = \rho_1 x_{t-1} + \rho_2 x_{t-1} + \rho_4 x_{t-1}\]

The coefficient \(\rho_3\) has been constrained to zero.

Warning

This class is meant to be used as a component in a structural time series model. For modeling of stationary processes with ARIMA, use statespace.BayesianSARIMA.

Examples

Model a timeseries as an AR(2) process with non-zero mean:

from pymc_experimental.statespace import structural as st
import pymc as pm
import pytensor.tensor as pt

trend = st.LevelTrendComponent(order=1, innovations_order=0)
ar = st.AutoregressiveComponent(2)
ss_mod = (trend + ar).build()

with pm.Model(coords=ss_mod.coords) as model:
    P0 = pm.Deterministic('P0', pt.eye(ss_mod.k_states) * 10, dims=ss_mod.param_dims['P0'])
    intitial_trend = pm.Normal('initial_trend', sigma=10, dims=ss_mod.param_dims['initial_trend'])
    ar_params = pm.Normal('ar_params', dims=ss_mod.param_dims['ar_params'])
    sigma_ar = pm.Exponential('sigma_ar', 1, dims=ss_mod.param_dims['sigma_ar'])

    ss_mod.build_statespace_graph(data, mode='JAX')
    idata = pm.sample(nuts_sampler='numpyro')
__init__(order: int = 1, name: str = 'AutoRegressive')[source]#

Methods

__init__([order, name])

build([name, filter_type, verbose])

Build a StructuralTimeSeries statespace model from the current component(s)

make_and_register_data(name, shape[, dtype])

Helper function to create a pytensor symbolic variable and register it in the _name_to_data dictionary

make_and_register_variable(name, shape[, dtype])

Helper function to create a pytensor symbolic variable and register it in the _name_to_variable dictionary

make_symbolic_graph()

populate_component_properties()