MeasurementError#
- class pymc_extras.statespace.models.structural.MeasurementError(name: str = 'MeasurementError', observed_state_names: list[str] | None = None, share_states: bool = False)[source]#
Measurement error component for structural time series models.
This component adds observation noise to the model by introducing a variance parameter that affects the observation covariance matrix H. Unlike other components, it has no hidden states and should only be used in combination with other components.
- Parameters:
name (str, optional) – Name of the measurement error component. Default is “MeasurementError”.
observed_state_names (list[str] | None, optional) – Names of the observed variables. 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
The measurement error component models observation noise as:
\[y_t = \text{signal}_t + \varepsilon_t, \quad \varepsilon_t \sim N(0, \sigma^2)\]Where \(\text{signal}_t\) is the true signal from other components and \(\sigma^2\) is the measurement error variance.
- This component:
Has no hidden states (k_states = 0)
Has no innovations (k_posdef = 0)
Adds a single parameter: sigma_{name}
Modifies the observation covariance matrix H
Examples
Basic usage with trend component:
from pymc_extras.statespace import structural as st import pymc as pm import pytensor.tensor as pt trend = st.LevelTrend(order=2, innovations_order=1) error = st.MeasurementError() ss_mod = (trend + error).build() # Use with PyMC 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']) initial_trend = pm.Normal('initial_trend', sigma=10, dims=ss_mod.param_dims['initial_trend']) sigma_obs = pm.Exponential('sigma_obs', 1, dims=ss_mod.param_dims['sigma_obs']) ss_mod.build_statespace_graph(data) idata = pm.sample()
Multivariate measurement error:
# For multiple observed variables # This creates separate measurement error variances for each variable # sigma_obs_error will have shape (3,) for the three variables error = st.MeasurementError( name="obs_error", observed_state_names=["gdp", "unemployment", "inflation"] )
Complete model example:
trend = st.LevelTrend(order=2, innovations_order=1) seasonal = st.TimeSeasonality(season_length=12, innovations=True) error = st.MeasurementError() model = (trend + seasonal + error).build() # The model now includes: # - Trend parameters: level_trend, sigma_trend # - Seasonal parameters: seasonal_coefs, sigma_seasonal # - Measurement error parameter: sigma_obs
See also
ComponentBase class for all structural components.
StructuralTimeSeriesComplete model class.
- __init__(name: str = 'MeasurementError', observed_state_names: list[str] | None = None, share_states: bool = False)[source]#
Methods
__init__([name, observed_state_names, ...])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
coordsdata_namesexog_namesk_endogk_posdefk_statesn_timestepsneeds_exog_dataobserved_state_namesparam_dimsparam_infoparam_namesshock_namesstate_names