knitr::opts_chunk$set(
  echo = TRUE, size = "small"
)
library("JDCruncheR")
library("kableExtra")
library("knitr")

With the current version of the JDCruncheR package (r utils::packageVersion("JDCruncheR")), you can:

About the cruncher

To prevent the package from being too voluminous, it does not contain the JDemetra+ cruncher. Said cruncher can be downloaded here: https://github.com/jdemetra/jdemetra-app/releases. For more information on the cruncher installation and its set up with a portable version of Java, please refer to the JDCruncheR wiki: https://github.com/InseeFr/JDCruncheR/wiki/Installation-&-configuration.

The JDemetra+ cruncher requires three elements to function:

In the JDCruncheR package, three functions are cruncher-related:

Generating the settings file with create_param_file()

The arguments of the function create_param_file() are described in the JDemetra+ cruncher wiki (https://github.com/jdemetra/jwsacruncher/wiki). The three main arguments are:

  1. policy, the refresh policy:
refresh_policy <- structure(list(`Option in JDemetra+` = c("Current adjustment (AO approach)",
"Fixed model", 
"Estimate regression coefficients", 
"Estimate regression coefficients + Arima parameters", 
"Estimate regression coefficients + Last outliers", 
"Estimate regression coefficients + All outliers", 
"Estimate regression coefficients + Arima model", 
"Concurrent"), 
`Cruncher options` = c("current", "fixed", "fixedparameters", "parameters (default policy)", "lastoutliers", "outliers", 
"stochastic", "complete or concurrent"), 
Description = c("The ARIMA model, outliers and other regression variables are not re-identified, and the values of all associated coefficients are fixed. All new observations are classified as additive outliers and corresponding coefficients are estimated during the regression phase. The transformation type remains unchanged.",
"The ARIMA model, outliers and other regression variables are not re-identified and the values of all coefficients are fixed. The transformation type remains unchanged.", 
"The ARIMA model, outliers and other regression variables are not re-identified. The coefficients of the ARIMA model are fixed but the regression variables coefficients are re-estimated. The transformation type remains unchanged.", 
"The ARIMA model, outliers and other regression variables are not re-identified. All coefficients of the RegARIMA model are re-estimated, for regression variables and ARIMA parameters. The transformation type remains unchanged.", 
"Outliers in the last year of the sample are re-identified. All coefficients of the RegARIMA model, regression variables and ARIMA parameters, are re-estimated. The transformation type remains unchanged.", 
"All outliers are re-identified. All coefficients of the RegARIMA model, regression variables and ARIMA parameters, are re-estimated. The transformation type remains unchanged.",
"Re-identification of the ARIMA model, outliers and regression variables, except the calendar variables. The transformation type remains unchanged.", 
"Complete re-identification of the whole RegARIMA model, all regression variables and ARIMA model orders.")), 
.Names = c("Option in JDemetra+", "Cruncher option", "Description"), class = "data.frame", row.names = c(NA, -7L))

kable(refresh_policy, caption = "The refresh/revision policies",
      booktabs = TRUE, format = "latex") %>% 
    kable_styling(full_width = T,
                  latex_options = "hold_position") %>% 
    group_rows("Current adjustment (AO approach)", 1, 1) %>% 
    group_rows("Partial concurrent adjustment", 2, 7) %>% 
    group_rows("Concurrent", 8, 8) %>% 
    column_spec(1, width = "4cm") %>% 
    column_spec(2, width = "2.5cm")

\begin{table}[!h]

\caption{\label{tab:unnamed-chunk-1}The refresh policies} \centering \begin{tabu} to \linewidth {>{\raggedright\arraybackslash}p{4cm}>{\raggedright\arraybackslash}p{2.5cm}>{\raggedright}X} \toprule Option in JDemetra+ & Cruncher option & Description\ \midrule \addlinespace[0.3em] \hspace{1em}Current adjustment (AO approach) & current & The ARIMA model, outliers and other regression variables are not re-identified, and the values of all associated coefficients are fixed. All new observations are classified as additive outliers and corresponding coefficients are estimated during the regression phase. The transformation type remains unchanged..\ \multicolumn{3}{l}{\textbf{Partial concurrent adjustment}}\ \hspace{1em}Fixed model & fixed & The ARIMA model, outliers and other regression variables are not re-identified and the values of all coefficients are fixed. The transformation type remains unchanged.\ \hspace{1em}Estimate regression coefficients & fixedparameters & The ARIMA model, outliers and other regression variables are not re-identified. The coefficients of the ARIMA model are fixed but the regression variables coefficients are re-estimated. The transformation type remains unchanged.\ \hspace{1em}Estimate regression coefficients + Arima parameters & parameters (default policy) & The ARIMA model, outliers and other regression variables are not re-identified. All coefficients of the RegARIMA model are re-estimated, for regression variables and ARIMA parameters. The transformation type remains unchanged.\ \hspace{1em}Estimate regression coefficients + Last outliers & lastoutliers & Outliers in the last year of the sample are re-identified. All coefficients of the RegARIMA model, regression variables and ARIMA parameters, are re-estimated. The transformation type remains unchanged.\ \hspace{1em}Estimate regression coefficients + all outliers & outliers & All outliers are re-identified. All coefficients of the RegARIMA model, regression variables and ARIMA parameters, are re-estimated. The transformation type remains unchanged.\ \hspace{1em}Estimate regression coefficients + Arima model & stochastic & Re-identification of the ARIMA model, outliers and regression variables, except the calendar variables. The transformation type remains unchanged.\ \addlinespace[0.3em] \multicolumn{3}{l}{\textbf{Concurrent}}\ \hspace{1em}Concurrent & complete or concurrent & Complete re-identification of the whole RegARIMA model, all regression variables and ARIMA model orders.\ \bottomrule \end{tabu} \end{table}

  1. matrix_item, a list containing the names of the parameters to export. By default, such names are those contained in the default_matrix_item option. Thus, the user can either modify the default_matrix_item option or the matrix_item option:
library("JDCruncheR")
# To see the default parameters:
getOption("default_matrix_item")
# To customise the parameter selection (here, only the information criteria are exported):
options(default_matrix_item = c("likelihood.aic",
                                "likelihood.aicc",
                                "likelihood.bic",
                                "likelihood.bicc"))
  1. tsmatrix_series, a list containing the names of the parameters to export. By default, such names are those contained in the default_tsmatrix_series option. Thus, the user can either modify the default_tsmatrix_series option or the tsmatrix_series option:
# To see the default parameters:
getOption("default_tsmatrix_series")
# To customise the parameter selection (here, only the seasonaly adjusted series and its previsions are exported):
options(default_tsmatrix_series = c("sa", "sa_f"))

To visualise all parameters that can be used to customise these options, enter ?create_param_file (in R).

Here are some use cases for the function create_param_file():

# A .param parameters file will be created in D:/, containing the "lastoutliers" refresh policy 
# and default values for the other parameters 
create_param_file(dir_file_param = "D:/",
                  policy = "lastoutliers")

# To customise the "default_matrix_item" and "default_tsmatrix_series" options 
# to only export the information criteria, the adjusted series and its forecast:
create_param_file(dir_file_param = "D:/",
                  policy = "lastoutliers",
                  matrix_item = c("likelihood.aic", "likelihood.aicc",
                                  "likelihood.bic", "likelihood.bicc"),
                  tsmatrix_series = c("sa", "sa_f"))

Launching the cruncher

To crunch a workspace with the functions cruncher() or cruncher_and_param(), the paths to the cruncher and the workspace must be specified via two parameters, cruncher_bin_directory and workspace.

Once declared, the path to the cruncher (stored in the parameter cruncher_bin_directory) is valid for all cruncher executions. The path must refer to the jwsacruncher.bat file location, within the "bin" installation folder. For example, if the cruncher is installed in D:\jdemetra-cli-2.2.3, the jwsacruncher.bat file will be in D:\jdemetra-cli-2.2.3\bin. The code to declare this path via the cruncher_bin_directory parameter is:

options(cruncher_bin_directory = "D:/jdemetra-cli-2.2.3/bin/")

If no path to a workspace was specified, a window opens for a manual workspace selection.

The function cruncher_and_param() creates a temporary parameters file by calling create_param_file(), which is then used to by the function cruncher() to crunch the workspace. In addition to the parameters used by these two functions, cruncher_and_param() carries the option rename_multi_documents with which the output folders can be renamed after the SAProcessings' names as displayed in the JDemetra+ interface (by default, rename_multi_documents = TRUE: the output files are renamed). Here are some use cases:

# Code to update the "ipi" workspace stored in D:/seasonal_adjustment/, with the refresh policy "lastoutliers".
# All other create_param_file() parameters are default ones. In particular, the exported parameters are the default 
# "default_matrix_item" and "default_tsmatrix_series", and the output folder is D:/seasonal_adjustment/Output/.
cruncher_and_param(workspace = "D:/seasonal_adjustment/ipi.xml",
                   rename_multi_documents = FALSE,
                   policy = "lastoutliers")

# Example of customisation of the parameter "output":
cruncher_and_param(workspace = "D:/seasonal_adjustment/ipi.xml",
                   output = "D:/cruncher_results/",
                   rename_multi_documents = FALSE,
                   policy = "lastoutliers")

# Here, we explicitely have "rename_multi_documents = TRUE" (which is also the default value) to rename the ouput folders 
# after the SAProcessings as displayed in the JDemetra+ interface. 
# With parameter "delete_existing_file = TRUE", all pre-existing versions of such folders are deleted before the export.
cruncher_and_param(workspace = "D:/Campagne_CVS/ipi.xml",
                   rename_multi_documents = TRUE,
                   delete_existing_file = TRUE,
                   policy = "lastoutliers")

# To see all the function parameters:
?cruncher_and_param


AQLT/JDCruncheR documentation built on March 20, 2024, 2:32 p.m.