Skip to content

pymetrix-seasonal

A plugin: a separate package

pymetrix-seasonal is a first-party plugin, installed on its own:

python -m pip install --pre pymetrix-seasonal

Seasonal adjustment for pymetrix by X-13ARIMA-SEATS (x13as) and TRAMO-SEATS (JDemetra+, in Java).

The names pymetrix_seasonal exports (its __all__), with their full documentation. Import them from the plugin: from pymetrix_seasonal import .... The plugin's README says more.

Public names

run_x13

run_x13(folder: str, spec: str, table: str, name: str) -> tuple[str, str, ndarray, str]

Run x13as on spec in a scratch folder: its console, its output file, the saved table (d11, s11, ...) as values, and its warnings. An error from the program is a DataError naming the series.

TramoSeats dataclass

TramoSeats(spec: Annotated[Literal['rsafull', 'rsa5', 'rsa4', 'rsa3', 'rsa2', 'rsa1', 'rsa0'], Widget('choice', help="JDemetra+'s specification: RSAfull, RSA5 and RSA4 choose the model automatically; RSA0 to RSA3 the airline model")] = 'rsafull', log: Annotated[bool | None, Widget('choice', help="multiplicative (logs) or additive; empty = the specification's (TRAMO's test; levels in RSA0)")] = None, outlier: Annotated[bool | None, Widget('choice', help="detect outliers; empty = the specification's (all but RSA0)")] = None, trading: Annotated[Literal['spec', 'none', 'working', 'trading', 'auto'], Widget('choice', help="trading-day effects, with leap year, each pretested: working days, six trading-day contrasts, or the better by an F-test; spec = the specification's")] = 'spec', easter: Annotated[bool | None, Widget('choice', help="an Easter effect, pretested; empty = the specification's (RSA2, RSA4, RSA5, RSAfull)")] = None, libraries: Annotated[str | None, Widget('text', advanced=True, help='folder of the JDemetra+ jars; empty = JDPLUS_PATH or where pymetrix_seasonal.jdemetra.install() put them')] = None, arima: Annotated[str, Widget('text', advanced=True, help="an ARIMA model such as (0 1 1)(0 1 1); empty = the specification's")] = '', outlier_types: Annotated[str, Widget('text', advanced=True, help="outlier types: ao ls tc so; empty = the specification's (ao ls tc)")] = '', critical: Annotated[float | None, Widget('number', min=2, max=10, step=0.1, advanced=True, help="outlier critical t-value; empty = set from the series' length")] = None, easter_days: Annotated[int, Widget('number', min=1, max=15, advanced=True, help='days the Easter effect lasts')] = 6, approximation: Annotated[Literal['legacy', 'none', 'noisy'], Widget('choice', advanced=True, group='SEATS', help='when the model does not decompose: approximate it as TRAMO-SEATS always has, not at all, or with a noisy trend')] = 'legacy', seats_method: Annotated[Literal['burman', 'kalman'], Widget('choice', advanced=True, group='SEATS', help="components by Burman's algorithm or the Kalman smoother")] = 'burman', trend_boundary: Annotated[float, Widget('number', min=0, max=1, step=0.05, advanced=True, group='SEATS', help='AR roots above this modulus go to the trend (rmod)')] = 0.5, seasonal_boundary: Annotated[float, Widget('number', min=0, max=1, step=0.05, advanced=True, group='SEATS', help='seasonal AR roots above this modulus go to the seasonal (smod)')] = 0.8, seasonal_boundary_pi: Annotated[float, Widget('number', min=0, max=1, step=0.05, advanced=True, group='SEATS', help='the same, for the root at the frequency pi')] = 0.8, seasonal_tolerance: Annotated[float, Widget('number', min=0, max=10, step=0.5, advanced=True, group='SEATS', help='degrees from a seasonal frequency that still count as seasonal (epsphi)')] = 2.0, xl: Annotated[float, Widget('number', min=0.9, max=1, step=0.01, advanced=True, group='SEATS', help='MA roots above this modulus are made unit roots (xl)')] = 0.95, interventions: Annotated[str, Widget('text', advanced=True, group='Regression', help='outliers known in advance, kept without testing: ao, ls, tc or so and the period, e.g. ls 2020Q2, ao 2008Q4')] = '', regressors: Annotated[str, Widget('text', advanced=True, group='Regression', help='series of the dataset as regressors (holidays, strikes, policy changes), each with the component its effect goes to: calendar (the default: removed from the adjusted series), irregular, trend or seasonal; e.g. holidays, strike=irregular')] = '')

TRAMO-SEATS (Gómez and Maravall, Bank of Spain), as Eurostat's JDemetra+ 3 computes it, in Java (see pymetrix.jdemetra): TRAMO fits a regARIMA model (logs or levels, the ARIMA model, outliers, trading-day and Easter effects), and SEATS splits the linearised series into trend, seasonal and irregular components by signal extraction from that model.

spec is one of JDemetra+'s predefined specifications, from RSA0 (levels, the airline model, nothing else) to RSAfull (the log test, an automatic model, outliers, trading days and Easter, each pretested); the other settings change it, and each left empty or at its default keeps the specification's own choice.

fixed_outliers

fixed_outliers() -> list[tuple[str, str]]

interventions as (type, period) pairs: "ls 2020Q2, ao 2008Q4" gives [("ls", "2020Q2"), ("ao", "2008Q4")].

user_regressors

user_regressors() -> list[tuple[str, str]]

regressors as (series, component) pairs: "holidays, strike=irregular" gives [("holidays", "calendar"), ("strike", "irregular")].

