Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint indentation #60

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,28 +1,9 @@
linters: linters_with_defaults(
indentation_linter = lintr::indentation_linter(indent = 4L),
# line_length_linter = lintr::line_length_linter(80L),
line_length_linter = lintr::line_length_linter(500L),
indentation_linter = NULL,
assignment_linter = NULL,
trailing_blank_lines_linter = NULL,
trailing_whitespace_linter = NULL,
whitespace_linter = NULL,
brace_linter = NULL,
infix_spaces_linter = NULL,
paren_body_linter = NULL,
indentation_linter = NULL,
function_left_parentheses_linter = NULL,
spaces_left_parentheses_linter = NULL,
commas_linter = NULL,
quotes_linter = NULL,
spaces_inside_linter = NULL,
vector_logic_linter = NULL,
seq_linter = NULL,
object_length_linter = NULL,
semicolon_linter = NULL,
cyclocomp_linter = NULL,
object_usage_linter = NULL,
object_name_linter = NULL,
commented_code_linter = NULL
line_length_linter = lintr::line_length_linter(150L),
# cyclocomp_linter = lintr::cyclocomp_linter(complexity_limit = 15L),
cyclocomp_linter = lintr::cyclocomp_linter(complexity_limit = 50L),
object_name_linter = NULL
)
encoding: "UTF-8"
10 changes: 8 additions & 2 deletions R/deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@ spec_x11 <- function() {
}
#' @name deprecated-rjd3x13
#' @export
fast_x13 <- function(ts, spec = c("rsa4", "rsa0", "rsa1", "rsa2c", "rsa3", "rsa5c"), context = NULL, userdefined = NULL) {
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) {
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)
}
33 changes: 26 additions & 7 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ summary.JD3_X13_OUTPUT <- function(object, ...) {
}

