From 5e35c32307a68194636228757e7d00ecd2a8abcf Mon Sep 17 00:00:00 2001 From: AQLT Date: Sat, 2 Mar 2024 20:55:28 +0100 Subject: [PATCH] ramp correction when frequency != 12 --- NEWS.md | 2 ++ R/utils.R | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index d3155ed3..84c995f6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ - possibility to export X-11 some components: `y_cmp`, `y_cmp_f`, `t_cmp`, `t_cmp_f`, `sa_cmp`, `s_cmp`, `s_cmp_f`, and `i_cmp`. +- correction when importing models containing ramp regressors when the frequency is not 12 (monthly). + # RJDemetra 0.2.5 diff --git a/R/utils.R b/R/utils.R index 34cbd283..bfc22bdb 100644 --- a/R/utils.R +++ b/R/utils.R @@ -8,10 +8,18 @@ identical_na <- function(x){ } -ramp <- function(start = 1990, end = 2020, +ramp <- function(start = 1900, end = 2100, start_ramp, end_ramp, frequency = 12){ start <- format_ts_date(start, frequency) end <- format_ts_date(end, frequency) + # start_ramp and end_ramp are defined in month and not in the frequency of the model + new_period <- rep(seq.int(from = 1, to = frequency), each = 12 / frequency) + if (length(start_ramp) == 2) { + start_ramp[2] <- new_period[start_ramp[2]] + } + if (length(end_ramp) == 2) { + end_ramp[2] <- new_period[end_ramp[2]] + } start_ramp <- format_ts_date(start_ramp, frequency) end_ramp <- format_ts_date(end_ramp, frequency) @@ -20,7 +28,7 @@ ramp <- function(start = 1990, end = 2020, if (missing(start) || missing(end)) { # if start and end not specified by hand start <- min(start_ramp - 1, start) - end <- min(end_ramp + 1, end) + end <- max(end_ramp + 1, end) } x <- ts(-1, start = start, end = end,