The functions developped in rjdmarkdown are:

The result is different between X-13ARIMA and TRAMO-SEATS models.

library(rjdmarkdown)
library(RJDemetra)
sa_x13 <- x13(ipi_c_eu[, "FR"])
sa_ts <- tramoseats(ipi_c_eu[, "FR"])

X-13-ARIMA model

Pre-processing (RegArima)

Summary

360 observations

Series has been log-transformed

Trading days effect (6 variables)

Easter [1] detected

3 detected outliers

Likelihood statistics

Number of effective observations = 347

Number of estimated parameters = 15

Loglikelihood = 853.667, AICc = 1529.651, BICc = -7.547

Standard error of the regression (ML estimate) = 0.020

ARIMA model

ARIMA coefficients
Coefficients Std. Error T-stat P (> | t|)
Phi(1) 0.026 0.118 0.218 0.827
Phi(2) 0.159 0.078 2.039 0.042
Theta(1) -0.517 0.113 -4.589 0.000 ***
BTheta(1) -0.703 0.041 -17.093 0.000 ***
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ’ ’ 1
ARIMA (2,1,1)(0,1,1)

Regression model

Regression coefficientss
Coefficients Std. Error T-stat P (> | t|)
Monday 0.005 0.002 2.309 0.022
Tuesday 0.008 0.002 3.895 0.000 ***
Wednesday 0.011 0.002 4.903 0.000 ***
Thursday 0.002 0.002 0.955 0.340
Friday 0.008 0.002 3.826 0.000 ***
Saturday -0.016 0.002 -7.599 0.000 ***
Easter [1] -0.021 0.004 -4.979 0.000 ***
AO (5-2011) 0.128 0.017 7.447 0.000 ***
LS (11-2008) -0.087 0.017 -5.131 0.000 ***
LS (1-2009) -0.068 0.017 -4.037 0.000 ***
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ’ ’ 1
print_decomposition(sa_x13, caption = NULL)

Decomposition (X-11)

Mode: multiplicative

S-I Ratio

S-I Ratio

M-statistics
Value Description
M-1 0.097 The relative contribution of the irregular over three months span
M-2 0.053 The relative contribution of the irregular component to the stationary portion of the variance
M-3 0.995 The amount of period to period change in the irregular component as compared to the amount of period to period change in the trend
M-4 0.421 The amount of autocorrelation in the irregular as described by the average duration of run
M-5 0.950 The number of periods it takes the change in the trend to surpass the amount of change in the irregular
M-6 0.154 The amount of year to year change in the irregular as compared to the amount of year to year change in the seasonal
M-7 0.074 The amount of moving seasonality present relative to the amount of stable seasonality
M-8 0.211 The size of the fluctuations in the seasonal component throughout the whole series
M-9 0.064 The average linear movement in the seasonal component throughout the whole series
M-10 0.267 The size of the fluctuations in the seasonal component in the recent years
M-11 0.250 The average linear movement in the seasonal component in the recent years
Q 0.322
Q-M2 0.355
Final filters: M3x5, Henderson-13 terms
Relative contribution of the components to the stationary portion of the variance in the original series, after the removal of the long term trend
Component
Cycle 1.941
Seasonal 62.123
Irregular 0.842
TD & Hol. 2.428
Others 32.787
Total 100.121
Diagnostics tests
P (> | t|)
mean 0.797
skewness 0.383
kurtosis 0.409
ljung box 0.000 ***
ljung box (residuals at seasonal lags) 0.199
ljung box (squared residuals) 0.802
qs test on sa 0.909
qs test on i 0.746
f-test on sa (seasonal dummies) 0.974
f-test on i (seasonal dummies) 0.947
Residual seasonality (entire series) 0.932
Residual seasonality (last 3 years) 0.940
f-test on sa (td) 0.985
f-test on i (td) 0.983
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ’ ’ 1

TRAMO-SEATS model

Some others graphics can also be added with the ggdemetra package, for example to add the seasonally adjusted series and its forecasts:

library(ggdemetra)
ggplot(data = ipi_c_eu_df, mapping = aes(x = date, y = FR)) +
    geom_line() +
    labs(title = NULL,
         x = NULL, y = NULL) +
    geom_sa(component = "y_f", linetype = 2,
            frequency = 12, method = "tramoseats") +
    geom_sa(component = "sa", color = "red") +
    geom_sa(component = "sa_f", color = "red", linetype = 2)
Seasonal adjustment of the French industrial production index

Seasonal adjustment of the French industrial production index

Pre-processing (Tramo)

Summary

360 observations

Series has been log-transformed

Trading days effect (2 variables)

Easter [6] detected

2 detected outliers

Likelihood statistics

Number of effective observations = 347

Number of estimated parameters = 9

Loglikelihood = 831.828, AICc = 1560.412, BICc = -7.523

Standard error of the regression (ML estimate) = 0.022

ARIMA model

ARIMA coefficients
Coefficients Std. Error T-stat P (> | t|)
Phi(1) 0.386 0.053 7.287 0.000 ***
Phi(2) 0.243 0.053 4.579 0.000 ***
BTheta(1) -0.713 0.040 -17.672 0.000 ***
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ’ ’ 1
ARIMA (2,1,0)(0,1,1)

