| Title: | Quality Assessment and Reporting for Seasonal Adjustment |
|---|---|
| Description: | Add-in to the 'rjd3x13' and 'rjd3tramoseats' packages on seasonal adjustments. It allows to produce quality assessments outputs (such as dashboards) and reports (with 'Quarto') describing seasonal adjustment models. |
| Authors: | Alain Quartier-la-Tente [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-7890-3857>) |
| Maintainer: | Alain Quartier-la-Tente <[email protected]> |
| License: | EUPL |
| Version: | 0.2.0 |
| Built: | 2026-11-18 14:26:39 UTC |
| Source: | https://github.com/AQLT/rjd3report |
Colors used in the tables of the dashboards (see simple_dashboard()) according to the status
of each statistic.
dashboard_colors( good = NULL, uncertain = NULL, bad = NULL, neutral = NULL, palette = c("pastel", "classic") )dashboard_colors( good = NULL, uncertain = NULL, bad = NULL, neutral = NULL, palette = c("pastel", "classic") )
good, uncertain, bad
|
colors of the good, uncertain and bad statistics. |
neutral |
color of the statistics without status (e.g. variance decomposition). |
palette |
|
A named character vector.
dashboard_colors() dashboard_colors(palette = "classic")dashboard_colors() dashboard_colors(palette = "classic")
Function to plot Statistics Canada dashboard of a seasonal adjustment model.
## S3 method for class 'sc_dashboard' plot( x, main = "Seasonal Adjustment Dashboard", subtitle = "", reference_date = TRUE, raw_color = "#33A02C", sa_color = "#E31A1C", trend_color = "black", colors = dashboard_colors(), ... )## S3 method for class 'sc_dashboard' plot( x, main = "Seasonal Adjustment Dashboard", subtitle = "", reference_date = TRUE, raw_color = "#33A02C", sa_color = "#E31A1C", trend_color = "black", colors = dashboard_colors(), ... )
x |
a |
main |
main title. |
subtitle |
subtitle. |
reference_date |
boolean indicating if the reference date should be printed (value of |
raw_color |
color for the raw series. |
sa_color |
color for the seasonal adjusted series. |
trend_color |
color for the trend. |
colors |
colors of the summary of key diagnostics according to the status of each statistic
(see |
... |
other parameters (unused). |
sa_model() reproduces Statistics Canada dashboard used to provide a snapshot of an single seasonal adjustment model at a point in time and to point out some possible problems (see references).
The dashboard is divided into four sections:
Recent History (top left panel): plot of the raw series, the seasonal adjusted series and the trend for the most recent periods (n_recent_obs last observations: 24 by default). It is intended to identify trendF direction, overall volatility and obvious outliers.
Summary of Key Diagnostics (top right panel):
Adjustability (only for X13 models): M7 statistic. Colors: red if M7 > 1.75, yellow if 1.25 < M7 < 1.75 and green if M7 < 1.25.
Residual seasonality: qs (auto-correlations at seasonal lags) and f (Friedman) test on seasonal adjusted series. Colors: red if p-value < 0.01, yellow if 0.01 < p-value < 0.05 and green if p-value > 0.05.
Residual trading-days effects: f (Friedman) test on seasonal adjusted serie. Colors: red if p-value < 0.01, yellow if 0.01 < p-value < 0.05 and green if p-value > 0.05.
Independence of RegARIMA residuals: Ljung-Box test. Colors: red if p-value < 0.01, yellow if 0.01 < p-value < 0.05 and green if p-value > 0.05.
Recent outliers on last (t) and penultimate (t-1) observation. Colors: Red ("bad") if there is an extreme value (only for X13: when table C17 equals to 0), yellow ("uncertain") if there is an outlier in the RegARIMA model and green ("good") otherwise.
Estimated Patterns and Anticipated Movements (middle panel): estimated trading day, moving holiday and seasonal pattern. It presents expected movement in unadjusted series based on the current and previous period.
Net Effect of Seasonal Adjustment (bottom panel): movement in the raw series, compared to typical ranges centered around "neutral" value (when the seasonal adjusted series of the last period is equal to the penultimate period). It also shows the movement in the seasonally adjusted series, compared to typical ranges.
KIRCHNER R., LADIRAY D., MAZZI G. L. (2018), "Quality Measures and Reporting for Seasonal Adjustment", edited by G. L. Mazzi, co-edited by D. Ladiray, European Union, Luxembourg. https://ec.europa.eu/eurostat/web/products-manuals-and-guidelines/-/KS-GQ-18-001
MATTHEWS S. (2016), "Quality Assurance of Seasonal Adjustment for a Large System of Time Series", 36th International Symposium on Forecasting Santander, Spain.
data <- window(rjd3toolkit::ABS$X0.2.09.10.M, start = 2003) sa_model <- rjd3x13::x13(data) dashboard_data <- sc_dashboard(sa_model) plot(dashboard_data, main = "My first seasonal adjustment dashboard", subtitle = "SA with X13")data <- window(rjd3toolkit::ABS$X0.2.09.10.M, start = 2003) sa_model <- rjd3x13::x13(data) dashboard_data <- sc_dashboard(sa_model) plot(dashboard_data, main = "My first seasonal adjustment dashboard", subtitle = "SA with X13")
Functions to plot a simple dashboard of a seasonal adjustment model: plot() uses base R graphics
and autoplot() uses ggplot2 (and patchwork).
With autoplot(), the tables keep their natural size (their font size is reduced if the figure is too small)
and only the plots are resized.
## S3 method for class 'simple_dashboard' plot( x, main = "Simple Dashboard", subtitle = NULL, color_series = c(y = "#F0B400", t = "#1E6C0B", sa = "#155692"), reference_date = TRUE, colors = dashboard_colors(), digits = x$digits, digits_outliers = x$digits_outliers, decimal.mark = getOption("OutDec"), ... ) ## S3 method for class 'simple_dashboard' autoplot( object, main = "Simple Dashboard", subtitle = NULL, color_series = c(y = "#F0B400", t = "#1E6C0B", sa = "#155692"), reference_date = TRUE, colors = dashboard_colors(), digits = object$digits, digits_outliers = object$digits_outliers, decimal.mark = getOption("OutDec"), base_size = 10, table_base_size = 9, ... )## S3 method for class 'simple_dashboard' plot( x, main = "Simple Dashboard", subtitle = NULL, color_series = c(y = "#F0B400", t = "#1E6C0B", sa = "#155692"), reference_date = TRUE, colors = dashboard_colors(), digits = x$digits, digits_outliers = x$digits_outliers, decimal.mark = getOption("OutDec"), ... ) ## S3 method for class 'simple_dashboard' autoplot( object, main = "Simple Dashboard", subtitle = NULL, color_series = c(y = "#F0B400", t = "#1E6C0B", sa = "#155692"), reference_date = TRUE, colors = dashboard_colors(), digits = object$digits, digits_outliers = object$digits_outliers, decimal.mark = getOption("OutDec"), base_size = 10, table_base_size = 9, ... )
x, object
|
A |
main |
Main title. |
subtitle |
Subtitle. |
color_series |
Color of the raw time series, the trend and the seasonally adjusted component. |
reference_date |
Boolean indicating if the reference date should be printed. |
colors |
colors of the tables according to the status of the statistics (see |
digits, digits_outliers
|
number of digits used in the tables (by default the values used in |
decimal.mark |
the character used as decimal mark. |
... |
Other unused parameters. |
base_size |
base font size of the plots and of the text. |
table_base_size |
base font size of the tables. |
data <- window(rjd3toolkit::ABS$X0.2.09.10.M, start = 2003) sa_model <- rjd3x13::x13(data) dashboard_data <- simple_dashboard(sa_model) plot(dashboard_data, main = "Simple dashboard") dashboard_data2 <- simple_dashboard2(sa_model) plot(dashboard_data2, main = "Simple dashboard with outliers") autoplot(dashboard_data2, main = "Simple dashboard with outliers")data <- window(rjd3toolkit::ABS$X0.2.09.10.M, start = 2003) sa_model <- rjd3x13::x13(data) dashboard_data <- simple_dashboard(sa_model) plot(dashboard_data, main = "Simple dashboard") dashboard_data2 <- simple_dashboard2(sa_model) plot(dashboard_data2, main = "Simple dashboard with outliers") autoplot(dashboard_data2, main = "Simple dashboard with outliers")
Methods to print the objects created by sa_preprocessing(), sa_decomposition(),
sa_diagnostics() and sa_report().
In a Quarto or R Markdown document, the objects are automatically rendered with
knit_print(): the output format (HTML, PDF, Typst, Word...) is detected and the tables are
built with tinytable.
## S3 method for class 'rjd3report_block' print(x, ...) ## S3 method for class 'rjd3report_block' knit_print(x, options = NULL, inline = FALSE, ...)## S3 method for class 'rjd3report_block' print(x, ...) ## S3 method for class 'rjd3report_block' knit_print(x, options = NULL, inline = FALSE, ...)
x |
the object to print. |
... |
unused parameters. |
options, inline
|
see |
report_template() returns the path of the Quarto template used by render_report().
use_report_template() copies it in a directory so that it can be customized
(and then used with render_report(template = )).
report_template() use_report_template(path = "sa_report.qmd", overwrite = FALSE)report_template() use_report_template(path = "sa_report.qmd", overwrite = FALSE)
path |
the path of the copied template. |
overwrite |
boolean indicating if an existing file should be overwritten. |
report_template()report_template()
Functions to describe a seasonal adjustment model in a report:
sa_decomposition( x, digits = 3, decimal.mark = getOption("OutDec"), title_level = NULL ) sa_diagnostics( x, tests = diagnostics_tests$id, digits = 3, decimal.mark = getOption("OutDec"), signif_stars = TRUE, var_decomposition = TRUE, title_level = NULL ) sa_preprocessing( x, digits = 3, decimal.mark = getOption("OutDec"), signif_stars = TRUE, title_level = NULL, summary = TRUE, likelihood = TRUE, arima = TRUE, regression = TRUE )sa_decomposition( x, digits = 3, decimal.mark = getOption("OutDec"), title_level = NULL ) sa_diagnostics( x, tests = diagnostics_tests$id, digits = 3, decimal.mark = getOption("OutDec"), signif_stars = TRUE, var_decomposition = TRUE, title_level = NULL ) sa_preprocessing( x, digits = 3, decimal.mark = getOption("OutDec"), signif_stars = TRUE, title_level = NULL, summary = TRUE, likelihood = TRUE, arima = TRUE, regression = TRUE )
x |
a seasonal adjustment model: result of |
digits |
number of digits used in the tables and in the text. |
decimal.mark |
the character used as decimal mark. |
title_level |
|
tests |
identifiers of the tests to print. By default all the available tests:
|
signif_stars |
boolean indicating if the significance stars should be added to the tables. |
var_decomposition |
boolean indicating if the table with the variance decomposition should be printed (only for seasonal adjustment models). |
summary, likelihood, arima, regression
|
booleans indicating which parts of the pre-processing description should be printed. |
sa_preprocessing() describes the pre-processing (RegARIMA or TRAMO model):
summary of the model, likelihood statistics, ARIMA and regression coefficients;
sa_decomposition() describes the decomposition (X-11 or SEATS);
sa_diagnostics() prints a table with the main diagnostics tests on the quality of the
pre-processing and of the decomposition.
The functions return objects that are automatically rendered in a Quarto (or R Markdown)
document, whatever the output format (HTML, PDF with LaTeX or Typst, Word...): it is no
longer necessary to specify the output format nor to use the chunk option results: asis.
The tables are built with tinytable.
The objects can also be printed in the console.
An object of class "rjd3report_block" (see print.rjd3report_block()).
y <- rjd3toolkit::ABS$X0.2.09.10.M sa_x13 <- rjd3x13::x13(y) sa_preprocessing(sa_x13) sa_decomposition(sa_x13) sa_diagnostics(sa_x13) sa_ts <- rjd3tramoseats::tramoseats(y) sa_decomposition(sa_ts) # In a Quarto document, just write in a chunk: # sa_preprocessing(sa_x13, title_level = 3)y <- rjd3toolkit::ABS$X0.2.09.10.M sa_x13 <- rjd3x13::x13(y) sa_preprocessing(sa_x13) sa_decomposition(sa_x13) sa_diagnostics(sa_x13) sa_ts <- rjd3tramoseats::tramoseats(y) sa_decomposition(sa_ts) # In a Quarto document, just write in a chunk: # sa_preprocessing(sa_x13, title_level = 3)
sa_report() gathers, for one or several seasonal adjustment models, the description of the
pre-processing (sa_preprocessing()), of the decomposition (sa_decomposition()),
the diagnostics (sa_diagnostics()) and some plots.
In a Quarto (or R Markdown) document, the result is automatically rendered whatever the
output format.
render_report() directly renders a report in a file using a Quarto template
(see report_template()).
sa_report( x, preprocessing = TRUE, decomposition = TRUE, diagnostics = TRUE, plots = TRUE, title_level = 2, ... ) render_report( x, output_file, output_format = c("html", "pdf", "typst", "docx"), title = "Seasonal adjustment report", template = report_template(), preprocessing = TRUE, decomposition = TRUE, diagnostics = TRUE, plots = TRUE, title_level = 1, quiet = TRUE, ... )sa_report( x, preprocessing = TRUE, decomposition = TRUE, diagnostics = TRUE, plots = TRUE, title_level = 2, ... ) render_report( x, output_file, output_format = c("html", "pdf", "typst", "docx"), title = "Seasonal adjustment report", template = report_template(), preprocessing = TRUE, decomposition = TRUE, diagnostics = TRUE, plots = TRUE, title_level = 1, quiet = TRUE, ... )
x |
the model(s) to describe. It can be:
|
preprocessing, decomposition, diagnostics
|
booleans indicating which parts should be printed. |
plots |
boolean indicating if the plots (series and SI-ratios) should be printed. |
title_level |
level of the first headings. For a workspace, the multiprocessings are
printed with headings of level |
... |
other parameters passed to |
output_file |
the output file (e.g. |
output_format |
the Quarto output format: |
title |
the title of the report. |
template |
the Quarto template used to render the report (see |
quiet |
boolean indicating if the output of Quarto should be suppressed. |
sa_report() returns an object of class "rjd3report_block"
(see print.rjd3report_block()).
render_report() returns invisibly the path of the output file.
y <- rjd3toolkit::ABS$X0.2.09.10.M sa_x13 <- rjd3x13::x13(y) sa_ts <- rjd3tramoseats::tramoseats(y) # In a Quarto document: # sa_report(sa_x13) # sa_report(list(X13 = sa_x13, `TRAMO-SEATS` = sa_ts)) if (quarto::quarto_available()) { output_file <- tempfile(fileext = ".html") render_report(list(X13 = sa_x13, `TRAMO-SEATS` = sa_ts), output_file) # browseURL(output_file) # From a workspace ws <- system.file("workspaces", "workspace_test.xml", package = "rjd3workspace") output_file <- tempfile(fileext = ".pdf") render_report(ws, output_file, output_format = "typst") }y <- rjd3toolkit::ABS$X0.2.09.10.M sa_x13 <- rjd3x13::x13(y) sa_ts <- rjd3tramoseats::tramoseats(y) # In a Quarto document: # sa_report(sa_x13) # sa_report(list(X13 = sa_x13, `TRAMO-SEATS` = sa_ts)) if (quarto::quarto_available()) { output_file <- tempfile(fileext = ".html") render_report(list(X13 = sa_x13, `TRAMO-SEATS` = sa_ts), output_file) # browseURL(output_file) # From a workspace ws <- system.file("workspaces", "workspace_test.xml", package = "rjd3workspace") output_file <- tempfile(fileext = ".pdf") render_report(ws, output_file, output_format = "typst") }
sarima_orders() returns the SARIMA orders as a list while
sarima_orders_ch() returns a string.
sarima_orders(x, ...) sarima_orders_ch(x, ...)sarima_orders(x, ...) sarima_orders_ch(x, ...)
x |
The model. |
... |
Other unused parameters. |
y <- rjd3toolkit::ABS$X0.2.09.10.M mod <- rjd3toolkit::sarima_estimate(y, order = c(0,1,1), seasonal = c(0,1,1)) sarima_orders(mod) sarima_orders_ch(mod) mod_x13 <- rjd3x13::x13(y) sarima_orders_ch(mod_x13)y <- rjd3toolkit::ABS$X0.2.09.10.M mod <- rjd3toolkit::sarima_estimate(y, order = c(0,1,1), seasonal = c(0,1,1)) sarima_orders(mod) sarima_orders_ch(mod) mod_x13 <- rjd3x13::x13(y) sarima_orders_ch(mod_x13)
Function to compute the data to produce the Statistics Canada seasonal adjustment dashboard
sc_dashboard(x, n_recent_obs = 24, context = NULL)sc_dashboard(x, n_recent_obs = 24, context = NULL)
x |
A seasonal adjustment model. |
n_recent_obs |
number of observation in the recent history panel (see details). By default |
context |
Context used to estimate the model. |
sa_model() reproduces Statistics Canada dashboard used to provide a snapshot of an single seasonal adjustment model at a point in time and to point out some possible problems (see references).
The dashboard is divided into four sections:
Recent History (top left panel): plot of the raw series, the seasonal adjusted series and the trend for the most recent periods (n_recent_obs last observations: 24 by default). It is intended to identify trend direction, overall volatility and obvious outliers.
Summary of Key Diagnostics (top right panel):
Adjustability (only for X13 models): M7 statistic. Colors: red if M7 1.75, yellow if 1.25 M7 < 1.75 and green if M7 < 1.25.
Residual seasonality: qs (auto-correlations at seasonal lags) and f (Friedman) test on seasonal adjusted series. Colors: red if p-value 0.01, yellow if 0.01 < p-value 0.05 and green if p-value > 0.05.
Residual trading-days effects: f (Friedman) test on seasonal adjusted serie. Colors: red if p-value 0.01, yellow if 0.01 < p-value 0.05 and green if p-value > 0.05.
Independence of RegARIMA residuals: Ljung-Box test. Colors: red if p-value 0.01, yellow if 0.01 < p-value 0.05 and green if p-value > 0.05.
Recent outliers on last (t) and penultimate (t-1) observation. Colors: Red ("bad") if there is an extreme value (only for X13: when table C17 equals to 0), yellow ("uncertain") if there is an outlier in the RegARIMA model and green ("good") otherwise.
Estimated Patterns and Anticipated Movements (middle panel): estimated trading day, moving holiday and seasonal pattern. It presents expected movement in unadjusted series based on the current and previous period.
Net Effect of Seasonal Adjustment (bottom panel): movement in the raw series, compared to typical ranges centered around "neutral" value (when the seasonal adjusted series of the last period is equal to the penultimate period). It also shows the movement in the seasonally adjusted series, compared to typical ranges.
KIRCHNER R., LADIRAY D., MAZZI G. L. (2018), "Quality Measures and Reporting for Seasonal Adjustment", edited by G. L. Mazzi, co-edited by D. Ladiray, European Union, Luxembourg. https://ec.europa.eu/eurostat/web/products-manuals-and-guidelines/-/KS-GQ-18-001
MATTHEWS S. (2016), "Quality Assurance of Seasonal Adjustment for a Large System of Time Series", 36th International Symposium on Forecasting Santander, Spain.
data <- window(rjd3toolkit::ABS$X0.2.09.10.M, start = 2003) sa_model <- rjd3x13::x13(data) sc_dashboard_data <- sc_dashboard(sa_model) plot(sc_dashboard_data, main = "My first seasonal adjustment dashboard", subtitle = "SA with X13")data <- window(rjd3toolkit::ABS$X0.2.09.10.M, start = 2003) sa_model <- rjd3x13::x13(data) sc_dashboard_data <- sc_dashboard(sa_model) plot(sc_dashboard_data, main = "My first seasonal adjustment dashboard", subtitle = "SA with X13")
Functions to compute the data to produce a simple seasonal adjustment dashboard.
simple_dashboard2() is a shortcut of simple_dashboard(n_last_outliers = 4): the
description text is smaller to include a table with the last outliers.
The dashboard can be plotted with base R (plot.simple_dashboard()) or with ggplot2
(autoplot.simple_dashboard()).
simple_dashboard( x, context = NULL, digits = 2, scale_var_decomp = FALSE, remove_others_contrib = FALSE, add_obs_to_forecast = TRUE, td_effect = NULL, n_last_outliers = 0, digits_outliers = digits, columns_outliers = c("Estimate", "T-stat"), order_outliers = c("AO", "LS", "TC", "SO") ) simple_dashboard2(x, ..., n_last_outliers = 4)simple_dashboard( x, context = NULL, digits = 2, scale_var_decomp = FALSE, remove_others_contrib = FALSE, add_obs_to_forecast = TRUE, td_effect = NULL, n_last_outliers = 0, digits_outliers = digits, columns_outliers = c("Estimate", "T-stat"), order_outliers = c("AO", "LS", "TC", "SO") ) simple_dashboard2(x, ..., n_last_outliers = 4)
x |
A seasonal adjustment model. |
context |
Context used to estimate the model. |
digits |
Number of digits used in the tables (default value used by the plot functions). |
scale_var_decomp |
boolean indicating if the variance decomposition table should be rescaled to 100. |
remove_others_contrib |
boolean indication if the "Others" contribution (i.e.: the pre-adjustment contribution) should be removed from the variance decomposition table. |
add_obs_to_forecast |
Boolean indicating if the last observed values should be added to the forecast table (for the plot). |
td_effect |
Boolean indicating if the residual trading days effect test should be printed.
By default ( |
n_last_outliers |
number of last outliers to be printed (by default |
digits_outliers |
number of digits used in the table of outliers. |
columns_outliers |
informations about outliers that should be printed in the summary table.
Can be either a vector of characters among |
order_outliers |
order of the outliers in case of several outliers at the same date. |
... |
other parameters passed to |
The colors of the tables depend on the status of each statistic (see dashboard_colors()):
Q-statistics (X-13 only): "good" if lower than 1 and "bad" otherwise;
seasonality tests on the linearised series: "good" if the p-value is lower than 0.01
(seasonality detected), "uncertain" if it is between 0.01 and 0.05 and "bad" otherwise;
residual seasonality and residual trading days effects tests: "bad" if the p-value is lower than 0.01,
"uncertain" if it is between 0.01 and 0.05 and "good" otherwise.
For the combined seasonality tests, "Present" (seasonality detected) is "good" on the linearised
series and "bad" on the seasonally adjusted series.
data <- window(rjd3toolkit::ABS$X0.2.09.10.M, start = 2003) sa_model <- rjd3x13::x13(data) dashboard_data <- simple_dashboard(sa_model) plot(dashboard_data, main = "Simple dashboard") dashboard_data2 <- simple_dashboard2(sa_model) plot(dashboard_data2, main = "Simple dashboard with outliers") # With ggplot2 autoplot(dashboard_data2, main = "Simple dashboard with outliers")data <- window(rjd3toolkit::ABS$X0.2.09.10.M, start = 2003) sa_model <- rjd3x13::x13(data) dashboard_data <- simple_dashboard(sa_model) plot(dashboard_data, main = "Simple dashboard") dashboard_data2 <- simple_dashboard2(sa_model) plot(dashboard_data2, main = "Simple dashboard with outliers") # With ggplot2 autoplot(dashboard_data2, main = "Simple dashboard with outliers")