Getting started with seasight

seasight provides tools to see seasonal adjustment more clearly. It wraps the seasonal interface to X-13ARIMA-SEATS with:

  • summary diagnostics,
  • automatic model selection, and
  • reproducible HTML reports.

The main target audience are applied economists and official statisticians who need stable, well-documented seasonal adjustment workflows, e.g. in National Accounts or short-term indicators.

The design follows the recommendations in Eurostat’s ESS Guidelines on Seasonal Adjustment and the Handbook on Seasonal Adjustment.(European Commission)

How this package differs from alternatives

seasight is designed to complement the core seasonal API.

  • Keep using seasonal::seas() when you need direct hand-crafted X-13 calls.
  • Use seasight when you need a standardized and auditable workflow around those calls (candidate grids, diagnostics, ranking, and reporting artifacts).

In other words, seasight focuses on decision support and reproducibility in institutional workflows, while the decomposition engine remains X-13 via seasonal.

Setup

library(seasight)
library(seasonal)

# Example monthly time series from base R
x <- AirPassengers
x
#>      Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
#> 1949 112 118 132 129 121 135 148 148 136 119 104 118
#> 1950 115 126 141 135 125 149 170 170 158 133 114 140
#> 1951 145 150 178 163 172 178 199 199 184 162 146 166
#> 1952 171 180 193 181 183 218 230 242 209 191 172 194
#> 1953 196 196 236 235 229 243 264 272 237 211 180 201
#> 1954 204 188 235 227 234 264 302 293 259 229 203 229
#> 1955 242 233 267 269 270 315 364 347 312 274 237 278
#> 1956 284 277 317 313 318 374 413 405 355 306 271 306
#> 1957 315 301 356 348 355 422 465 467 404 347 305 336
#> 1958 340 318 362 348 363 435 491 505 404 359 310 337
#> 1959 360 342 406 396 420 472 548 559 463 407 362 405
#> 1960 417 391 419 461 472 535 622 606 508 461 390 432

We assume that X-13ARIMA-SEATS is available via the seasonal package (see ?seasonal::seas for installation details).

A first seasonal adjustment with seasonal

In production you typically start from a manually maintained X-13 specification. Here we use the very simple default call:

m_current <- seas(x)
summary(m_current)
#> 
#> Call:
#> seas(x = x)
#> 
#> Coefficients:
#>                     Estimate Std. Error z value Pr(>|z|)    
#> Weekday           -0.0029497  0.0005232  -5.638 1.72e-08 ***
#> Easter[1]          0.0177674  0.0071580   2.482   0.0131 *  
#> AO1951.May         0.1001558  0.0204387   4.900 9.57e-07 ***
#> MA-Nonseasonal-01  0.1156204  0.0858588   1.347   0.1781    
#> MA-Seasonal-12     0.4973600  0.0774677   6.420 1.36e-10 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> SEATS adj.  ARIMA: (0 1 1)(0 1 1)  Obs.: 144  Transform: log
#> AICc: 947.3, BIC: 963.9  QS (no seasonality in final):    0  
#> Box-Ljung (no autocorr.): 23.88   Shapiro (normality): 0.9908

m_current is a regular seasonal::seas object. seasight does not replace seasonal – it sits on top and helps you:

  • assess the quality of a given model,
  • explore alternative specifications, and
  • document the decision in a consistent way.

Low-level diagnostics: sa_tests_model()

The basic diagnostic building block is sa_tests_model(). It computes a set of standard tests for a single seas model:

tests_current <- sa_tests_model(m_current)
tests_current
#> # A tibble: 1 × 15
#>      M7 IDS   QS_p_x11 QS_p_seats  QS_p QSori_p_x11 QSori_p_seats QSori_p  LB_p
#>   <dbl> <chr>    <dbl>      <dbl> <dbl>       <dbl>         <dbl>   <dbl> <dbl>
#> 1 0.203 yes          1          1     1           0             0       0 0.225
#> # ℹ 6 more variables: QS_SA_x11 <dbl>, QS_SA_seats <dbl>, QS_SA <dbl>,
#> #   QSori_x11 <dbl>, QSori_seats <dbl>, QSori <dbl>

For the 0.1.x pre-submission cycle, the core user-facing outputs are frozen; typical fields include:

  • Residual seasonality (QS on SA) X-11/SEATS QS statistics on the seasonally adjusted series.
  • Seasonality in the original series (QSori) QS statistics on the unadjusted series.
  • M7 X-11 M-statistics for residual seasonality (M7 is the main one used by Eurostat).(European Commission)
  • IDS The “identifiable seasonality” indicator used in Eurostat practice.
  • Residual autocorrelation (Ljung–Box) A basic check that the ARIMA model is absorbing the dynamics.
  • Volatility reduction How much the standard deviation of growth rates falls when moving from raw to seasonally adjusted data.
  • Seasonal amplitude Size of the seasonal component relative to the series level.