Regression model

Regression coefficientss
Coefficients Std. Error T-stat P (> | t|)
Week days 0.007 0.000 23.891 0.000 ***
Leap year 0.022 0.007 3.238 0.001 **
Easter [6] -0.021 0.004 -5.118 0.000 ***
AO (5-2011) 0.129 0.017 7.640 0.000 ***
AO (5-2000) 0.058 0.017 3.409 0.001 ***
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ’ ’ 1
print_decomposition(sa_ts, caption = NULL)

Decomposition (SEATS)

Mode: multiplicative

S-I Ratio

S-I Ratio

Model

AR: \(1+0.386B+0.243B^{2}\)

D: \(1-B-B^{12}+B^{13}\)

MA: \(1-0.713B^{12}\)

SA

AR: \(1+0.386B+0.243B^{2}\)

D: \(1-2.000B+B^{2}\)

MA: \(1-0.975B+0.004B^{2}-0.003B^{3}+0.002B^{4}\)

Innovation variance: 0.747

Trend

D: \(1-2.000B+B^{2}\)

MA: \(1+0.028B-0.972B^{2}\)

Innovation variance: 0.070

Seasonal

D: \(1+B+B^{2}+B^{3}+B^{4}+B^{5}+B^{6}+B^{7}+B^{8}+B^{9}+B^{10}+B^{11}\)

MA: \(1+1.353B+1.194B^{2}+1.260B^{3}+1.124B^{4}+0.886B^{5}+0.683B^{6}+0.440B^{7}+0.272B^{8}+0.020B^{9}-0.055B^{10}-0.222B^{11}\)

Innovation variance: 0.030

Transitory

AR: \(1+0.386B+0.243B^{2}\)

MA: \(1-0.316B-0.684B^{2}\)

Innovation variance: 0.052

Irregular

Innovation variance: 0.222

Relative contribution of the components to the stationary portion of the variance in the original series, after the removal of the long term trend
Component
Cycle 5.694
Seasonal 88.840
Irregular 0.820
TD & Hol. 3.412
Others 0.469
Total 99.234
Diagnostics tests
P (> | t|)
mean 0.933
skewness 0.323
kurtosis 0.237
ljung box 0.001 ***
ljung box (residuals at seasonal lags) 0.197
ljung box (squared residuals) 0.002 **
qs test on sa 1.000
qs test on i 1.000
f-test on sa (seasonal dummies) 1.000
f-test on i (seasonal dummies) 1.000
Residual seasonality (entire series) 1.000
Residual seasonality (last 3 years) 0.984
f-test on sa (td) 0.135
f-test on i (td) 0.256
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ’ ’ 1

Directly create a R Markdown file

A R Markdown can also directly be created and render with the create_rmd function. It can take as argument a SA, jSA, sa_item, multiprocessing (all the models of the multiprocessing are printed) or workspace object (all the models of all the multiprocessing of the workspace are printed).

The print of the pre-processing, decomposition and diagnostics can also be customized with preprocessing_fun, decomposition_fun and diagnostics_fun arguments. For example, to reproduce the example of the previous section:

preprocessing_customized <- function(x){
  library(ggdemetra)
  y <- get_ts(x)
  data_plot <- data.frame(date = time(y), y = y)
  p <- ggplot(data = data_plot, mapping = aes(x = date, y = y)) +
    geom_line() +
    labs(title = NULL,
         x = NULL, y = NULL) +
    geom_sa(component = "y_f", linetype = 2,
            frequency = 12, method = "tramoseats") +
    geom_sa(component = "sa", color = "red") +
    geom_sa(component = "sa_f", color = "red", linetype = 2)
  plot(p)
  cat("\n\n")
  print_preprocessing(sa_ts)
}
decomposition_customized <- function(x){
  print_decomposition(x, caption = NULL)
}

output_file <- tempfile(fileext = ".Rmd")

create_rmd(sa_ts, output_file, output_format = "html_document",
           preprocessing_fun = preprocessing_customized,
           decomposition_fun = decomposition_customized,
           knitr_chunk_opts = list(
             fig.pos = "h", results = "asis",
             fig.cap =c("Seasonal adjustment of the French industrial production index",
                        "S-I Ratio"),
             warning = FALSE, message = FALSE, echo = FALSE)
)
# To open the file:
browseURL(sub(".Rmd",".html", output_file, fixed= TRUE))

Several models can also be printed creating a workspace:

wk <- new_workspace()
new_multiprocessing(wk, "sa1")
add_sa_item(wk, "sa1", sa_x13, "X13")
add_sa_item(wk, "sa1", sa_ts, "TramoSeats")
# It's important to compute the workspace to be able to import the models
compute(wk)

output_file <- tempfile(fileext = ".Rmd")
create_rmd(wk, output_file, output_format = "html_document",
           output_options = list(toc = TRUE,
                                 number_sections = TRUE))
# To open the file:
browseURL(sub(".Rmd",".html", output_file, fixed= TRUE))

Reproductibility

To produce this document, the knitr options were set as followed:

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>", out.width = "100%",
  fig.dim = c(7, 5),
  warning = FALSE, message = FALSE
)

And the options results='asis', fig.cap = "S-I Ratio" were used in the chunks.