inputs

inputs() -> tuple[str, ...]

The dataset's series the adjustment uses besides the series adjusted: the regressors.

changes

changes() -> dict[str, Any]

The settings that change the specification: those not at their defaults.

specification

specification(J: Any, period: int, index: PeriodIndex | None = None) -> Any

JDemetra+'s TramoSeatsSpec: the predefined spec with this object's changes. User regressors refer to the context decompose fills (group r); index, the series' periods, places the interventions.

decompose

decompose(y: ndarray, period: int, name: str, index: PeriodIndex | None = None, notes: dict[str, str] | None = None, regressors: dict[str, ndarray] | None = None) -> tuple[ndarray, bool]

The seasonal factor (or component), from JDemetra+'s adjusted series; notes, if given, gets the model TRAMO chose, the outliers it found, the regression effects, the specification and the JDemetra+ version. regressors gives the values of the series named in regressors, over the same periods as y.

X13 dataclass

X13(log: Annotated[bool | None, _LOG] = None, outlier: Annotated[bool, Widget('checkbox', help='detect and adjust for outliers')] = True, trading: Annotated[bool, Widget('checkbox', help='estimate trading-day effects (td)')] = False, program: Annotated[str | None, Widget('text', advanced=True, help='folder of the x13as program; empty = X13PATH or the PATH')] = None, adjustment: Annotated[Literal['x11', 'seats'], Widget('choice', help='X-11 moving averages, or SEATS (signal extraction from the ARIMA model)')] = 'x11', mode: Annotated[Literal['auto', 'mult', 'add', 'pseudoadd', 'logadd'], Widget('choice', help="X-11 decomposition: multiplicative, additive, pseudo-additive or log-additive; auto = X-13's default")] = 'auto', easter: Annotated[int, Widget('number', min=0, max=25, help='days before Easter in an Easter regressor (often 8); 0 = none')] = 0, seasonal_filter: Annotated[Literal['', 's3x1', 's3x3', 's3x5', 's3x9', 's3x15', 'stable', 'msr', 'x11default'], Widget('choice', advanced=True, help='X-11 seasonal moving average (3x3, 3x5, 3x9, ...); empty = chosen by X-13 (msr)')] = '', trend_filter: Annotated[int | None, Widget('number', min=3, max=101, step=2, advanced=True, help='X-11 Henderson trend filter length (odd); empty = chosen by X-13')] = None, sigma_limits: Annotated[str, Widget('text', advanced=True, help="X-11 extreme-value limits in standard deviations, e.g. 1.5 2.5; empty = X-13's")] = '', arima: Annotated[str, Widget('text', advanced=True, help='an ARIMA model such as (0 1 1)(0 1 1); empty = chosen automatically')] = '', max_order: Annotated[str, Widget('text', advanced=True, help='automatic model: largest regular and seasonal ARMA orders')] = '2 1', max_diff: Annotated[str, Widget('text', advanced=True, help='automatic model: largest regular and seasonal differences')] = '2 1', outlier_types: Annotated[str, Widget('text', advanced=True, help="outlier types to look for: ao ls tc so (or all); empty = X-13's (ao ls)")] = '', critical: Annotated[float | None, Widget('number', min=2, max=10, step=0.1, advanced=True, help="outlier critical t-value; empty = set by X-13 from the series' length")] = None, forecast: Annotated[int | None, Widget('number', min=0, max=120, advanced=True, help="periods forecast to extend the series before filtering; empty = X-13's default")] = None, spec: Annotated[str, Widget('text', advanced=True, help='other X-13 specification text, added as written')] = '')

X-13ARIMA-SEATS (US Census Bureau), the x13as program run on a specification written here: an ARIMA model (chosen automatically, or given), outliers, trading-day and Easter effects, then X-11 or SEATS adjustment.

Each setting left at its default leaves that option out of the specification, so X-13 uses its own default; with every default the specification is the one statsmodels' x13_arima_analysis writes. spec adds any other X-13 specification text (for example check{print=all}); options the fields here write cannot be given twice.

specification

specification(y: ndarray, index: PeriodIndex, period: int, name: str, log: bool) -> str

The X-13 specification for one series (its data included).

decompose

decompose(y: ndarray, period: int, name: str, index: PeriodIndex | None = None, notes: dict[str, str] | None = None) -> tuple[ndarray, bool]

The seasonal factor (or component); notes, if given, gets the program's folder, the specification it ran (backend_options, the data left out) and what the run reports (x13_notes).

x13_notes

x13_notes(stdout: bytes | str, output: str) -> dict[str, str]

What an X-13 run reports about itself: the program's version, the ARIMA model it estimated, and the outliers it found ("none" when it looked and found none), read from its console and output file.

x13_program

x13_program(path: str | None = None) -> str | None

Where the X-13ARIMA-SEATS program is: path, the folder in X13PATH, or the PATH.

Plugin plumbing

What pymetrix's plugin loader reads (PLUGIN, register) and the plugin's version.

__version__ module-attribute

__version__ = '0.1.0a1'

PLUGIN module-attribute

PLUGIN = PluginInfo(name='pymetrix-seasonal', version=__version__, license='BSD-3-Clause', maintainer='Geoffrey Heenan', description='Seasonal adjustment by X-13ARIMA-SEATS (the x13as program) and TRAMO-SEATS (JDemetra+, in Java)', install='pip install "pymetrix-seasonal[jdemetra]"')

register

register() -> None

The entry point: importing the package has registered both methods.