These metrics are the raw ingredients for the higher-level decisions discussed below.

Automatic model search: auto_seasonal_analysis()

auto_seasonal_analysis() searches over a grid of candidate X-13 specs and ranks them according to a composite score:

To keep this example quick to build, we use three default ARIMA specifications and skip the additional fivebestmdl() search and revision-history calculations. Increase the grid and include_history_top_n for a full model review.

res <- auto_seasonal_analysis(
  y                = x,
  use_fivebest     = FALSE,
  max_specs        = 3,
  include_history_top_n = 0,
  include_easter   = "auto",
  td_usertype      = "td",
  engine           = "auto"   # let seasight choose between SEATS / X-11
)

names(res)
#>  [1] "best"                 "y"                    "table"               
#>  [4] "specs_tried"          "frequency"            "transform"           
#>  [7] "comparison_mode"      "regressor_comparison" "weak_seasonality"    
#> [10] "baseline"             "seasonality"

The most important components are:

  • res$best The best seas model (a regular seasonal::seas object).

  • res$table A tibble with one row per candidate, including:

    head(res$table[, c("model_label", "engine", "AICc", "QS_p", "LB_p")])
    #> # A tibble: 6 × 5
    #>   model_label engine  AICc  QS_p   LB_p
    #>   <chr>       <chr>  <dbl> <dbl>  <dbl>
    #> 1 Spec_1      seats   985.     1 0.120 
    #> 2 Spec_5      seats   987.     1 0.132 
    #> 3 Spec_3      seats   989.     1 0.0605
    #> 4 Spec_2      x11     985.     1 0.120 
    #> 5 Spec_6      x11     987.     1 0.132 
    #> 6 Spec_4      x11     989.     1 0.0605

    Typical columns include:

    • model_label – a short identifier,
    • ARIMA structure (ARIMA_disp / arima / spec_id),
    • with_td, td_p – trading-day regressor and its p-value,
    • QS_p_x11, QS_p_seats, QS_p – QS on SA,
    • QSori_p_x11, QSori_p_seats, QSori_p – QS on original,
    • LB_p – Ljung–Box p-value,
    • seasonal_amp_pct – peak-to-trough seasonal amplitude: the seasonal-factor range in percentage points for log models, or the additive component range as a percentage of the median absolute series level for level models,
    • vola_reduction_pct – volatility reduction (%),
    • dist_sa_L1 – L1 distance vs. the current SA (if supplied),
    • rev_mae – mean absolute revision (if history info is available),
    • score – the composite score used for ranking.
  • res$seasonality A nested list with an “existence-of-seasonality” decision for the original series, based on QS, IDS and M7 (see Eurostat guidelines).(European Commission)

Calendar regressors (trading days & moving holidays)

seasight can compare models without regressors against models with user-supplied calendar regressors via td_candidates.

A key design choice: the package does not ship country-specific calendars. Instead you can build generic regressors yourself and pass them in.

The holiday dates below fall outside the AirPassengers sample. We therefore use a simulated monthly series for 2018–2024 to demonstrate alignment and model fitting. This example holds ARIMA at the first default specification while comparing calendar and engine choices. It is an illustration, not an estimate of actual holiday effects.

set.seed(123)
month <- seq_len(84)
y_holiday <- ts(
  exp(4 + 0.01 * month + 0.15 * sin(2 * pi * month / 12) + rnorm(84, sd = 0.03)),
  start = c(2018, 1), frequency = 12
)

diwali_dates <- as.Date(c(
  "2018-11-07","2019-10-27","2020-11-14","2021-11-04",
  "2022-10-24","2023-11-12","2024-11-01"
))

td <- build_user_xreg(
  y = y_holiday,
  holidays = list(diwali = list(dates = diwali_dates, start = -1, end = 1)),
  td_usertype = "holiday"
)

res_td <- auto_seasonal_analysis(
  y_holiday, td_candidates = td, engine = "auto",
  use_fivebest = FALSE, max_specs = 1,
  include_history_top_n = 0
)
res_td$table[1, c("model_label", "with_td", "td_name", "QS_p", "LB_p")]
#> # A tibble: 1 × 5
#>   model_label with_td td_name  QS_p   LB_p
#>   <chr>       <lgl>   <chr>   <dbl>  <dbl>
#> 1 Spec_1      FALSE   <NA>        1 0.0565

For more realistic workflows (multiple TD candidates, baselines, and decision rules), see the SA practice and Advanced vignettes.

Inspecting the winning model

The winning model is in res$best:

