Skip to content

Commit

Permalink
v3.1.0
Browse files Browse the repository at this point in the history
v3.1.0
  • Loading branch information
palatej authored Oct 11, 2023
2 parents b56486d + 4631f54 commit da61dfa
Show file tree
Hide file tree
Showing 29 changed files with 496 additions and 253 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
^.*\.Rproj$
^\.Rproj\.user$
^README\.Rmd$
10 changes: 6 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"),
Expand All @@ -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
Expand All @@ -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'
13 changes: 10 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions R/deprecated.R
Original file line number Diff line number Diff line change
@@ -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)
}
29 changes: 15 additions & 14 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,",
Expand All @@ -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", ...)
)
),
Expand All @@ -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))
}

Expand Down Expand Up @@ -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 = "")

Expand Down Expand Up @@ -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))
}
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/regarima_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
92 changes: 92 additions & 0 deletions R/revisions.R
Original file line number Diff line number Diff line change
@@ -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))
}
9 changes: 5 additions & 4 deletions R/set_x11_spec.R
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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"),
Expand Down
6 changes: 3 additions & 3 deletions R/udvar.R
Original file line number Diff line number Diff line change
Expand Up @@ -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() |>
Expand Down Expand Up @@ -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() |>
Expand Down Expand Up @@ -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)) |>
Expand Down
Loading

0 comments on commit da61dfa

Please sign in to comment.