Autoregressive#

class pymc_extras.statespace.models.structural.Autoregressive(order: int = 1, name: str = 'auto_regressive', observed_state_names: list[str] | None = None, share_states: bool = False)[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.

  • name (str, default "auto_regressive") – A name for this autoregressive component. Used to label dimensions and coordinates.

  • observed_state_names (list[str] | None, default None) – List of strings for observed state labels. If None, defaults to [“data”].

  • share_states (bool, default False) – Whether latent states are shared across the observed states. If True, there will be only one set of latent states, which are observed by all observed states. If False, each observed state has its own set of latent states. This argument has no effect if k_endog is 1.

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

Examples

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

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

trend = st.LevelTrend(order=1, innovations_order=0)
ar = st.Autoregressive(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)
    idata = pm.sample(nuts_sampler='numpyro')
__init__(order: int = 1, name: str = 'auto_regressive', observed_state_names: list[str] | None = None, share_states: bool = False)[source]#

Methods

__init__([order, name, ...])

build([name, filter_type, verbose, mode])

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

set_coords()

Set default coordinate specifications.

set_data_info()

Set default data specifications.

set_parameters()

Set component parameter specifications.

set_shocks()

Set default shock specifications based on the number of sources of innovations in the component.

set_states()

Set default state specification based on number of states and endogenous variables in the component.

Attributes

coords

data_names

exog_names

k_endog

k_posdef

k_states

n_timesteps

needs_exog_data

observed_state_names

param_dims

param_info

param_names

shock_names

state_names