best <- res$best
summary(best)$coefficients
#>                    Estimate  Std. Error  z value     Pr(>|z|)
#> Easter[1]         0.0199900 0.009935389 2.012000 4.421992e-02
#> MA-Nonseasonal-01 0.3770536 0.079758774 4.727424 2.273859e-06
#> MA-Seasonal-12    0.5493530 0.076648159 7.167204 7.654501e-13

You can use it like any other seas object:

final(best)[1:6]
#> [1] 123.8496 125.0909 125.1333 127.7531 126.0318 125.8312
original(best)[1:6]
#> [1] 112 118 132 129 121 135
resid(best)[1:6]
#> [1]  0.0009818329  0.0009095614 -0.0079922898  0.0071903729 -0.0186996341
#> [6] -0.0176225435

If you prefer to keep everything explicit, you can access the underlying specification as R code using sa_copyable_call() (also shown in the HTML report, see below):

sa_copyable_call(best, x_expr = "AirPassengers")
#> [1] "seas(x = AirPassengers, transform.function = \"log\", arima.model = \"(0 1 1)(0 1 1)\", regression.variables = \"easter[1]\", regression.aictest = NULL, outlier = NULL)"

Visual “cards”: sa_existence_card() and sa_engine_choice_card()

In interactive HTML outputs (e.g. pkgdown site, Quarto, Shiny) it is often helpful to summarise key decisions in compact “cards”.

seasight exposes two such cards:

# Existence-of-seasonality card
sa_existence_card(res)

Existence of Seasonality

Existence of seasonality: ADJUST — based on IDS, M7 and QS on the original series.

  • IDS (ONS 'identifiable seasonality'): yes.
  • M7 (X-11): 0.203 → clear seasonality.
  • QS on original: X-11 p = <0.001, SEATS p = <0.001 → overall = <0.001.
  • SEATS seasonal component: present.

At least two test families indicate seasonality. Proceed with seasonal adjustment.


# Engine choice card (SEATS vs X-11)
sa_engine_choice_card(res)

Engine choice: SEATS vs X-11

Decomposition engine selected: SEATS

  • Residual seasonality (QS on SA): SEATS p = 1.000, X-11 p = 1.000. SEATS is equivalent or better.
  • QS on original (existence): SEATS p = <0.001, X-11 p = <0.001.
  • SEATS seasonal component: present.

SEATS is the default choice; switching to X-11 only occurs if there are clear advantages (residual QS) or stability-related warnings.

  • The existence card explains whether the series should be adjusted, combining QS, M7 and IDS into a single “robust” call.
  • The engine card provides a transparent rationale for choosing SEATS vs X-11 based on their diagnostics and stability.

From analysis to decision: sa_should_switch()

If you provide a current (baseline) model, seasight can suggest whether you should keep it or switch to the new best candidate.

res_with_baseline <- auto_seasonal_analysis(
  y             = x,
  current_model = m_current,
  use_fivebest  = FALSE,
  max_specs     = 3,
  include_history_top_n = 0
)

sa_should_switch(res_with_baseline)
#> [1] "KEEP_CURRENT_MODEL"

The decision rule takes into account:

  • whether the new model passes basic diagnostics (QS / Ljung–Box),
  • whether comparable AICc improves materially relative to the incumbent,
  • whether QS and Ljung–Box diagnostics avoid material deterioration, and
  • whether distance and seasonal-correlation safeguards are satisfied.

An identical adjustment is kept. If incumbent evidence is missing or AICc is not comparable because the input sample or transformation differs, the helper returns "REVIEW_REQUIRED" instead of recommending a change.

You can always override this decision – the goal is to provide a transparent, reproducible default that is broadly aligned with Eurostat practice (e.g. avoid switching for tiny cosmetic improvements).(European Commission)

A full HTML report in one call: sa_report_html()

For documentation, review meetings or method reports you often want a self-contained HTML document:

tmp_file <- tempfile(fileext = ".html")

sa_report_html(
  y             = res_with_baseline,
  current_model = m_current,
  title         = "AirPassengers – seasight demo",
  outfile       = tmp_file
)

tmp_file
#> [1] "/tmp/RtmpBUdTgo/fileb963b9d9870.html"
# Browse to this file in your file manager or with browseURL(tmp_file)

The report includes:

  • an executive summary (existence of seasonality, best model, decision),
  • narrative cards explaining why the model was chosen,
  • comparison plots vs. the current model (levels and growth),
  • diagnostics (QS, M7, IDS, Ljung–Box, seasonal amplitude, volatility reduction),
  • outlier listings for current and new model,
  • copy-pasteable seas() calls for both specifications, and
  • a “Top candidates” table with the highest-ranked alternatives.

Where to go next

For a deeper dive into:

  • using baselines (current production models),
  • passing custom trading-day candidates, and
  • understanding the built-in decision rules,

see the companion vignette:

“Advanced usage: baselines, TD candidates & decision rules”

which uses the same AirPassengers series but goes further into methodological details.