#' @export
print.summary.JD3_X13_RSLTS <- function(x, digits = max(3L, getOption("digits") - 3L), signif.stars = getOption("show.signif.stars"), ...) {
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 = "")
Expand All @@ -105,7 +108,9 @@ print.summary.JD3_X13_RSLTS <- function(x, digits = max(3L, getOption("digits")
}

#' @export
print.JD3_X13_OUTPUT <- function(x, digits = max(3L, getOption("digits") - 3L), summary_info = getOption("summary_info"),
print.JD3_X13_OUTPUT <- function(x,
digits = max(3L, getOption("digits") - 3L),
summary_info = getOption("summary_info"),
...) {
print(x$result, digits = digits, summary_info = summary_info, ...)
return(invisible(x))
Expand Down Expand Up @@ -365,11 +370,25 @@ print.JD3_X13_SPEC <- function(x, ...) {
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 = "")
cat("Target: ", x$benchmarking$target,
ifelse(
test = x$benchmarking$target == "TARGET_CALENDARADJUSTED",
yes = " (Auto)",
no = ""
),
"\n", sep = "")
cat("Lambda: ", x$benchmarking$lambda,
ifelse(test = x$benchmarking$lambda == 1, yes = " (Auto)", no = ""),
"\n", sep = "")
cat("Rho: ", x$benchmarking$rho,
ifelse(test = x$benchmarking$rho == 1, yes = " (Auto)", no = ""),
"\n", sep = "")
cat("Bias: ", x$benchmarking$bias,
ifelse(test = x$benchmarking$bias == "BIAS_NONE", yes = " (Auto)", no = ""),
"\n", sep = "")
cat("Use forecast: ",
ifelse(test = x$benchmarking$forecast, yes = "Yes", no = "No (Auto)"),
"\n", sep = "")
}

return(invisible(x))
Expand Down
33 changes: 23 additions & 10 deletions R/regarima_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,46 @@ NULL
#' @param mean Boolean to include or not the mean.
#' @param X user defined regressors (other than calendar).
#' @param X.td calendar regressors.
#' @param ao,ls,so,tc Boolean to indicate which type of outliers should be detected.
#' @param cv `numeric`. The entered critical value for the outlier detection procedure.
#' If equal to 0 the critical value for the outlier detection procedure is automatically determined
#' by the number of observations.
#' @param clean Clean missing values at the beginning/end of the series. Regression variables are automatically resized, if need be.
#' @param ao,ls,so,tc Boolean to indicate which type of outliers should be
#' detected.
#' @param cv `numeric`. The entered critical value for the outlier detection
#' procedure. If equal to 0 the critical value for the outlier detection
#' procedure is automatically determined by the number of observations.
#' @param clean Clean missing values at the beginning/end of the series.
#' Regression variables are automatically resized, if need be.
#'
#' @return a `"JD3_REGARIMA_OUTLIERS"` object, containing input variables and results
#'
#' @examples
#' regarima_outliers(rjd3toolkit::ABS$X0.2.09.10.M)
#'
#' @export
regarima_outliers <- function(y, order = c(0L, 1L, 1L), seasonal = c(0L, 1L, 1L), mean = FALSE,
X = NULL, X.td = NULL, ao = TRUE, ls = TRUE, tc = FALSE, so = FALSE, cv = 0, clean = FALSE) {
regarima_outliers <- function(y,
order = c(0L, 1L, 1L),
seasonal = c(0L, 1L, 1L),
mean = FALSE,
X = NULL,
X.td = NULL,
ao = TRUE,
ls = TRUE,
tc = FALSE,
so = FALSE,
cv = 0,
clean = FALSE) {
if (!is.ts(y)) {
stop("y must be a time series")
}
if (!is.null(X.td)) {
sy <- start(y)
td <- rjd3toolkit::td(s = y, groups = X.td)
X <- cbind(X, td)
}


jregarima <- .jcall(
"jdplus/x13/base/r/RegArimaOutliersDetection", "Ljdplus/x13/base/r/RegArimaOutliersDetection$Results;", "process",
rjd3toolkit::.r2jd_tsdata(y), as.integer(order), as.integer(seasonal), mean, rjd3toolkit::.r2jd_matrix(X),
"jdplus/x13/base/r/RegArimaOutliersDetection",
"Ljdplus/x13/base/r/RegArimaOutliersDetection$Results;", "process",
rjd3toolkit::.r2jd_tsdata(y), as.integer(order), as.integer(seasonal),
mean, rjd3toolkit::.r2jd_matrix(X),
ao, ls, tc, so, cv, clean
)
model <- list(
Expand Down
6 changes: 4 additions & 2 deletions R/revisions.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,17 @@ x13_revisions <- function(ts, spec, data_ids = NULL, ts_ids = NULL, cmp_ids = NU
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)
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)
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")
Expand Down
105 changes: 64 additions & 41 deletions R/set_x11_spec.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,57 @@
#' 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=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;
#' @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;
#' `"Multiplicative"` - assumes a multiplicative relationship;
#' `"LogAdditive"` - performs an additive decomposition of the logarithms of the series being adjusted;
#' `"PseudoAdditive"` - assumes an pseudo-additive relationship. Could be changed by the program, if needed.
#' @param seasonal.comp logical: if `TRUE`, the program computes a seasonal component. Otherwise, the seasonal component
#' is not estimated and its values are all set to 0 (additive decomposition) or 1 (multiplicative decomposition).
#' @param lsigma numeric: the lower sigma boundary for the detection of extreme values, > 0.5, default=1.5.
#' @param usigma numeric: the upper sigma boundary for the detection of extreme values, > lsigma, default=2.5.
#' @param henderson.filter numeric: the length of the Henderson filter (odd number between 3 and 101). If `henderson.filter = 0` an automatic selection of the Henderson filter's length
#' for the trend estimation is enabled.
#' @param seasonal.filter a vector of character(s) specifying which seasonal moving average (i.e. seasonal filter)
#' will be used to estimate the seasonal factors for the entire series. The vector can be of length:
#' 1 - the same seasonal filter is used for all periods (e.g.: `seasonal.filter = "Msr"` or `seasonal.filter = "S3X3"` );
#' or have a different value for each quarter (length 4) or each month (length 12) - (e.g. for quarterly series: `seasonal.filter = c("S3X3", "Msr", "S3X3", "Msr")`).
#' Possible filters are: `"Msr"`, `"Stable"`, `"X11Default"`, `"S3X1"`, `"S3X3"`, `"S3X5"`, `"S3X9"`, `"S3X15"`.
#' `"Msr"` - the program chooses the final seasonal filter automatically.
#' @param bcasts,fcasts numeric: the number of backasts (`bcasts`) or forecasts (`fcasts`) generated by the RegARIMA model in periods (positive values) or years (negative values).Default values: fcasts=-1 and bcasts=0.
#' @param calendar.sigma character to specify if the standard errors used for extreme values detection and adjustment are computed:
#' from 5 year spans of irregulars (`"None"`, default value);
#' separately for each calendar period (`"All"`);
#' separately for each period only if Cochran's hypothesis test determines that the irregular component is heteroskedastic
#' by calendar month/quarter (`"Signif"`);
#' separately for two complementary sets of calendar months/quarters specified by the x11.sigmaVector parameter (`"Select"`,
#' see parameter `sigma.vector`).
#' @param sigma.vector a vector to specify one of the two groups of periods for which standard errors used for extreme values
#' 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.
#' `"LogAdditive"` - performs an additive decomposition of the logarithms of the
#' series being adjusted;
#' `"PseudoAdditive"` - assumes an pseudo-additive relationship. Could be
#' changed by the program, if needed.
#' @param seasonal.comp logical: if `TRUE`, the program computes a seasonal
#' component. Otherwise, the seasonal component is not estimated and its values
#' are all set to 0 (additive decomposition) or 1 (multiplicative
#' decomposition).
#' @param lsigma numeric: the lower sigma boundary for the detection of extreme
#' values, > 0.5, default=1.5.
#' @param usigma numeric: the upper sigma boundary for the detection of extreme
#' values, > lsigma, default=2.5.
#' @param henderson.filter numeric: the length of the Henderson filter (odd
#' number between 3 and 101). If `henderson.filter = 0` an automatic selection
#' of the Henderson filter's length for the trend estimation is enabled.
#' @param seasonal.filter a vector of character(s) specifying which seasonal
#' moving average (i.e. seasonal filter) will be used to estimate the seasonal
#' factors for the entire series. The vector can be of length: 1 - the same
#' seasonal filter is used for all periods (e.g.: `seasonal.filter = "Msr"` or
#' `seasonal.filter = "S3X3"` ); or have a different value for each quarter
#' (length 4) or each month (length 12) - (e.g. for quarterly series:
#' `seasonal.filter = c("S3X3", "Msr", "S3X3", "Msr")`). Possible filters are:
#' `"Msr"`, `"Stable"`, `"X11Default"`, `"S3X1"`, `"S3X3"`, `"S3X5"`, `"S3X9"`,
#' `"S3X15"`. `"Msr"` - the program chooses the final seasonal filter
#' automatically.
#' @param bcasts,fcasts numeric: the number of backasts (`bcasts`) or forecasts
#' (`fcasts`) generated by the RegARIMA model in periods (positive values) or
#' years (negative values).Default values: fcasts=-1 and bcasts=0.
#' @param calendar.sigma character to specify if the standard errors used for
#' extreme values detection and adjustment are computed: from 5 year spans of
#' irregulars (`"None"`, default value); separately for each calendar period
#' (`"All"`); separately for each period only if Cochran's hypothesis test
#' determines that the irregular component is heteroskedastic by calendar
#' month/quarter (`"Signif"`); separately for two complementary sets of calendar
#' months/quarters specified by the x11.sigmaVector parameter (`"Select"`, see
#' parameter `sigma.vector`).
#' @param sigma.vector a vector to specify one of the two groups of periods for
#' which standard errors used for extreme values 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.
#' @seealso [x13_spec()] and [x11_spec()].
Expand Down Expand Up @@ -67,19 +89,20 @@ set_x11 <- function(x,
UseMethod("set_x11", x)
}
#' @export
set_x11.JD3_X11_SPEC <- function(x,
mode = c(NA, "Undefined", "Additive", "Multiplicative", "LogAdditive", "PseudoAdditive"),
seasonal.comp = NA,
seasonal.filter = NA,
henderson.filter = NA,
lsigma = NA,
usigma = NA,
fcasts = NA,
bcasts = NA,
calendar.sigma = c(NA, "None", "Signif", "All", "Select"),
sigma.vector = NA,
exclude.forecast = NA,
bias = c(NA, "LEGACY")) {
set_x11.JD3_X11_SPEC <- function(
x,
mode = c(NA, "Undefined", "Additive", "Multiplicative", "LogAdditive", "PseudoAdditive"),
seasonal.comp = NA,
seasonal.filter = NA,
henderson.filter = NA,
lsigma = NA,
usigma = NA,
fcasts = NA,
bcasts = NA,
calendar.sigma = c(NA, "None", "Signif", "All", "Select"),
sigma.vector = NA,
exclude.forecast = NA,
bias = c(NA, "LEGACY")) {
mode <- match.arg(
toupper(mode[1]),
c(
Expand Down
Loading
Loading