diff --git a/DESCRIPTION b/DESCRIPTION index b2d332e..357c4ae 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,7 +27,7 @@ Remotes: SystemRequirements: Java (>= 17) License: EUPL URL: https://github.com/rjdverse/rjd3x13, https://rjdverse.github.io/rjd3x13/ -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Roxygen: list(markdown = TRUE) BugReports: https://github.com/rjdverse/rjd3x13/issues Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE index 74050b8..d3eb6be 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,6 +23,7 @@ S3method(print,JD3_X11_SPEC) S3method(print,JD3_X13_OUTPUT) S3method(print,JD3_X13_RSLTS) S3method(print,JD3_X13_SPEC) +S3method(print,summary.JD3_X13_RSLTS) S3method(remove_outlier,JD3_X13_SPEC) S3method(remove_ramp,JD3_X13_SPEC) S3method(residuals,JD3_REGARIMA_OUTPUT) @@ -41,6 +42,8 @@ S3method(set_transform,JD3_X13_SPEC) S3method(set_x11,JD3_X11_SPEC) S3method(set_x11,JD3_X13_SPEC) S3method(summary,JD3_REGARIMA_OUTPUT) +S3method(summary,JD3_X13_OUTPUT) +S3method(summary,JD3_X13_RSLTS) S3method(vcov,JD3_REGARIMA_OUTPUT) S3method(vcov,JD3_X13_OUTPUT) export(.jd2r_spec_regarima) diff --git a/R/print.R b/R/print.R index 0f5829f..0897f6e 100644 --- a/R/print.R +++ b/R/print.R @@ -9,7 +9,7 @@ print_x11_decomp <- function(x, digits = max(3L, getOption("digits") - 3L), ...) printCoefmat(mstats, digits = digits, P.values= FALSE, na.print = "NA", ...) cat("\n") cat("Final filters:","\n") - cat("Seasonal filter: ",x$decomposition$final_seasonal) + cat(sprintf("Seasonal filter: S3X%s", x$decomposition$final_seasonal)) cat("\n") cat(sprintf("Trend filter: %s terms Henderson moving average", x$decomposition$final_henderson)) cat("\n") @@ -17,9 +17,8 @@ print_x11_decomp <- function(x, digits = max(3L, getOption("digits") - 3L), ...) } print_diagnostics <- function(x, digits = max(3L, getOption("digits") - 3L), ...){ - diagnostics <- rjd3toolkit::diagnostics(x) - variance_decomposition <- diagnostics$variance_decomposition - residual_tests <- diagnostics$residual_tests + variance_decomposition <- x$variance_decomposition + residual_tests <- x$residual_tests cat("Relative contribution of the components to the stationary", "portion of the variance in the original series,", @@ -47,203 +46,55 @@ print_diagnostics <- function(x, digits = max(3L, getOption("digits") - 3L), return(invisible(x)) } -print_final <- function(x, ...){ - print(rjd3toolkit::sa_decomposition(x), ...) - return(invisible(x)) -} #' @export -print.JD3_REGARIMA_SPEC <- function(x, ...) { - - cat("Specification", "\n", sep = "") - - - cat("\n", "Series", "\n", sep = "") - - cat("Serie span: ") - print(x$basic$span) - - cat("Preliminary Check: ", ifelse(x$basic$preliminaryCheck, "Yes", "No"), "\n", sep = "") - - - cat("\n", "Estimate", "\n", sep = "") - - cat("Model span: ") - print(x$estimate$span) - cat("\n") - cat("Tolerance: ", x$estimate$tol, "\n", sep = "") - - - cat("\n", "Transformation", "\n", sep = "") - - cat("Function: ", x$transform$fn, "\n", sep = "") - cat("AIC difference: ", x$transform$aicdiff, "\n", sep = "") - cat("Adjust: ", x$transform$adjust, "\n", sep = "") - - - cat("\n", "Regression", "\n", sep = "") - - if (!is.null(x$regression$td$users) && length(x$regression$td$users) > 0) { - cat("Calendar regressor: user-defined calendar", "\n", sep = "") - cat("Test: ", x$regression$td$test, "\n", sep = "") - } else if (x$regression$td$w > 0) { - cat("No calendar regressor", "\n", sep = "") - } else if (x$regression$td$td == "TD_NONE") { - cat("No calendar regressor", "\n", sep = "") - } else { - if (x$regression$td$td == "TD7") { - cat("Calendar regressor: TradingDays\n", sep = "") - } else if (x$regression$td$td == "TD2") { - cat("Calendar regressor: WorkingDays\n", sep = "") - } else if (x$regression$td$td %in% c("TD3", "TD3C", "TD4")) { - cat("Calendar regressor: ", x$regression$td$td, "\n", sep = "") - } else { - message("Trading days regressor unknown.") - } - cat("with Leap Year: ", - ifelse(x$regression$td$lp == "LEAPYEAR", "Yes", "No"), "\n", sep = "") - cat("AutoAdjust: ", x$regression$td$autoadjust, "\n", sep = "") - cat("Test: ", x$regression$td$test, "\n", sep = "") - } +print.JD3_X13_RSLTS <- function(x, digits = max(3L, getOption("digits") - 3L), summary_info = getOption("summary_info"), + ...){ + cat("Model: X-13\n") + print(x$preprocessing, digits = digits, summary_info = FALSE, ...) cat("\n") - - cat("Easter: ") - if (x$regression$easter$type == "UNUSED") { - cat("No\n") - } else { - cat(x$regression$easter$type, "\n") - cat("Duration:", x$regression$easter$duration, ifelse(x$regression$easter$duration == 8, "(Auto)", ""), "\n") - cat("Test:", x$regression$easter$test, ifelse(x$regression$easter$test == "ADD", "(Auto)", ""), "\n") - - if (!is.null(x$regression$easter$coef)) { - cat("Coef:\n") - cat("\t- Type:", x$regression$easter$coefficient$type, - ifelse(x$regression$easter$coefficient$type == "FIXED", "(Auto)", ""), "\n") - cat("\t- Value:", x$regression$easter$coefficient$value, "\n") - } - } - + cat(sprintf("Seasonal filter: S3X%s", x$decomposition$final_seasonal)) cat("\n") - - cat("Pre-specified outliers: ", length(x$regression$outliers), "\n", sep = "") - if (!is.null(x$regression$outliers) && length(x$regression$outliers) > 0) { - for (out in x$regression$outliers) { - cat("\t- ", out$name, - ifelse(is.null(out$coef), "", paste0(", coefficient: ", out$coef$value, " (", out$coef$type, ")")), - "\n", sep = "") - } - } - cat("Ramps: ") - if (!is.null(x$regression$ramps) && length(x$regression$ramps) > 0) { - cat("\n") - for (ramp in x$regression$ramps) { - cat("\t- start: ", ramp$start, ", end : ", ramp$end, - ifelse(is.null(ramp$coef), "", paste0(", coefficient: ", ramp$coef, " (", ramp$coef$type, ")")), sep = "") - cat("\n") - } - } else { - cat("No\n") - } - - if (!is.null(x$regression$users) && length(x$regression$users) > 0) { - cat("User-defined variables:\n") - for (uv in x$regression$users) { - cat("\t-", uv$name, - ifelse(is.null(uv$coef), "", paste0(", coefficient: ", uv$coef)), - ", component: ", uv$regeffect, "\n", sep = "") - } - } - - cat("\n", "Outliers", "\n", sep = "") - - if (is.null(x$outlier$outliers) || length(x$outlier$outliers) == 0) { - cat("Is enabled: No\n") - } else { - cat("Detection span: ") - print(x$outlier$span) - - cat("Outliers type: \n") - for (out in x$outlier$outliers) { - cat("\t- ", out$type, ", critical value : ", out$va, ifelse(out$va == 0, " (Auto)", ""), "\n", sep = "") - } - - cat("TC rate: ", x$outlier$monthlytcrate, ifelse(x$outlier$monthlytcrate == 0.7, " (Auto)", ""), "\n", sep = "") - cat("Method: ", x$outlier$method, ifelse(x$outlier$method == "ADDONE", " (Auto)", ""), "\n", sep = "") - } - - - cat("\n", "ARIMA", "\n", sep = "") - - print(x$arima) - + cat(sprintf("Trend filter: %s terms Henderson moving average\n", x$decomposition$final_henderson)) + if (summary_info) + cat("\nFor a more detailed output, use the 'summary()' function.\n") return(invisible(x)) } #' @export -print.JD3_X11_SPEC <- function(x, ...) { - - cat("Specification X11", "\n", sep = "") - - - cat("Seasonal component: ", ifelse(x$seasonal, "Yes", "No"), "\n", sep = "") - cat("Length of the Henderson filter: ", x$henderson, "\n", sep = "") - cat("Seasonal filter: ", x$sfilters, "\n", sep = "") - cat("Boundaries used for extreme values correction :", - "\n\t lower_sigma: ", x$lsig, - "\n\t upper_sigma: ", x$usig) - cat("\n") - cat("Nb of forecasts: ", x$nfcasts, "\n", sep = "") - cat("Nb of backcasts: ", x$nbcasts, "\n", sep = "") - cat("Calendar sigma: ", x$sigma, "\n", sep = "") - - return(invisible(x)) +summary.JD3_X13_RSLTS <- function(object, ...){ + x <- list(preprocessing = summary(object$preprocessing), + decomposition = object[c("mstats", "decomposition")], + diagnostics = rjd3toolkit::diagnostics(object), + final = rjd3toolkit::sa_decomposition(object) + ) + class(x) <- "summary.JD3_X13_RSLTS" + return(x) } #' @export -print.JD3_X13_SPEC <- function(x, ...) { - - print(x$regarima) - - cat("\n") - - print(x$x11) - - cat("\n", "Benchmarking", "\n", sep = "") - - if (!x$benchmarking$enabled) { - cat("Is enabled: No\n") - } else { - cat("Enabled: Yes\n", sep = "") - cat("Target: ", x$benchmarking$target, ifelse(x$benchmarking$target == "TARGET_CALENDARADJUSTED", " (Auto)", ""), "\n", sep = "") - cat("Lambda: ", x$benchmarking$lambda, ifelse(x$benchmarking$lambda == 1, " (Auto)", ""), "\n", sep = "") - cat("Rho: ", x$benchmarking$rho, ifelse(x$benchmarking$rho == 1, " (Auto)", ""), "\n", sep = "") - cat("Bias: ", x$benchmarking$bias, ifelse(x$benchmarking$bias == "BIAS_NONE", " (Auto)", ""), "\n", sep = "") - cat("Use forecast: ", ifelse(x$benchmarking$forecast, "Yes", "No (Auto)"), "\n", sep = "") - } - - return(invisible(x)) +summary.JD3_X13_OUTPUT <- function(object, ...){ + summary(object$result, ...) } #' @export -print.JD3_X13_RSLTS <- function(x, digits = max(3L, getOption("digits") - 3L), - ...){ - - cat("RegARIMA","\n",sep="") - print(x$preprocessing, digits = digits, ...) - cat("\n", "Decomposition","\n",sep="") - print_x11_decomp(x, digits = digits, ...) - cat("\n", "Diagnostics","\n",sep="") - print_diagnostics(x, digits = digits, ...) - cat("\n", "Final","\n",sep="") - print_final(x, digits = digits, ...) - return(invisible(x)) +print.summary.JD3_X13_RSLTS <- function(x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ...){ + cat("Model: X-13\n") + print(x$preprocessing, digits = digits, signif.stars = signif.stars, ...) + cat("\n", "Decomposition","\n",sep="") + print_x11_decomp(x$decomposition, digits = digits, ...) + cat("\n", "Diagnostics","\n",sep="") + print_diagnostics(x$diagnostics, digits = digits, ...) + cat("\n", "Final","\n",sep="") + print(x$final, digits = digits, ...) + return(invisible(x)) } #' @export -print.JD3_X13_OUTPUT<- function(x, digits = max(3L, getOption("digits") - 3L), +print.JD3_X13_OUTPUT<- function(x, digits = max(3L, getOption("digits") - 3L), summary_info = getOption("summary_info"), ...){ - print(x$result, digits = digits, ...) + print(x$result, digits = digits, summary_info = summary_info, ...) return(invisible(x)) } @@ -310,3 +161,177 @@ diagnostics.JD3_X13_RSLTS<-function(x, ...){ diagnostics.JD3_X13_OUTPUT<-function(x, ...){ return(rjd3toolkit::diagnostics(x$result, ...)) } + + +#' @export +print.JD3_REGARIMA_SPEC <- function(x, ...) { + + cat("Specification", "\n", sep = "") + + + cat("\n", "Series", "\n", sep = "") + + cat("Serie span: ") + print(x$basic$span) + + cat("Preliminary Check: ", ifelse(x$basic$preliminaryCheck, "Yes", "No"), "\n", sep = "") + + + cat("\n", "Estimate", "\n", sep = "") + + cat("Model span: ") + print(x$estimate$span) + cat("\n") + cat("Tolerance: ", x$estimate$tol, "\n", sep = "") + + + cat("\n", "Transformation", "\n", sep = "") + + cat("Function: ", x$transform$fn, "\n", sep = "") + cat("AIC difference: ", x$transform$aicdiff, "\n", sep = "") + cat("Adjust: ", x$transform$adjust, "\n", sep = "") + + + cat("\n", "Regression", "\n", sep = "") + + if (!is.null(x$regression$td$users) && length(x$regression$td$users) > 0) { + cat("Calendar regressor: user-defined calendar", "\n", sep = "") + cat("Test: ", x$regression$td$test, "\n", sep = "") + } else if (x$regression$td$w > 0) { + cat("No calendar regressor", "\n", sep = "") + } else if (x$regression$td$td == "TD_NONE") { + cat("No calendar regressor", "\n", sep = "") + } else { + if (x$regression$td$td == "TD7") { + cat("Calendar regressor: TradingDays\n", sep = "") + } else if (x$regression$td$td == "TD2") { + cat("Calendar regressor: WorkingDays\n", sep = "") + } else if (x$regression$td$td %in% c("TD3", "TD3C", "TD4")) { + cat("Calendar regressor: ", x$regression$td$td, "\n", sep = "") + } else { + message("Trading days regressor unknown.") + } + cat("with Leap Year: ", + ifelse(x$regression$td$lp == "LEAPYEAR", "Yes", "No"), "\n", sep = "") + cat("AutoAdjust: ", x$regression$td$autoadjust, "\n", sep = "") + cat("Test: ", x$regression$td$test, "\n", sep = "") + } + + cat("\n") + + cat("Easter: ") + if (x$regression$easter$type == "UNUSED") { + cat("No\n") + } else { + cat(x$regression$easter$type, "\n") + cat("Duration:", x$regression$easter$duration, ifelse(x$regression$easter$duration == 8, "(Auto)", ""), "\n") + cat("Test:", x$regression$easter$test, ifelse(x$regression$easter$test == "ADD", "(Auto)", ""), "\n") + + if (!is.null(x$regression$easter$coef)) { + cat("Coef:\n") + cat("\t- Type:", x$regression$easter$coefficient$type, + ifelse(x$regression$easter$coefficient$type == "FIXED", "(Auto)", ""), "\n") + cat("\t- Value:", x$regression$easter$coefficient$value, "\n") + } + } + + cat("\n") + + cat("Pre-specified outliers: ", length(x$regression$outliers), "\n", sep = "") + if (!is.null(x$regression$outliers) && length(x$regression$outliers) > 0) { + for (out in x$regression$outliers) { + cat("\t- ", out$name, + ifelse(is.null(out$coef), "", paste0(", coefficient: ", out$coef$value, " (", out$coef$type, ")")), + "\n", sep = "") + } + } + cat("Ramps: ") + if (!is.null(x$regression$ramps) && length(x$regression$ramps) > 0) { + cat("\n") + for (ramp in x$regression$ramps) { + cat("\t- start: ", ramp$start, ", end : ", ramp$end, + ifelse(is.null(ramp$coef), "", paste0(", coefficient: ", ramp$coef, " (", ramp$coef$type, ")")), sep = "") + cat("\n") + } + } else { + cat("No\n") + } + + if (!is.null(x$regression$users) && length(x$regression$users) > 0) { + cat("User-defined variables:\n") + for (uv in x$regression$users) { + cat("\t-", uv$name, + ifelse(is.null(uv$coef), "", paste0(", coefficient: ", uv$coef)), + ", component: ", uv$regeffect, "\n", sep = "") + } + } + + cat("\n", "Outliers", "\n", sep = "") + + if (is.null(x$outlier$outliers) || length(x$outlier$outliers) == 0) { + cat("Is enabled: No\n") + } else { + cat("Detection span: ") + print(x$outlier$span) + + cat("Outliers type: \n") + for (out in x$outlier$outliers) { + cat("\t- ", out$type, ", critical value : ", out$va, ifelse(out$va == 0, " (Auto)", ""), "\n", sep = "") + } + + cat("TC rate: ", x$outlier$monthlytcrate, ifelse(x$outlier$monthlytcrate == 0.7, " (Auto)", ""), "\n", sep = "") + cat("Method: ", x$outlier$method, ifelse(x$outlier$method == "ADDONE", " (Auto)", ""), "\n", sep = "") + } + + + cat("\n", "ARIMA", "\n", sep = "") + + print(x$arima) + + return(invisible(x)) +} + +#' @export +print.JD3_X11_SPEC <- function(x, ...) { + + cat("Specification X11", "\n", sep = "") + + + cat("Seasonal component: ", ifelse(x$seasonal, "Yes", "No"), "\n", sep = "") + cat("Length of the Henderson filter: ", x$henderson, "\n", sep = "") + cat("Seasonal filter: ", x$sfilters, "\n", sep = "") + cat("Boundaries used for extreme values correction :", + "\n\t lower_sigma: ", x$lsig, + "\n\t upper_sigma: ", x$usig) + cat("\n") + cat("Nb of forecasts: ", x$nfcasts, "\n", sep = "") + cat("Nb of backcasts: ", x$nbcasts, "\n", sep = "") + cat("Calendar sigma: ", x$sigma, "\n", sep = "") + + return(invisible(x)) +} + +#' @export +print.JD3_X13_SPEC <- function(x, ...) { + + print(x$regarima) + + cat("\n") + + print(x$x11) + + cat("\n", "Benchmarking", "\n", sep = "") + + if (!x$benchmarking$enabled) { + cat("Is enabled: No\n") + } else { + cat("Enabled: Yes\n", sep = "") + cat("Target: ", x$benchmarking$target, ifelse(x$benchmarking$target == "TARGET_CALENDARADJUSTED", " (Auto)", ""), "\n", sep = "") + cat("Lambda: ", x$benchmarking$lambda, ifelse(x$benchmarking$lambda == 1, " (Auto)", ""), "\n", sep = "") + cat("Rho: ", x$benchmarking$rho, ifelse(x$benchmarking$rho == 1, " (Auto)", ""), "\n", sep = "") + cat("Bias: ", x$benchmarking$bias, ifelse(x$benchmarking$bias == "BIAS_NONE", " (Auto)", ""), "\n", sep = "") + cat("Use forecast: ", ifelse(x$benchmarking$forecast, "Yes", "No (Auto)"), "\n", sep = "") + } + + return(invisible(x)) +} diff --git a/R/regarima_generic.R b/R/regarima_generic.R index 535868c..e222eca 100644 --- a/R/regarima_generic.R +++ b/R/regarima_generic.R @@ -25,11 +25,14 @@ residuals.JD3_REGARIMA_OUTPUT <- function(object, ...){ } #' @export summary.JD3_REGARIMA_OUTPUT <- function(object, ...){ - summary(object$result, ...) + x <- summary(object$result, ...) + x$method <- "RegARIMA" + x } #' @export -print.JD3_REGARIMA_OUTPUT <- function(x, ...){ - print(x$result, ...) +print.JD3_REGARIMA_OUTPUT <- function(x, summary_info = getOption("summary_info"), ...){ + cat("Method: RegARIMA\n") + print(x$result, summary_info = summary_info, ...) } #' @export diagnostics.JD3_REGARIMA_OUTPUT <- function(x, ...){ diff --git a/R/zzz.R b/R/zzz.R index 98b6f17..3fedb63 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -7,7 +7,7 @@ if (!requireNamespace("rjd3toolkit", quietly = TRUE)) stop("Loading rjd3 libraries failed") - result <- .jpackage(pkgname, lib.loc=libname) + result <- .jpackage(pkgname, lib.loc=libname) if (!result) stop("Loading java packages failed") proto.dir <- system.file("proto", package = pkgname) @@ -15,5 +15,6 @@ # reload extractors rjd3toolkit::reload_dictionaries() - + if(is.null(getOption("summary_info"))) + options(summary_info = TRUE) }