diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf..931662b 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,3 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +^README\.Rmd$ diff --git a/DESCRIPTION b/DESCRIPTION index 2a8dba8..e888a9b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rjd3x13 Type: Package Title: Seasonal Adjustment with X-13 and 'JDemetra+ 3.0' -Version: 3.0.0 +Version: 3.1.0 Authors@R: c( person("Jean", "Palate", role = c("aut", "cre"), email = "jean.palate@nbb.be"), @@ -15,7 +15,7 @@ Depends: R (>= 3.6.0) Imports: rJava (>= 1.0-6), - rjd3toolkit (>= 3.0.0), + rjd3toolkit (>= 3.1.0), RProtoBuf (>= 0.4.17) SystemRequirements: Java (>= 17) License: EUPL @@ -25,14 +25,16 @@ Roxygen: list(markdown = TRUE) BugReports: https://github.com/rjdemetra/rjd3x13/issues Encoding: UTF-8 Collate: + 'deprecated.R' 'print.R' 'regarima_generic.R' 'utils.R' 'regarima_outliers.R' 'regarima_spec.R' - 'set_x11_spec.R' - 'udvar.R' 'x13_rslts.R' 'x13_spec.R' + 'revisions.R' + 'set_x11_spec.R' + 'udvar.R' 'x13.R' 'zzz.R' diff --git a/NAMESPACE b/NAMESPACE index 6221f30..cb7881c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,8 +27,8 @@ S3method(remove_outlier,JD3_X13_SPEC) S3method(remove_ramp,JD3_X13_SPEC) S3method(residuals,JD3_REGARIMA_OUTPUT) S3method(residuals,JD3_X13_OUTPUT) -S3method(sa.decomposition,JD3_X13_OUTPUT) -S3method(sa.decomposition,JD3_X13_RSLTS) +S3method(sa_decomposition,JD3_X13_OUTPUT) +S3method(sa_decomposition,JD3_X13_RSLTS) S3method(set_arima,JD3_X13_SPEC) S3method(set_automodel,JD3_X13_SPEC) S3method(set_basic,JD3_X13_SPEC) @@ -52,16 +52,23 @@ export(fast_regarima) export(fast_x13) export(jx13) export(regarima) +export(regarima_fast) export(regarima_outliers) export(regarima_refresh) +export(regarima_spec) export(set_x11) export(spec_regarima) export(spec_x11) export(spec_x13) export(userdefined_variables_x13) export(x11) +export(x11_spec) export(x13) +export(x13_dictionary) +export(x13_fast) export(x13_refresh) +export(x13_revisions) +export(x13_spec) import(RProtoBuf) import(rjd3toolkit) importFrom(RProtoBuf,readProtoFiles2) @@ -83,7 +90,7 @@ importFrom(rjd3toolkit,add_usrdefvar) importFrom(rjd3toolkit,diagnostics) importFrom(rjd3toolkit,remove_outlier) importFrom(rjd3toolkit,remove_ramp) -importFrom(rjd3toolkit,sa.decomposition) +importFrom(rjd3toolkit,sa_decomposition) importFrom(rjd3toolkit,set_arima) importFrom(rjd3toolkit,set_automodel) importFrom(rjd3toolkit,set_basic) diff --git a/R/deprecated.R b/R/deprecated.R new file mode 100644 index 0000000..aa95ea6 --- /dev/null +++ b/R/deprecated.R @@ -0,0 +1,34 @@ +#' Deprecated functions +#' +#' +#' @param ts,spec,context,userdefined,name Parameters. +#' @name deprecated-rjd3x13 +#' @export +spec_x13<-function(name = c("rsa4","rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c")){ + .Deprecated("x13_spec") + x13_spec(name) +} +#' @name deprecated-rjd3x13 +#' @export +spec_regarima<-function(name=c("rg4","rg0", "rg1", "rg2c", "rg3", "rg5c")){ + .Deprecated("regarima_spec") + regarima_spec(name) +} +#' @name deprecated-rjd3x13 +#' @export +spec_x11 <- function() { + .Deprecated("x11_spec") + x11_spec() +} +#' @name deprecated-rjd3x13 +#' @export +fast_x13<-function(ts, spec=c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c"), context=NULL, userdefined = NULL){ + .Deprecated("x13_fast") + x13_fast(ts, spec, context, userdefined) +} +#' @name deprecated-rjd3x13 +#' @export +fast_regarima<-function(ts, spec= c("rg4", "rg0", "rg1", "rg2c", "rg3","rg5c"), context=NULL, userdefined = NULL){ + .Deprecated("regarima_fast") + regarima_fast(ts, spec, context, userdefined) +} diff --git a/R/print.R b/R/print.R index 83100f8..e76ddcd 100644 --- a/R/print.R +++ b/R/print.R @@ -19,7 +19,7 @@ print_diagnostics <- function(x, digits = max(3L, getOption("digits") - 3L), ...){ diagnostics = rjd3toolkit::diagnostics(x) variance_decomposition = diagnostics$variance_decomposition - residuals_test = diagnostics$residuals_test + residual_tests = diagnostics$residual_tests cat("Relative contribution of the components to the stationary", "portion of the variance in the original series,", @@ -38,7 +38,7 @@ print_diagnostics <- function(x, digits = max(3L, getOption("digits") - 3L), cat("\n") cat(paste0(" ", capture.output( - printCoefmat(residuals_test[,"P.value", drop = FALSE], digits = digits, + printCoefmat(residual_tests[,"P.value", drop = FALSE], digits = digits, na.print = "NA", ...) ) ), @@ -48,7 +48,7 @@ print_diagnostics <- function(x, digits = max(3L, getOption("digits") - 3L), return(invisible(x)) } print_final <- function(x, ...){ - print(rjd3toolkit::sa.decomposition(x), ...) + print(rjd3toolkit::sa_decomposition(x), ...) return(invisible(x)) } @@ -203,11 +203,11 @@ print.JD3_X11_SPEC <- function(x, ...) { #' @export print.JD3_X13_SPEC <- function(x, ...) { - print(x$regarima, enable_print_style = enable_print_style) + print(x$regarima) cat("\n") - print(x$x11, enable_print_style = enable_print_style) + print(x$x11) cat("\n", "Benchmarking", "\n", sep = "") @@ -248,11 +248,11 @@ print.JD3_X13_OUTPUT<- function(x, digits = max(3L, getOption("digits") - 3L), } #' @export -print.JD3X11 <- function(x) { +print.JD3X11 <- function(x, ...) { table <- do.call(cbind, x[grepl(pattern = "^d(\\d+)$", x = names(x))]) cat("Last values\n") - print(tail(.preformat.ts(table))) + print(utils::tail(stats::.preformat.ts(table))) return(invisible(x)) } @@ -266,7 +266,7 @@ plot.JD3_X13_RSLTS <- function(x, first_date = NULL, last_date = NULL, colors = c(y = "#F0B400", t = "#1E6C0B", sa = "#155692", s = "#1E6C0B", i = "#155692"), ...){ - plot(rjd3toolkit::sa.decomposition(x), + plot(rjd3toolkit::sa_decomposition(x), first_date = first_date, last_date = last_date, type_chart = type_chart, caption = caption, @@ -297,12 +297,13 @@ diagnostics.JD3_X13_RSLTS<-function(x, ...){ variance_decomposition = matrix(unlist(variance_decomposition), ncol = 1, dimnames = list(names(variance_decomposition), "Component")) - residuals_test = x$diagnostics[grep("test", names(x$diagnostics))] - residuals_test = data.frame(Statistic = sapply(residuals_test, function(test) test[["value"]]), - P.value = sapply(residuals_test, function(test) test[["pvalue"]]), - Description = sapply(residuals_test, function(test) attr(test, "distribution"))) - list(variance_decomposition = variance_decomposition, - residuals_test = residuals_test) + residual_tests = x$diagnostics[grep("test", names(x$diagnostics))] + residual_tests = data.frame(Statistic = sapply(residual_tests, function(test) test[["value"]]), + P.value = sapply(residual_tests, function(test) test[["pvalue"]]), + Description = sapply(residual_tests, function(test) attr(test, "distribution"))) + list(preprocessing = rjd3toolkit::diagnostics(x$preprocessing), + variance_decomposition = variance_decomposition, + residual_tests = residual_tests) } #' @export diff --git a/R/regarima_outliers.R b/R/regarima_outliers.R index f73fc45..8627afe 100644 --- a/R/regarima_outliers.R +++ b/R/regarima_outliers.R @@ -33,7 +33,7 @@ regarima_outliers<-function(y, order=c(0L,1L,1L), seasonal=c(0L,1L,1L), mean=F, jregarima<-.jcall("jdplus/x13/base/r/RegArimaOutliersDetection", "Ljdplus/x13/base/r/RegArimaOutliersDetection$Results;", "process", - rjd3toolkit::.r2jd_ts(y), as.integer(order), as.integer(seasonal), mean, rjd3toolkit::.r2jd_matrix(X), + rjd3toolkit::.r2jd_tsdata(y), as.integer(order), as.integer(seasonal), mean, rjd3toolkit::.r2jd_matrix(X), ao, ls, tc, so, cv, clean) model<-list( y=rjd3toolkit::.proc_ts(jregarima, "y"), diff --git a/R/revisions.R b/R/revisions.R new file mode 100644 index 0000000..8570b13 --- /dev/null +++ b/R/revisions.R @@ -0,0 +1,92 @@ +#' @include utils.R x13_spec.R x13_rslts.R +NULL + +.jrevisions<-function(jts, jspec, jcontext){ + jrslt<-.jcall("jdplus/x13/base/r/X13RevisionHistory", + "Ljdplus/toolkit/base/r/timeseries/Revisions;", "revisions", jts, jspec, jcontext) + return (jrslt) +} + + +#' Revisions History +#' +#' Compute revisions history +#' +#' @param ts The time series used for the estimation. +#' @param spec The specification used. +#' @param data_ids A `list` of `list` to specify the statistics to export. +#' Each sub-list must contain two elements: +#' `start` (first date to compute the history, in the format `"YYYY-MM-DD"`) +#' and `id` (the name of the statistics, see [x13_dictionary()]). +#' See example. +#' @param ts_ids A `list` of `list` to specify the specific date of a component whose history is to be studied. +#' Each sub-list must contain three elements: +#' `start` (first date to compute the history, in the format `"YYYY-MM-DD"`), +#' `period` (the date of the studied) +#' and `id` (the name of the component, see [x13_dictionary()]). +#' See example. +#' @param cmp_ids A `list` of `list` to specify the component whose history is to be studied. +#' Each sub-list must contain three elements: +#' `start` (first date to compute the history, in the format `"YYYY-MM-DD"`), +#' `end` (last date to compute the history, in the format `"YYYY-MM-DD"`) +#' and `id` (the name of the component, see [x13_dictionary()]). +#' As many series as periods between `start` and `end` will be exported. +#' See example. +#' @param context The context of the specification. +#' +#' @examples +#' s <- rjd3toolkit::ABS$X0.2.09.10.M +#' sa_mod <- x13(s) +#' data_ids <- list( +#' # Get the coefficient of the trading-day coefficient from 2005-jan +#' list(start = "2005-01-01", id = "regression.td(1)"), +#' # Get the ljung-box statistics on residuals from 2010-jan +#' list(start = "2010-01-01", id = "residuals.lb")) +#' ts_ids <- list( +#' # Get the SA component estimates of 2010-jan from 2010-jan +#' list(period = "2010-01-01", start = "2010-01-01", id = "sa"), +#' # Get the irregular component estimates of 2010-jan from 2015-jan +#' list(period = "2010-01-01", start = "2015-01-01", id = "i")) +#' cmp_ids <- list( +#' # Get the SA component estimates (full time series) 2010-jan to 2020-jan +#' list(start = "2010-01-01", end = "2020-01-01", id = "sa"), +#' # Get the trend component estimates (full time series) 2010-jan to 2020-jan +#' list(start = "2010-01-01", end = "2020-01-01", id = "t")) +#' rh <- x13_revisions(s, sa_mod$result_spec, data_ids, ts_ids, cmp_ids) +#' @export +x13_revisions<-function(ts, spec, data_ids=NULL, ts_ids=NULL, cmp_ids=NULL, context=NULL){ + jts<-rjd3toolkit::.r2jd_tsdata(ts) + jspec<-.r2jd_spec_x13(spec) + if (is.null(context)){ + jcontext <- .jnull("jdplus/toolkit/base/api/timeseries/regression/ModellingContext") + } else { + jcontext <- rjd3toolkit::.r2jd_modellingcontext(context) + } + ldata<-NULL + jr<-.jrevisions(jts, jspec, jcontext) + if (! is.null(data_ids)){ + ldata<-lapply(data_ids, function(data_id){ + w<-.jcall(jr, "Ljdplus/toolkit/base/api/timeseries/TsData;", "history", data_id$id, data_id$start) + return (rjd3toolkit::.jd2r_tsdata(w)) + }) + names(ldata) <- sapply(data_ids, `[[`,"id") + } + lts<-NULL + if (! is.null(ts_ids)){ + lts<-lapply(ts_ids, function(ts_id){ + w<-.jcall(jr, "Ljdplus/toolkit/base/api/timeseries/TsData;", "tsHistory", ts_id$id, ts_id$period, ts_id$start) + return (rjd3toolkit::.jd2r_tsdata(w)) + }) + names(lts) <- sapply(ts_ids, `[[`,"id") + } + lcmp<-NULL + if (! is.null(cmp_ids)){ + lcmp<-lapply(cmp_ids, function(cmp_id){ + w<-.jcall(jr, "Ljdplus/toolkit/base/api/timeseries/TsDataTable;", "tsSelect", cmp_id$id, cmp_id$start, cmp_id$end) + return (rjd3toolkit::.jd2r_mts(w)) + }) + names(lcmp) <- sapply(cmp_ids, `[[`,"id") + } + + return (list(data=ldata, series=lts, components=lcmp)) +} diff --git a/R/set_x11_spec.R b/R/set_x11_spec.R index 28c8324..44e6d81 100644 --- a/R/set_x11_spec.R +++ b/R/set_x11_spec.R @@ -1,7 +1,7 @@ #' Set X-11 Specification #' -#' @param x the specification to be modified, object of class "JD3_X11_SPEC", default X11 spec can be obtained as 'x=spec_x11()' +#' @param x the specification to be modified, object of class "JD3_X11_SPEC", default X11 spec can be obtained as 'x=x11_spec()' #' @param mode character: the decomposition mode. Determines the mode of the seasonal adjustment decomposition to be performed: #' `"Undefined"` - no assumption concerning the relationship between the time series components is made; #' `"Additive"` - assumes an additive relationship; @@ -32,9 +32,10 @@ #' detection and adjustment will be computed separately. Only used if `calendar.sigma = "Select"`. Possible values are: `1` or `2`. #' @param exclude.forecast Boolean to exclude forecasts and backcasts. If `TRUE`, the RegARIMA model forecasts and backcasts are not used during the detection of extreme values in the seasonal adjustment routines.Default= FALSE. #' @param bias TODO. -#' @return a "JD3_X11_SPEC" object, containing all the parameters +#' @return a "JD3_X11_SPEC" object, containing all the parameters. +#' @seealso [x13_spec()] and [x11_spec()]. #' @examples -#' init_spec <- spec_x11() +#' init_spec <- x11_spec() #' new_spec <- set_x11(init_spec, #' mode = "LogAdditive", #' seasonal.comp = 1, @@ -48,7 +49,7 @@ #' sigma.vector = NA, #' exclude.forecast = FALSE, #' bias = "LEGACY") -#' @rdname spec_x11 +#' @rdname x11_spec #' @export set_x11 <- function(x, mode = c(NA, "Undefined", "Additive", "Multiplicative", "LogAdditive", "PseudoAdditive"), diff --git a/R/udvar.R b/R/udvar.R index 174e2bd..7dfb64b 100644 --- a/R/udvar.R +++ b/R/udvar.R @@ -42,7 +42,7 @@ userdefined_variables_x13 <- function(x = c("X-13","RegArima","X-11")){ choices = c("x13", "regarima", "x11")) # library(rjd3x13) - # jts<-rjd3toolkit::.r2jd_ts(rjd3toolkit::ABS$X0.2.09.10.M) + # jts<-rjd3toolkit::.r2jd_tsdata(rjd3toolkit::ABS$X0.2.09.10.M) # jrslt<- rJava::.jcall("jdplus/x13/base/r/X13", "Ljdplus/x13/base/core/x13/X13Output;", "fullProcess", jts, "RSA3") # rjd3toolkit::dictionary(rjd3toolkit::.jd3_object(jrslt$getResult(), result = TRUE)) |> # sort() |> @@ -140,7 +140,7 @@ userdefined_variables_x13 <- function(x = c("X-13","RegArima","X-11")){ "y_b", "y_b(?)", "y_eb(?)", "y_ef(?)", "y_f", "y_f(?)", "yc", "ycal", "ycal_f(?)") - # jts<-rjd3toolkit::.r2jd_ts(rjd3toolkit::ABS$X0.2.09.10.M) + # jts<-rjd3toolkit::.r2jd_tsdata(rjd3toolkit::ABS$X0.2.09.10.M) # jrslt<- rJava::.jcall("jdplus/x13/base/r/RegArima", "Ljdplus/x13/base/core/x13/regarima/RegArimaOutput;", "fullProcess", jts, "RG3") # rjd3toolkit::dictionary(rjd3toolkit::.jd3_object(jrslt$getResult(), result = TRUE)) |> # sort() |> @@ -180,7 +180,7 @@ userdefined_variables_x13 <- function(x = c("X-13","RegArima","X-11")){ "span.n", "span.start", "tde", "tde_b(?)", "tde_f(?)", "y", "y_b(?)", "y_eb(?)", "y_ef(?)", "y_f(?)", "yc", "ycal", "ycal_f(?)") - # jts<-rjd3toolkit::.r2jd_ts(rjd3toolkit::ABS$X0.2.09.10.M) + # jts<-rjd3toolkit::.r2jd_tsdata(rjd3toolkit::ABS$X0.2.09.10.M) # jrslt<- rJava::.jcall("jdplus/x13/base/r/X11", "Ljdplus/x13/base/core/x11/X11Results;", "process", jts, # rjd3x13::.r2jd_spec_x11(rjd3x13::spec_x11())) # rjd3toolkit::dictionary(rjd3toolkit::.jd3_object(jrslt, result = TRUE)) |> diff --git a/R/x13.R b/R/x13.R index a8adeb0..18fe8f0 100644 --- a/R/x13.R +++ b/R/x13.R @@ -6,16 +6,16 @@ NULL #' @param ts an univariate time series. #' @param spec the model specification. Can be either the name of a predefined specification or a user-defined specification. #' @param context list of external regressors (calendar or other) to be used for estimation -#' @param userdefined a vector containing additional output variables. +#' @param userdefined a vector containing additional output variables (see [x13_dictionary()]). #' -#' @return the `regarima()` function returns a list with the results (`"JD3_REGARIMA_RSLTS"` object), the estimation specification and the result specification, while `fast_regarima()` is a faster function that only returns the results. +#' @return the `regarima()` function returns a list with the results (`"JD3_REGARIMA_RSLTS"` object), the estimation specification and the result specification, while `regarima_fast()` is a faster function that only returns the results. #' #' @examples #' y = rjd3toolkit::ABS$X0.2.09.10.M -#' sp = spec_regarima("rg5c") +#' sp = regarima_spec("rg5c") #' sp = rjd3toolkit::add_outlier(sp, #' type = c("AO"), c("2015-01-01", "2010-01-01")) -#' fast_regarima(y, spec = sp) +#' regarima_fast(y, spec = sp) #' sp = rjd3toolkit::set_transform( #' rjd3toolkit::set_tradingdays( #' rjd3toolkit::set_easter(sp, enabled = FALSE), @@ -23,12 +23,12 @@ NULL #' ), #' fun = "None" #' ) -#' fast_regarima(y, spec = sp) +#' regarima_fast(y, spec = sp) #' sp = rjd3toolkit::set_outlier(sp, outliers.type = c("AO")) -#' fast_regarima(y, spec = sp) +#' regarima_fast(y, spec = sp) #' @export regarima<-function(ts, spec=c("rg4", "rg0", "rg1", "rg2c", "rg3","rg5c"), context=NULL, userdefined = NULL){ - jts<-rjd3toolkit::.r2jd_ts(ts) + jts<-rjd3toolkit::.r2jd_tsdata(ts) if (is.character(spec)){ spec = gsub("sa", "g", tolower(spec), fixed = TRUE) spec = match.arg(spec[1], @@ -53,8 +53,8 @@ regarima<-function(ts, spec=c("rg4", "rg0", "rg1", "rg2c", "rg3","rg5c"), contex } #' @export #' @rdname regarima -fast_regarima<-function(ts, spec= c("rg4", "rg0", "rg1", "rg2c", "rg3","rg5c"), context=NULL, userdefined = NULL){ - jts<-rjd3toolkit::.r2jd_ts(ts) +regarima_fast<-function(ts, spec= c("rg4", "rg0", "rg1", "rg2c", "rg3","rg5c"), context=NULL, userdefined = NULL){ + jts<-rjd3toolkit::.r2jd_tsdata(ts) if (is.character(spec)){ spec = gsub("sa", "g", tolower(spec), fixed = TRUE) spec = match.arg(spec[1], @@ -99,14 +99,13 @@ fast_regarima<-function(ts, spec= c("rg4", "rg0", "rg1", "rg2c", "rg3","rg5c"), #' #' #' @examples - #' y = rjd3toolkit::ABS$X0.2.09.10.M -#' fast_x13(y,"rsa3") +#' x13_fast(y,"rsa3") #' x13(y,"rsa5c") -#' fast_regarima(y,"rg0") +#' regarima_fast(y,"rg0") #' regarima(y,"rg3") #' -#' sp = spec_x13("rsa5c") +#' sp = x13_spec("rsa5c") #' sp = rjd3toolkit::add_outlier(sp, #' type = c("AO"), c("2015-01-01", "2010-01-01")) #' sp = rjd3toolkit::set_transform( @@ -119,16 +118,16 @@ fast_regarima<-function(ts, spec= c("rg4", "rg0", "rg1", "rg2c", "rg3","rg5c"), #' x13(y,spec=sp) #' sp = set_x11(sp, #' henderson.filter = 13) -#' fast_x13(y, spec = sp) +#' x13_fast(y, spec = sp) #' -#' @return the `x13()` function returns a list with the results, the estimation specification and the result specification, while `fast_x13()` is a faster function that only returns the results. +#' @return the `x13()` function returns a list with the results, the estimation specification and the result specification, while `x13_fast()` is a faster function that only returns the results. #' The `jx13()` functions only returns results in a java object which will allow to customize outputs in other packages (use [rjd3toolkit::dictionary()] to #' get the list of variables and [rjd3toolkit::result()] to get a specific variable). -#' In the estimation functions `x13()` and `fast_x13()` you can directly use a specification name (string) -#' #' If you want to customize a specification you have to create a specification object first +#' In the estimation functions `x13()` and `x13_fast()` you can directly use a specification name (string). +#' If you want to customize a specification you have to create a specification object first. #' @export x13<-function(ts, spec=c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c"), context=NULL, userdefined = NULL){ - jts<-rjd3toolkit::.r2jd_ts(ts) + jts<-rjd3toolkit::.r2jd_tsdata(ts) if (is.character(spec)){ spec = gsub("g", "sa", tolower(spec), fixed = TRUE) spec = match.arg(spec[1], @@ -155,8 +154,8 @@ x13<-function(ts, spec=c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c"), cont #' @export #' @rdname x13 -fast_x13<-function(ts, spec=c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c"), context=NULL, userdefined = NULL){ - jts<-rjd3toolkit::.r2jd_ts(ts) +x13_fast<-function(ts, spec=c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c"), context=NULL, userdefined = NULL){ + jts<-rjd3toolkit::.r2jd_tsdata(ts) if (is.character(spec)){ spec = gsub("g", "sa", tolower(spec), fixed = TRUE) spec = match.arg(spec[1], @@ -183,7 +182,7 @@ fast_x13<-function(ts, spec=c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c"), #' @export #' @rdname x13 jx13<-function(ts, spec=c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c"), context=NULL, userdefined = NULL){ - jts<-rjd3toolkit::.r2jd_ts(ts) + jts<-rjd3toolkit::.r2jd_tsdata(ts) if (is.character(spec)){ spec = gsub("g", "sa", tolower(spec), fixed = TRUE) spec = match.arg(spec[1], @@ -230,13 +229,13 @@ jx13<-function(ts, spec=c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c"), con #' #' @examples #' y <- rjd3toolkit::ABS$X0.2.09.10.M -#' x11_spec <- spec_x11() +#' x11_spec <- x11_spec() #' x11(y, x11_spec) #' x11_spec <- set_x11(x11_spec, henderson.filter = 13) #' x11(y, x11_spec) #' @export -x11 <- function(ts, spec = spec_x11(), userdefined = NULL){ - jts<-rjd3toolkit::.r2jd_ts(ts) +x11 <- function(ts, spec = x11_spec(), userdefined = NULL){ + jts<-rjd3toolkit::.r2jd_tsdata(ts) jspec<-.r2jd_spec_x11(spec) jrslt<-.jcall("jdplus/x13/base/r/X11", "Ljdplus/x13/base/core/x11/X11Results;", "process", jts, jspec) if (is.jnull(jrslt)){ @@ -268,6 +267,7 @@ x11 <- function(ts, spec = spec_x11(), userdefined = NULL){ #' #' \strong{FixedParameters}: pre-adjustment reg-arima model is partially modified: regression coefficients will be re-estimated but regression variables, Arima orders #' and coefficients are unchanged. +#' #' \strong{FixedAutoRegressiveParameters}: same as FixedParameters but Arima Moving Average coefficients (MA) are also re-estimated, Auto-regressive (AR) coefficients are kept fixed. #' #' \strong{FreeParameters}: all regression and Arima model coefficients are re-estimated, regression variables and Arima orders are kept fixed. @@ -276,17 +276,19 @@ x11 <- function(ts, spec = spec_x11(), userdefined = NULL){ #' #' \strong{Outliers_StochasticComponent}: same as "Outliers" but Arima model orders (p,d,q)(P,D,Q) can also be re-identified. #' -#' @param spec the current specification to be refreshed ("result_spec") -#' @param refspec the reference specification used to define the domain considered for re-estimation ("domain_spec") +#' @param spec the current specification to be refreshed (`"result_spec"`). +#' @param refspec the reference specification used to define the domain considered for re-estimation (`"domain_spec"`). #' By default this is the `"RG5c"` or `"RSA5"` specification. -#' @param policy the refresh policy to apply (see details) -#' @param period,start,end to specify the span on which outliers will be re-identified when `policy` equals to `"Outliers"` -#' or `"Outliers_StochasticComponent"`. Span definition: \code{period}: numeric, number of observations in a year (12,4...). \code{start}: vector -#' indicating the start of the series in the format c(YYYY,MM). \code{end}: vector in the format c(YYYY,MM) indicating the date from which outliers -#' will be re-identified. If span parameters are not specified outliers will be re-detected on the whole series. +#' @param policy the refresh policy to apply (see details). +#' @param period,start,end to specify the span on which outliers will not be re-identified (i.e.: re-detected) when `policy = "Outliers"` +#' or `policy = "Outliers_StochasticComponent"`. +#' Span definition: \code{period}: numeric, number of observations in a year (12, 4...). +#' \code{start} and \code{end}: first and last date from which outliers will not be re-identfied, +#' defined as arrays of two elements: year and first period (for example, if `period = 12`, `c(1980, 1)` for January 1980). +#' If they are not specified, the outliers will be re-identified on the whole series. #' -#' @return a new specification, an object of class `"JD3_X13_SPEC"` (`spec_x13()`), -#' `"JD3_REGARIMA_SPEC"` (`spec_regarima()`) +#' @return a new specification, an object of class `"JD3_X13_SPEC"` or +#' `"JD3_REGARIMA_SPEC"`. #' #' @references #' More information on revision policies in JDemetra+ online documentation: @@ -299,9 +301,9 @@ x11 <- function(ts, spec = spec_x11(), userdefined = NULL){ #'# raw series for second (refreshed) estimation #'y_new <-window(y,end = 2010) #'# specification for first estimation -#'spec_x13_1<-spec_x13("rsa5c") +#'spec_x13_1<-x13_spec("rsa5c") #'# first estimation -#'sa_x13<- rjd3x13::x13(y_raw, spec_x13_1) +#'sa_x13<- x13(y_raw, spec_x13_1) #' # refreshing the specification #' current_result_spec <- sa_x13$result_spec #' current_domain_spec <- sa_x13$estimation_spec @@ -352,3 +354,12 @@ x13_refresh<-function(spec, refspec=NULL, policy=c("FreeParameters", "Complete", return (.jd2r_spec_x13(jnspec)) } +#' X-13 Dictionary +#' +#' @return A vector containing the names of all the available output objects (series, diagnostics, parameters). +#' @export +x13_dictionary<-function(){ + return (.jcall("jdplus/x13/base/r/X13","[S", "dictionary")) +} + + diff --git a/R/x13_rslts.R b/R/x13_rslts.R index be0f666..84fead1 100644 --- a/R/x13_rslts.R +++ b/R/x13_rslts.R @@ -1,5 +1,5 @@ #' @include utils.R -#' @importFrom rjd3toolkit sa.decomposition +#' @importFrom rjd3toolkit sa_decomposition NULL .regarima_rslts <- function(jrslts){ @@ -46,18 +46,18 @@ NULL .p2r_x11_rslts<-function(p){ return (structure( list( - d1=rjd3toolkit::.p2r_ts(p$d1), - d2=rjd3toolkit::.p2r_ts(p$d2), - d4=rjd3toolkit::.p2r_ts(p$d4), - d5=rjd3toolkit::.p2r_ts(p$d5), - d6=rjd3toolkit::.p2r_ts(p$d6), - d7=rjd3toolkit::.p2r_ts(p$d7), - d8=rjd3toolkit::.p2r_ts(p$d8), - d9=rjd3toolkit::.p2r_ts(p$d9), - d10=rjd3toolkit::.p2r_ts(p$d10), - d11=rjd3toolkit::.p2r_ts(p$d11), - d12=rjd3toolkit::.p2r_ts(p$d12), - d13=rjd3toolkit::.p2r_ts(p$d13), + d1=rjd3toolkit::.p2r_tsdata(p$d1), + d2=rjd3toolkit::.p2r_tsdata(p$d2), + d4=rjd3toolkit::.p2r_tsdata(p$d4), + d5=rjd3toolkit::.p2r_tsdata(p$d5), + d6=rjd3toolkit::.p2r_tsdata(p$d6), + d7=rjd3toolkit::.p2r_tsdata(p$d7), + d8=rjd3toolkit::.p2r_tsdata(p$d8), + d9=rjd3toolkit::.p2r_tsdata(p$d9), + d10=rjd3toolkit::.p2r_tsdata(p$d10), + d11=rjd3toolkit::.p2r_tsdata(p$d11), + d12=rjd3toolkit::.p2r_tsdata(p$d12), + d13=rjd3toolkit::.p2r_tsdata(p$d13), final_seasonal=p$final_seasonal_filters, final_henderson=p$final_henderson_filter ), @@ -67,31 +67,31 @@ NULL .p2r_x13_final<-function(p){ return (list( - d11final=rjd3toolkit::.p2r_ts(p$d11final), - d12final=rjd3toolkit::.p2r_ts(p$d12final), - d13final=rjd3toolkit::.p2r_ts(p$d13final), - d16=rjd3toolkit::.p2r_ts(p$d16), - d18=rjd3toolkit::.p2r_ts(p$d18), - d11a=rjd3toolkit::.p2r_ts(p$d11a), - d12a=rjd3toolkit::.p2r_ts(p$d12a), - d16a=rjd3toolkit::.p2r_ts(p$d16a), - d18a=rjd3toolkit::.p2r_ts(p$d18a), - e1=rjd3toolkit::.p2r_ts(p$e1), - e2=rjd3toolkit::.p2r_ts(p$e2), - e3=rjd3toolkit::.p2r_ts(p$e3), - e11=rjd3toolkit::.p2r_ts(p$e11) + d11final=rjd3toolkit::.p2r_tsdata(p$d11final), + d12final=rjd3toolkit::.p2r_tsdata(p$d12final), + d13final=rjd3toolkit::.p2r_tsdata(p$d13final), + d16=rjd3toolkit::.p2r_tsdata(p$d16), + d18=rjd3toolkit::.p2r_tsdata(p$d18), + d11a=rjd3toolkit::.p2r_tsdata(p$d11a), + d12a=rjd3toolkit::.p2r_tsdata(p$d12a), + d16a=rjd3toolkit::.p2r_tsdata(p$d16a), + d18a=rjd3toolkit::.p2r_tsdata(p$d18a), + e1=rjd3toolkit::.p2r_tsdata(p$e1), + e2=rjd3toolkit::.p2r_tsdata(p$e2), + e3=rjd3toolkit::.p2r_tsdata(p$e3), + e11=rjd3toolkit::.p2r_tsdata(p$e11) )) } .p2r_x13_preadjust<-function(p){ return (list( - a1=rjd3toolkit::.p2r_ts(p$a1), - a1a=rjd3toolkit::.p2r_ts(p$a1a), - a1b=rjd3toolkit::.p2r_ts(p$a1b), - a6=rjd3toolkit::.p2r_ts(p$a6), - a7=rjd3toolkit::.p2r_ts(p$a7), - a8=rjd3toolkit::.p2r_ts(p$a8), - a9=rjd3toolkit::.p2r_ts(p$a9) + a1=rjd3toolkit::.p2r_tsdata(p$a1), + a1a=rjd3toolkit::.p2r_tsdata(p$a1a), + a1b=rjd3toolkit::.p2r_tsdata(p$a1b), + a6=rjd3toolkit::.p2r_tsdata(p$a6), + a7=rjd3toolkit::.p2r_tsdata(p$a7), + a8=rjd3toolkit::.p2r_tsdata(p$a8), + a9=rjd3toolkit::.p2r_tsdata(p$a9) )) } @@ -99,23 +99,22 @@ NULL ############################# Generics #' @export -#' @importFrom rjd3toolkit sa.decomposition -sa.decomposition.JD3_X13_RSLTS<-function(x, ...){ +#' @importFrom rjd3toolkit sa_decomposition +sa_decomposition.JD3_X13_RSLTS<-function(x, ...){ if (is.null(x)) return (NULL) - return (rjd3toolkit::sadecomposition(x$preadjust$a1, - x$final$d11final, - x$final$d12final, - x$final$d10final, - # x$decomposition$d10, - x$final$d13final, + return (rjd3toolkit::sadecomposition(x$preadjust$a1, #y + x$final$d11final, #sa + x$final$d12final, #t + x$final$d16, #s + x$final$d13final, #i x$preprocessing$description$log )) } #' @export -sa.decomposition.JD3_X13_OUTPUT<-function(x, ...){ - return (rjd3toolkit::sadecomposition(x$result, ...)) +sa_decomposition.JD3_X13_OUTPUT<-function(x, ...){ + return (rjd3toolkit::sa_decomposition(x$result, ...)) } diff --git a/R/x13_spec.R b/R/x13_spec.R index 6779e44..2e6d6fa 100644 --- a/R/x13_spec.R +++ b/R/x13_spec.R @@ -6,25 +6,25 @@ NULL #' #' Set of functions to create default specification objects associated with the X-13ARIMA seasonal adjustment method. #' -#' Specification setting of sheer X-11 decomposition method (without reg-arima pre-adjustment) is supported by the `spec_x11()` function only +#' Specification setting of sheer X-11 decomposition method (without reg-arima pre-adjustment) is supported by the `x11_spec()` function only #' and doesn't appear among the possible X13-Arima default specifications #' -#' Specification setting can be restricted to the reg-arima part with the `spec_regarima()` function, -#' without argument `spec_regarima()` yields a RG5c specification +#' Specification setting can be restricted to the reg-arima part with the `regarima_spec()` function, +#' without argument `regarima_spec()` yields a RG5c specification #' -#' When setting a complete X13-Arima spec, `spec_x13()` without argument yields a RSA5c specification +#' When setting a complete X13-Arima spec, `x13_spec()` without argument yields a RSA5c specification #' #' #' @param name the name of a predefined specification. #' #' @examples -#' init_spec <- spec_x11() -#' init_spec <- spec_regarima("rg4") -#' init_spec <- spec_x13("rsa5c") +#' init_spec <- x11_spec() +#' init_spec <- regarima_spec("rg4") +#' init_spec <- x13_spec("rsa5c") #' -#' @return an object of class `"JD3_X13_SPEC"` (`spec_x13()`), -#' `"JD3_REGARIMA_SPEC"` (`spec_regarima()`) or -#' `"JD3_X11_SPEC"` (`spec_x11()`). +#' @return an object of class `"JD3_X13_SPEC"` (`x13_spec()`), +#' `"JD3_REGARIMA_SPEC"` (`regarima_spec()`) or +#' `"JD3_X11_SPEC"` (`x11_spec()`). #' #' @details #' The available predefined 'JDemetra+' model specifications are described in the table below: @@ -38,10 +38,14 @@ NULL #' RSA4c/RG4c |\tab automatic |\tab AO/LS/TC |\tab 2 td vars + Easter |\tab automatic\cr #' RSA5c/RG5c |\tab automatic |\tab AO/LS/TC |\tab 7 td vars + Easter |\tab automatic #' } -#' @name spec_x13 -#' @rdname spec_x13 +#' #' @seealso +#' - To set the pre-processing parameters: [rjd3toolkit::set_arima()], [rjd3toolkit::set_automodel()], [rjd3toolkit::set_basic()], [rjd3toolkit::set_easter()], [rjd3toolkit::set_estimate()], [rjd3toolkit::set_outlier()], [rjd3toolkit::set_tradingdays()], [rjd3toolkit::set_transform()], [rjd3toolkit::add_outlier()], [rjd3toolkit::remove_outlier()], [rjd3toolkit::add_ramp()], [rjd3toolkit::remove_ramp()], [rjd3toolkit::add_usrdefvar()]. +#' - To set the decomposition parameters: [set_x11()]. +#' - To set the benchmarking parameters: [rjd3toolkit::set_benchmarking()]. +#' @name x13_spec +#' @rdname x13_spec #' @export -spec_regarima<-function(name=c("rg4","rg0", "rg1", "rg2c", "rg3", "rg5c")){ +regarima_spec<-function(name=c("rg4","rg0", "rg1", "rg2c", "rg3", "rg5c")){ name = gsub("sa", "g", tolower(name), fixed = TRUE) name = match.arg(name[1], choices = c("rg0", "rg1", "rg2c", "rg3","rg4", "rg5c") @@ -50,9 +54,9 @@ spec_regarima<-function(name=c("rg4","rg0", "rg1", "rg2c", "rg3", "rg5c")){ } -#' @rdname spec_x13 +#' @rdname x13_spec #' @export -spec_x13<-function(name = c("rsa4","rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c")){ +x13_spec<-function(name = c("rsa4","rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c")){ name = gsub("g", "sa", tolower(name), fixed = TRUE) name = match.arg(name[1], choices = c("rsa0", "rsa1", "rsa2c", "rsa3","rsa4", "rsa5c") @@ -61,9 +65,9 @@ spec_x13<-function(name = c("rsa4","rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c")){ } -#' @rdname spec_x11 +#' @rdname x13_spec #' @export -spec_x11<-function(){ +x11_spec<-function(){ return (.jd2r_spec_x11(.jfield("jdplus/x13/base/api/x11/X11Spec", "Ljdplus/x13/base/api/x11/X11Spec;", "DEFAULT"))) } diff --git a/R/zzz.R b/R/zzz.R index 2126b6c..7dd7f6c 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -14,7 +14,7 @@ readProtoFiles2(protoPath = proto.dir) # reload extractors - .jcall("jdplus/toolkit/base/api/information/InformationExtractors", "V", "reloadExtractors") + rjd3toolkit::reload_dictionaries() } diff --git a/README.Rmd b/README.Rmd index b2f7121..f9e6f7e 100644 --- a/README.Rmd +++ b/README.Rmd @@ -18,7 +18,7 @@ library(rjd3x13) rjd3x13 offers full acces to options and outputs of X-13 (`rjd3x13::x13()`), including RegARIMA modelling (`rjd3x13::regarima()`) and X-11 decomposition (`rjd3x13::x11()`). -The specification can be created with the functions `rjd3x13::spec_regarima()`, `rjd3x13::spec_x11()` or `rjd3x13::spec_x13()` and can be modified with the function: +The specification can be created with the functions `rjd3x13::regarima_spec()`, `rjd3x13::x11_spec()` or `rjd3x13::x13_spec()` and can be modified with the function: - for the pre-processing: `rjd3toolkit::set_arima()`, `rjd3toolkit::set_automodel()`, `rjd3toolkit::set_basic()`, `rjd3toolkit::set_easter()`, `rjd3toolkit::set_estimate()`, `rjd3toolkit::set_outlier()`, `rjd3toolkit::set_tradingdays()`, `rjd3toolkit::set_transform()`, `rjd3toolkit::add_outlier()`, `rjd3toolkit::remove_outlier()`, `rjd3toolkit::add_ramp()`, `rjd3toolkit::remove_ramp()`, `rjd3toolkit::add_usrdefvar()`; diff --git a/README.md b/README.md index fdda0e6..fa25773 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,7 @@ rjd3x13 offers full acces to options and outputs of X-13 and X-11 decomposition (`rjd3x13::x11()`). The specification can be created with the functions -`rjd3x13::spec_regarima()`, `rjd3x13::spec_x11()` or -`rjd3x13::spec_x13()` and can be modified with the function: +`rjd3x13::regarima_spec()`, `rjd3x13::x11_spec()` or - for the pre-processing: `rjd3toolkit::set_arima()`, `rjd3toolkit::set_automodel()`, `rjd3toolkit::set_basic()`, @@ -31,40 +30,3 @@ The specification can be created with the functions remotes::install_github("rjdemetra/rjd3toolkit") remotes::install_github("rjdemetra/rjd3x13") ``` - -## Usage - -``` r -library(rjd3x13) -y <- rjd3toolkit::ABS$X0.2.09.10.M -x13_model <- x13(y) -summary(x13_model$result$preprocessing) # Summary of regarima model -#> Log-transformation: yes -#> SARIMA model: (2,1,1) (0,1,1) -#> -#> Coefficients -#> Estimate Std. Error T-stat Pr(>|t|) -#> phi(1) 0.34740 0.06502 5.343 1.53e-07 *** -#> phi(2) 0.21733 0.06000 3.622 0.000329 *** -#> theta(1) -0.69937 0.05115 -13.672 < 2e-16 *** -#> btheta(1) -0.48038 0.06993 -6.869 2.45e-11 *** -#> --- -#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 -#> -#> Regression model: -#> Estimate Std. Error T-stat Pr(>|t|) -#> td 0.0023233 0.0006844 3.395 0.000755 *** -#> easter 0.0520113 0.0084894 6.127 2.13e-09 *** -#> TC (2000-06-01) 0.1590340 0.0288578 5.511 6.37e-08 *** -#> AO (2000-07-01) -0.2900774 0.0400551 -7.242 2.25e-12 *** -#> --- -#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 -#> Number of observations: 425 , Number of effective observations: 412 , Number of parameters: 9 -#> Loglikelihood: 746.7517, Adjusted loglikelihood: -2120.875 -#> Standard error of the regression (ML estimate): 0.03927991 -#> AIC: 4259.75 , AICc: 4260.198 , BIC: 4295.939 - -plot(x13_model) # Plot of the final decomposition -``` - - diff --git a/inst/java/jdplus-x13-base-api-3.0.2.jar b/inst/java/jdplus-x13-base-api-3.1.0.jar similarity index 89% rename from inst/java/jdplus-x13-base-api-3.0.2.jar rename to inst/java/jdplus-x13-base-api-3.1.0.jar index ffa840d..006dbf8 100644 Binary files a/inst/java/jdplus-x13-base-api-3.0.2.jar and b/inst/java/jdplus-x13-base-api-3.1.0.jar differ diff --git a/inst/java/jdplus-x13-base-core-3.0.2.jar b/inst/java/jdplus-x13-base-core-3.1.0.jar similarity index 87% rename from inst/java/jdplus-x13-base-core-3.0.2.jar rename to inst/java/jdplus-x13-base-core-3.1.0.jar index d5b492a..58b7c52 100644 Binary files a/inst/java/jdplus-x13-base-core-3.0.2.jar and b/inst/java/jdplus-x13-base-core-3.1.0.jar differ diff --git a/inst/java/jdplus-x13-base-protobuf-3.0.2.jar b/inst/java/jdplus-x13-base-protobuf-3.1.0.jar similarity index 95% rename from inst/java/jdplus-x13-base-protobuf-3.0.2.jar rename to inst/java/jdplus-x13-base-protobuf-3.1.0.jar index bd913f2..1bb60f0 100644 Binary files a/inst/java/jdplus-x13-base-protobuf-3.0.2.jar and b/inst/java/jdplus-x13-base-protobuf-3.1.0.jar differ diff --git a/inst/java/jdplus-x13-base-r-3.0.2.jar b/inst/java/jdplus-x13-base-r-3.1.0.jar similarity index 69% rename from inst/java/jdplus-x13-base-r-3.0.2.jar rename to inst/java/jdplus-x13-base-r-3.1.0.jar index e601dae..3a11d6c 100644 Binary files a/inst/java/jdplus-x13-base-r-3.0.2.jar and b/inst/java/jdplus-x13-base-r-3.1.0.jar differ diff --git a/man/deprecated-rjd3x13.Rd b/man/deprecated-rjd3x13.Rd new file mode 100644 index 0000000..3b07b44 --- /dev/null +++ b/man/deprecated-rjd3x13.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/deprecated.R +\name{deprecated-rjd3x13} +\alias{deprecated-rjd3x13} +\alias{spec_x13} +\alias{spec_regarima} +\alias{spec_x11} +\alias{fast_x13} +\alias{fast_regarima} +\title{Deprecated functions} +\usage{ +spec_x13(name = c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c")) + +spec_regarima(name = c("rg4", "rg0", "rg1", "rg2c", "rg3", "rg5c")) + +spec_x11() + +fast_x13( + ts, + spec = c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c"), + context = NULL, + userdefined = NULL +) + +fast_regarima( + ts, + spec = c("rg4", "rg0", "rg1", "rg2c", "rg3", "rg5c"), + context = NULL, + userdefined = NULL +) +} +\arguments{ +\item{ts, spec, context, userdefined, name}{Parameters.} +} +\description{ +Deprecated functions +} diff --git a/man/refresh.Rd b/man/refresh.Rd index 4f4243d..2f7b36d 100644 --- a/man/refresh.Rd +++ b/man/refresh.Rd @@ -27,21 +27,23 @@ x13_refresh( ) } \arguments{ -\item{spec}{the current specification to be refreshed ("result_spec")} +\item{spec}{the current specification to be refreshed (\code{"result_spec"}).} -\item{refspec}{the reference specification used to define the domain considered for re-estimation ("domain_spec") +\item{refspec}{the reference specification used to define the domain considered for re-estimation (\code{"domain_spec"}). By default this is the \code{"RG5c"} or \code{"RSA5"} specification.} -\item{policy}{the refresh policy to apply (see details)} +\item{policy}{the refresh policy to apply (see details).} -\item{period, start, end}{to specify the span on which outliers will be re-identified when \code{policy} equals to \code{"Outliers"} -or \code{"Outliers_StochasticComponent"}. Span definition: \code{period}: numeric, number of observations in a year (12,4...). \code{start}: vector -indicating the start of the series in the format c(YYYY,MM). \code{end}: vector in the format c(YYYY,MM) indicating the date from which outliers -will be re-identified. If span parameters are not specified outliers will be re-detected on the whole series.} +\item{period, start, end}{to specify the span on which outliers will not be re-identified (i.e.: re-detected) when \code{policy = "Outliers"} +or \code{policy = "Outliers_StochasticComponent"}. +Span definition: \code{period}: numeric, number of observations in a year (12, 4...). +\code{start} and \code{end}: first and last date from which outliers will not be re-identfied, +defined as arrays of two elements: year and first period (for example, if \code{period = 12}, \code{c(1980, 1)} for January 1980). +If they are not specified, the outliers will be re-identified on the whole series.} } \value{ -a new specification, an object of class \code{"JD3_X13_SPEC"} (\code{spec_x13()}), -\code{"JD3_REGARIMA_SPEC"} (\code{spec_regarima()}) +a new specification, an object of class \code{"JD3_X13_SPEC"} or +\code{"JD3_REGARIMA_SPEC"}. } \description{ Function allowing to create a new specification by updating a specification used for a previous estimation. @@ -62,6 +64,7 @@ Available refresh policies are: \strong{FixedParameters}: pre-adjustment reg-arima model is partially modified: regression coefficients will be re-estimated but regression variables, Arima orders and coefficients are unchanged. + \strong{FixedAutoRegressiveParameters}: same as FixedParameters but Arima Moving Average coefficients (MA) are also re-estimated, Auto-regressive (AR) coefficients are kept fixed. \strong{FreeParameters}: all regression and Arima model coefficients are re-estimated, regression variables and Arima orders are kept fixed. @@ -77,9 +80,9 @@ y_raw <-window(y,end = 2009) # raw series for second (refreshed) estimation y_new <-window(y,end = 2010) # specification for first estimation -spec_x13_1<-spec_x13("rsa5c") +spec_x13_1<-x13_spec("rsa5c") # first estimation -sa_x13<- rjd3x13::x13(y_raw, spec_x13_1) +sa_x13<- x13(y_raw, spec_x13_1) # refreshing the specification current_result_spec <- sa_x13$result_spec current_domain_spec <- sa_x13$estimation_spec diff --git a/man/regarima.Rd b/man/regarima.Rd index 256fdd3..94f346c 100644 --- a/man/regarima.Rd +++ b/man/regarima.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/x13.R \name{regarima} \alias{regarima} -\alias{fast_regarima} +\alias{regarima_fast} \title{RegARIMA model, pre-adjustment in X13} \usage{ regarima( @@ -12,7 +12,7 @@ regarima( userdefined = NULL ) -fast_regarima( +regarima_fast( ts, spec = c("rg4", "rg0", "rg1", "rg2c", "rg3", "rg5c"), context = NULL, @@ -26,20 +26,20 @@ fast_regarima( \item{context}{list of external regressors (calendar or other) to be used for estimation} -\item{userdefined}{a vector containing additional output variables.} +\item{userdefined}{a vector containing additional output variables (see \code{\link[=x13_dictionary]{x13_dictionary()}}).} } \value{ -the \code{regarima()} function returns a list with the results (\code{"JD3_REGARIMA_RSLTS"} object), the estimation specification and the result specification, while \code{fast_regarima()} is a faster function that only returns the results. +the \code{regarima()} function returns a list with the results (\code{"JD3_REGARIMA_RSLTS"} object), the estimation specification and the result specification, while \code{regarima_fast()} is a faster function that only returns the results. } \description{ RegARIMA model, pre-adjustment in X13 } \examples{ y = rjd3toolkit::ABS$X0.2.09.10.M -sp = spec_regarima("rg5c") +sp = regarima_spec("rg5c") sp = rjd3toolkit::add_outlier(sp, type = c("AO"), c("2015-01-01", "2010-01-01")) -fast_regarima(y, spec = sp) +regarima_fast(y, spec = sp) sp = rjd3toolkit::set_transform( rjd3toolkit::set_tradingdays( rjd3toolkit::set_easter(sp, enabled = FALSE), @@ -47,7 +47,7 @@ sp = rjd3toolkit::set_transform( ), fun = "None" ) -fast_regarima(y, spec = sp) +regarima_fast(y, spec = sp) sp = rjd3toolkit::set_outlier(sp, outliers.type = c("AO")) -fast_regarima(y, spec = sp) +regarima_fast(y, spec = sp) } diff --git a/man/spec_x13.Rd b/man/spec_x13.Rd deleted file mode 100644 index 3577c67..0000000 --- a/man/spec_x13.Rd +++ /dev/null @@ -1,49 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/x13_spec.R -\name{spec_x13} -\alias{spec_x13} -\alias{spec_regarima} -\title{RegARIMA/X-13 Default Specifications} -\usage{ -spec_regarima(name = c("rg4", "rg0", "rg1", "rg2c", "rg3", "rg5c")) - -spec_x13(name = c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c")) -} -\arguments{ -\item{name}{the name of a predefined specification.} -} -\value{ -an object of class \code{"JD3_X13_SPEC"} (\code{spec_x13()}), -\code{"JD3_REGARIMA_SPEC"} (\code{spec_regarima()}) or -\code{"JD3_X11_SPEC"} (\code{spec_x11()}). -} -\description{ -Set of functions to create default specification objects associated with the X-13ARIMA seasonal adjustment method. -} -\details{ -Specification setting of sheer X-11 decomposition method (without reg-arima pre-adjustment) is supported by the \code{spec_x11()} function only -and doesn't appear among the possible X13-Arima default specifications - -Specification setting can be restricted to the reg-arima part with the \code{spec_regarima()} function, -without argument \code{spec_regarima()} yields a RG5c specification - -When setting a complete X13-Arima spec, \code{spec_x13()} without argument yields a RSA5c specification - -The available predefined 'JDemetra+' model specifications are described in the table below: - -\tabular{rrrrrrr}{ -\strong{Identifier} |\tab \strong{Log/level detection} |\tab \strong{Outliers detection} |\tab \strong{Calendar effects} |\tab \strong{ARIMA}\cr -RSA0/RG0 |\tab \emph{NA} |\tab \emph{NA} |\tab \emph{NA} |\tab Airline(+mean)\cr -RSA1/RG1 |\tab automatic |\tab AO/LS/TC |\tab \emph{NA} |\tab Airline(+mean)\cr -RSA2c/RG2c |\tab automatic |\tab AO/LS/TC |\tab 2 td vars + Easter |\tab Airline(+mean)\cr -RSA3/RG3 |\tab automatic |\tab AO/LS/TC |\tab \emph{NA} |\tab automatic\cr -RSA4c/RG4c |\tab automatic |\tab AO/LS/TC |\tab 2 td vars + Easter |\tab automatic\cr -RSA5c/RG5c |\tab automatic |\tab AO/LS/TC |\tab 7 td vars + Easter |\tab automatic -} -} -\examples{ -init_spec <- spec_x11() -init_spec <- spec_regarima("rg4") -init_spec <- spec_x13("rsa5c") - -} diff --git a/man/x11.Rd b/man/x11.Rd index 2c4acd4..294e7d5 100644 --- a/man/x11.Rd +++ b/man/x11.Rd @@ -4,21 +4,21 @@ \alias{x11} \title{X-11 Decomposition Algorithm} \usage{ -x11(ts, spec = spec_x11(), userdefined = NULL) +x11(ts, spec = x11_spec(), userdefined = NULL) } \arguments{ \item{ts}{an univariate time series.} \item{spec}{the specification.} -\item{userdefined}{a vector containing additional output variables.} +\item{userdefined}{a vector containing additional output variables (see \code{\link[=x13_dictionary]{x13_dictionary()}}).} } \description{ X-11 Decomposition Algorithm } \examples{ y <- rjd3toolkit::ABS$X0.2.09.10.M -x11_spec <- spec_x11() +x11_spec <- x11_spec() x11(y, x11_spec) x11_spec <- set_x11(x11_spec, henderson.filter = 13) x11(y, x11_spec) diff --git a/man/spec_x11.Rd b/man/x11_spec.Rd similarity index 94% rename from man/spec_x11.Rd rename to man/x11_spec.Rd index 94bb538..94f170d 100644 --- a/man/spec_x11.Rd +++ b/man/x11_spec.Rd @@ -1,8 +1,7 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/set_x11_spec.R, R/x13_spec.R +% Please edit documentation in R/set_x11_spec.R \name{set_x11} \alias{set_x11} -\alias{spec_x11} \title{Set X-11 Specification} \usage{ set_x11( @@ -21,11 +20,9 @@ set_x11( exclude.forecast = NA, bias = c(NA, "LEGACY") ) - -spec_x11() } \arguments{ -\item{x}{the specification to be modified, object of class "JD3_X11_SPEC", default X11 spec can be obtained as 'x=spec_x11()'} +\item{x}{the specification to be modified, object of class "JD3_X11_SPEC", default X11 spec can be obtained as 'x=x11_spec()'} \item{mode}{character: the decomposition mode. Determines the mode of the seasonal adjustment decomposition to be performed: \code{"Undefined"} - no assumption concerning the relationship between the time series components is made; @@ -69,13 +66,13 @@ detection and adjustment will be computed separately. Only used if \code{calenda \item{bias}{TODO.} } \value{ -a "JD3_X11_SPEC" object, containing all the parameters +a "JD3_X11_SPEC" object, containing all the parameters. } \description{ Set X-11 Specification } \examples{ -init_spec <- spec_x11() +init_spec <- x11_spec() new_spec <- set_x11(init_spec, mode = "LogAdditive", seasonal.comp = 1, @@ -90,3 +87,6 @@ new_spec <- set_x11(init_spec, exclude.forecast = FALSE, bias = "LEGACY") } +\seealso{ +\code{\link[=x13_spec]{x13_spec()}} and \code{\link[=x11_spec]{x11_spec()}}. +} diff --git a/man/x13.Rd b/man/x13.Rd index d407ba3..62c44a8 100644 --- a/man/x13.Rd +++ b/man/x13.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/x13.R \name{x13} \alias{x13} -\alias{fast_x13} +\alias{x13_fast} \alias{jx13} \title{Seasonal Adjustment with X13-ARIMA} \usage{ @@ -13,7 +13,7 @@ x13( userdefined = NULL ) -fast_x13( +x13_fast( ts, spec = c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c"), context = NULL, @@ -34,26 +34,26 @@ jx13( \item{context}{list of external regressors (calendar or other) to be used for estimation} -\item{userdefined}{a vector containing additional output variables.} +\item{userdefined}{a vector containing additional output variables (see \code{\link[=x13_dictionary]{x13_dictionary()}}).} } \value{ -the \code{x13()} function returns a list with the results, the estimation specification and the result specification, while \code{fast_x13()} is a faster function that only returns the results. +the \code{x13()} function returns a list with the results, the estimation specification and the result specification, while \code{x13_fast()} is a faster function that only returns the results. The \code{jx13()} functions only returns results in a java object which will allow to customize outputs in other packages (use \code{\link[rjd3toolkit:dictionary]{rjd3toolkit::dictionary()}} to get the list of variables and \code{\link[rjd3toolkit:dictionary]{rjd3toolkit::result()}} to get a specific variable). -In the estimation functions \code{x13()} and \code{fast_x13()} you can directly use a specification name (string) -#' If you want to customize a specification you have to create a specification object first +In the estimation functions \code{x13()} and \code{x13_fast()} you can directly use a specification name (string). +If you want to customize a specification you have to create a specification object first. } \description{ Seasonal Adjustment with X13-ARIMA } \examples{ y = rjd3toolkit::ABS$X0.2.09.10.M -fast_x13(y,"rsa3") +x13_fast(y,"rsa3") x13(y,"rsa5c") -fast_regarima(y,"rg0") +regarima_fast(y,"rg0") regarima(y,"rg3") -sp = spec_x13("rsa5c") +sp = x13_spec("rsa5c") sp = rjd3toolkit::add_outlier(sp, type = c("AO"), c("2015-01-01", "2010-01-01")) sp = rjd3toolkit::set_transform( @@ -66,6 +66,6 @@ sp = rjd3toolkit::set_transform( x13(y,spec=sp) sp = set_x11(sp, henderson.filter = 13) -fast_x13(y, spec = sp) +x13_fast(y, spec = sp) } diff --git a/man/x13_dictionary.Rd b/man/x13_dictionary.Rd new file mode 100644 index 0000000..ddfbd3b --- /dev/null +++ b/man/x13_dictionary.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/x13.R +\name{x13_dictionary} +\alias{x13_dictionary} +\title{X-13 Dictionary} +\usage{ +x13_dictionary() +} +\value{ +A vector containing the names of all the available output objects (series, diagnostics, parameters). +} +\description{ +X-13 Dictionary +} diff --git a/man/x13_revisions.Rd b/man/x13_revisions.Rd new file mode 100644 index 0000000..63ae810 --- /dev/null +++ b/man/x13_revisions.Rd @@ -0,0 +1,66 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/revisions.R +\name{x13_revisions} +\alias{x13_revisions} +\title{Revisions History} +\usage{ +x13_revisions( + ts, + spec, + data_ids = NULL, + ts_ids = NULL, + cmp_ids = NULL, + context = NULL +) +} +\arguments{ +\item{ts}{The time series used for the estimation.} + +\item{spec}{The specification used.} + +\item{data_ids}{A \code{list} of \code{list} to specify the statistics to export. +Each sub-list must contain two elements: +\code{start} (first date to compute the history, in the format \code{"YYYY-MM-DD"}) +and \code{id} (the name of the statistics, see \code{\link[=x13_dictionary]{x13_dictionary()}}). +See example.} + +\item{ts_ids}{A \code{list} of \code{list} to specify the specific date of a component whose history is to be studied. +Each sub-list must contain three elements: +\code{start} (first date to compute the history, in the format \code{"YYYY-MM-DD"}), +\code{period} (the date of the studied) +and \code{id} (the name of the component, see \code{\link[=x13_dictionary]{x13_dictionary()}}). +See example.} + +\item{cmp_ids}{A \code{list} of \code{list} to specify the component whose history is to be studied. +Each sub-list must contain three elements: +\code{start} (first date to compute the history, in the format \code{"YYYY-MM-DD"}), +\code{end} (last date to compute the history, in the format \code{"YYYY-MM-DD"}) +and \code{id} (the name of the component, see \code{\link[=x13_dictionary]{x13_dictionary()}}). +As many series as periods between \code{start} and \code{end} will be exported. +See example.} + +\item{context}{The context of the specification.} +} +\description{ +Compute revisions history +} +\examples{ +s <- rjd3toolkit::ABS$X0.2.09.10.M +sa_mod <- x13(s) +data_ids <- list( + # Get the coefficient of the trading-day coefficient from 2005-jan + list(start = "2005-01-01", id = "regression.td(1)"), + # Get the ljung-box statistics on residuals from 2010-jan + list(start = "2010-01-01", id = "residuals.lb")) +ts_ids <- list( + # Get the SA component estimates of 2010-jan from 2010-jan + list(period = "2010-01-01", start = "2010-01-01", id = "sa"), + # Get the irregular component estimates of 2010-jan from 2015-jan + list(period = "2010-01-01", start = "2015-01-01", id = "i")) +cmp_ids <- list( + # Get the SA component estimates (full time series) 2010-jan to 2020-jan + list(start = "2010-01-01", end = "2020-01-01", id = "sa"), + # Get the trend component estimates (full time series) 2010-jan to 2020-jan + list(start = "2010-01-01", end = "2020-01-01", id = "t")) +rh <- x13_revisions(s, sa_mod$result_spec, data_ids, ts_ids, cmp_ids) +} diff --git a/man/x13_spec.Rd b/man/x13_spec.Rd new file mode 100644 index 0000000..d29f298 --- /dev/null +++ b/man/x13_spec.Rd @@ -0,0 +1,58 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/x13_spec.R +\name{x13_spec} +\alias{x13_spec} +\alias{regarima_spec} +\alias{x11_spec} +\title{RegARIMA/X-13 Default Specifications} +\usage{ +regarima_spec(name = c("rg4", "rg0", "rg1", "rg2c", "rg3", "rg5c")) + +x13_spec(name = c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c")) + +x11_spec() +} +\arguments{ +\item{name}{the name of a predefined specification.} +} +\value{ +an object of class \code{"JD3_X13_SPEC"} (\code{x13_spec()}), +\code{"JD3_REGARIMA_SPEC"} (\code{regarima_spec()}) or +\code{"JD3_X11_SPEC"} (\code{x11_spec()}). +} +\description{ +Set of functions to create default specification objects associated with the X-13ARIMA seasonal adjustment method. +} +\details{ +Specification setting of sheer X-11 decomposition method (without reg-arima pre-adjustment) is supported by the \code{x11_spec()} function only +and doesn't appear among the possible X13-Arima default specifications + +Specification setting can be restricted to the reg-arima part with the \code{regarima_spec()} function, +without argument \code{regarima_spec()} yields a RG5c specification + +When setting a complete X13-Arima spec, \code{x13_spec()} without argument yields a RSA5c specification + +The available predefined 'JDemetra+' model specifications are described in the table below: + +\tabular{rrrrrrr}{ +\strong{Identifier} |\tab \strong{Log/level detection} |\tab \strong{Outliers detection} |\tab \strong{Calendar effects} |\tab \strong{ARIMA}\cr +RSA0/RG0 |\tab \emph{NA} |\tab \emph{NA} |\tab \emph{NA} |\tab Airline(+mean)\cr +RSA1/RG1 |\tab automatic |\tab AO/LS/TC |\tab \emph{NA} |\tab Airline(+mean)\cr +RSA2c/RG2c |\tab automatic |\tab AO/LS/TC |\tab 2 td vars + Easter |\tab Airline(+mean)\cr +RSA3/RG3 |\tab automatic |\tab AO/LS/TC |\tab \emph{NA} |\tab automatic\cr +RSA4c/RG4c |\tab automatic |\tab AO/LS/TC |\tab 2 td vars + Easter |\tab automatic\cr +RSA5c/RG5c |\tab automatic |\tab AO/LS/TC |\tab 7 td vars + Easter |\tab automatic +} +#' @seealso +\itemize{ +\item To set the pre-processing parameters: \code{\link[rjd3toolkit:set_arima]{rjd3toolkit::set_arima()}}, \code{\link[rjd3toolkit:set_automodel]{rjd3toolkit::set_automodel()}}, \code{\link[rjd3toolkit:set_basic]{rjd3toolkit::set_basic()}}, \code{\link[rjd3toolkit:set_easter]{rjd3toolkit::set_easter()}}, \code{\link[rjd3toolkit:set_estimate]{rjd3toolkit::set_estimate()}}, \code{\link[rjd3toolkit:set_outlier]{rjd3toolkit::set_outlier()}}, \code{\link[rjd3toolkit:set_tradingdays]{rjd3toolkit::set_tradingdays()}}, \code{\link[rjd3toolkit:set_transform]{rjd3toolkit::set_transform()}}, \code{\link[rjd3toolkit:add_outlier]{rjd3toolkit::add_outlier()}}, \code{\link[rjd3toolkit:add_outlier]{rjd3toolkit::remove_outlier()}}, \code{\link[rjd3toolkit:add_outlier]{rjd3toolkit::add_ramp()}}, \code{\link[rjd3toolkit:add_outlier]{rjd3toolkit::remove_ramp()}}, \code{\link[rjd3toolkit:add_usrdefvar]{rjd3toolkit::add_usrdefvar()}}. +\item To set the decomposition parameters: \code{\link[=set_x11]{set_x11()}}. +\item To set the benchmarking parameters: \code{\link[rjd3toolkit:set_benchmarking]{rjd3toolkit::set_benchmarking()}}. +} +} +\examples{ +init_spec <- x11_spec() +init_spec <- regarima_spec("rg4") +init_spec <- x13_spec("rsa5c") + +}