From 4173c67db6dcb3ee99904ea5e3342b886abfee0c Mon Sep 17 00:00:00 2001 From: palatej Date: Thu, 18 Jul 2024 10:01:59 +0200 Subject: [PATCH 1/3] Documentation on (uc)arima models --- R/arima.R | 62 ++++++++++++++++++++++++++-------------- man/arima_difference.Rd | 14 +++++---- man/arima_properties.Rd | 2 +- man/ucarima_canonical.Rd | 4 ++- man/ucarima_estimate.Rd | 18 +++++++++--- man/ucarima_model.Rd | 21 ++++++++++++-- man/ucarima_wk.Rd | 21 ++++++++++++-- 7 files changed, 104 insertions(+), 38 deletions(-) diff --git a/R/arima.R b/R/arima.R index 47445da..476896e 100644 --- a/R/arima.R +++ b/R/arima.R @@ -185,21 +185,22 @@ arima_lsum<-function(components){ return(.jd2r_arima(jsum)) } -#' Remove an arima model from an existing one +#' Remove an arima model from an existing one. More exactly, m_diff = m_left - m_right iff m_left = m_right + m_diff. #' -#' @param left Left operand -#' @param right Right operand -#' @param simplify Simplify the results +#' @param left Left operand (JD3_ARIMA object) +#' @param right Right operand (JD3_ARIMA object) +#' @param simplify Simplify the results if possible (common roots in the auto-regressive and in the moving average polynomials) #' #' @return a `"JD3_ARIMA"` model. #' @export #' -#' @details #' #' @examples #' mod1 = arima_model(delta = c(1,-2,1)) #' mod2 = arima_model(variance=.01) -#' diff<- arima_difference(mod1, mod2) +#' diff <- arima_difference(mod1, mod2) +#' sum <- arima_sum(diff, mod2) +#' # sum should be equal to mod1 #' arima_difference<-function(left, right, simplify=TRUE){ jleft<-.r2jd_arima(left) @@ -216,7 +217,7 @@ arima_difference<-function(left, right, simplify=TRUE){ #' @param nacf maximum lag at which to calculate the acf. #' #' @examples -#' mod1 = arima_model(ar = c(0.1, 0.2), delta = 0, ma = 0) +#' mod1 <- arima_model(ar = c(0.1, 0.2), delta = 0, ma = 0) #' arima_properties(mod1) #' @export arima_properties<-function(model, nspectrum=601, nacf=36){ @@ -226,16 +227,21 @@ arima_properties<-function(model, nspectrum=601, nacf=36){ return(list(acf=acf, spectrum=spectrum)) } -#' Title +#' Creates an UCARIMA model, which is composed of ARIMA models with independent innovations. #' -#' @param model -#' @param components -#' @param complements Complements of (some) components +#' @param model The reduced model. Usually not provided. +#' @param components The ARIMA models representing the components +#' @param complements Complements of (some) components. Usually not provided +#' @param checkmodel When the model is provided and *checkmodel* is TRUE, we check that it indeed corresponds to the reduced form of the components; similar controls are applied on complements. Currently not implemented #' -#' @return +#' @return A list with the reduced model, the components and their complements #' @export #' #' @examples +#' mod1 <- arima_model("trend", delta = c(1,-2,1)) +#' mod2 <- arima_model("noise", var = 1600) +#' hp<-ucarima_model(components=list(mod1, mod2)) +#' print(hp$model) ucarima_model<-function(model=NULL, components, complements=NULL, checkmodel=FALSE){ if (is.null(model)) model<-arima_lsum(components) @@ -265,16 +271,22 @@ ucarima_model<-function(model=NULL, components, complements=NULL, checkmodel=FAL #' Wiener Kolmogorov Estimators #' -#' @param ucm UCARIMA model returned by [ucarima_model()]. -#' @param cmp -#' @param signal -#' @param nspectrum -#' @param nwk +#' @param ucm An UCARIMA model returned by [ucarima_model()]. +#' @param cmp Index of the component for which we want to compute the filter +#' @param signal TRUE for the signal (component), FALSE for the noise (complement) +#' @param nspectrum Number of points used to compute the (pseudo-) spectrum of the estimator +#' @param nwk Number of weights of the wiener-kolmogorov filter returned in the result #' -#' @return +#' @return A list with the (pseudo-)spectrum, the weights of the filter and the squared-gain function (with the same number of points as the spectrum) #' @export #' #' @examples +#' mod1 <- arima_model("trend", delta = c(1,-2,1)) +#' mod2 <- arima_model("noise", var = 1600) +#' hp<-ucarima_model(components=list(mod1, mod2)) +#' wk1<-ucarima_wk(hp, 1, nwk=50) +#' wk2<-ucarima_wk(hp, 2) +#' plot(wk1$filter, type='h') ucarima_wk<-function(ucm, cmp, signal=TRUE, nspectrum=601, nwk=300){ jucm<-.r2jd_ucarima(ucm) jwks<-.jcall("jdplus/toolkit/base/r/arima/UcarimaModels", "Ljdplus/toolkit/base/core/ucarima/WienerKolmogorovEstimators;", "wienerKolmogorovEstimators", jucm) @@ -306,13 +318,21 @@ ucarima_canonical<-function(ucm, cmp=0, adjust=TRUE){ #' Estimate UCARIMA Model #' #' @inheritParams ucarima_wk -#' @param x univariate time series -#' @param stdev +#' @param x Univariate time series +#' @param stdev TRUE if standard deviation of the components are computed #' -#' @return matrix containing the different components. +#' @return A matrix containing the different components and their standard deviations if stdev is TRUE. #' @export #' #' @examples +#' mod1 <- arima_model("trend", delta = c(1,-2,1)) +#' mod2 <- arima_model("noise", var = 16) +#' hp <- ucarima_model(components=list(mod1, mod2)) +#' s <- log(aggregate(retail$AutomobileDealers)) +#' all <- ucarima_estimate(s, hp, stdev=TRUE) +#' plot(s, type = 'l') +#' t <- ts(all[,1], frequency = frequency(s), start = start(s)) +#' lines(t, col='blue') ucarima_estimate<-function(x, ucm, stdev=TRUE){ jucm<-.r2jd_ucarima(ucm) jcmps<-.jcall("jdplus/toolkit/base/r/arima/UcarimaModels", "Ljdplus/toolkit/base/api/math/matrices/Matrix;", "estimate", diff --git a/man/arima_difference.Rd b/man/arima_difference.Rd index 2203d46..19c1678 100644 --- a/man/arima_difference.Rd +++ b/man/arima_difference.Rd @@ -2,26 +2,28 @@ % Please edit documentation in R/arima.R \name{arima_difference} \alias{arima_difference} -\title{Remove an arima model from an existing one} +\title{Remove an arima model from an existing one. More exactly, m_diff = m_left - m_right iff m_left = m_right + m_diff.} \usage{ arima_difference(left, right, simplify = TRUE) } \arguments{ -\item{left}{Left operand} +\item{left}{Left operand (JD3_ARIMA object)} -\item{right}{Right operand} +\item{right}{Right operand (JD3_ARIMA object)} -\item{simplify}{Simplify the results} +\item{simplify}{Simplify the results if possible (common roots in the auto-regressive and in the moving average polynomials)} } \value{ a \code{"JD3_ARIMA"} model. } \description{ -Remove an arima model from an existing one +Remove an arima model from an existing one. More exactly, m_diff = m_left - m_right iff m_left = m_right + m_diff. } \examples{ mod1 = arima_model(delta = c(1,-2,1)) mod2 = arima_model(variance=.01) -diff<- arima_difference(mod1, mod2) +diff <- arima_difference(mod1, mod2) +sum <- arima_sum(diff, mod2) +# sum should be equal to mod1 } diff --git a/man/arima_properties.Rd b/man/arima_properties.Rd index 4d0386d..42bb952 100644 --- a/man/arima_properties.Rd +++ b/man/arima_properties.Rd @@ -17,6 +17,6 @@ arima_properties(model, nspectrum = 601, nacf = 36) ARIMA Properties } \examples{ -mod1 = arima_model(ar = c(0.1, 0.2), delta = 0, ma = 0) +mod1 <- arima_model(ar = c(0.1, 0.2), delta = 0, ma = 0) arima_properties(mod1) } diff --git a/man/ucarima_canonical.Rd b/man/ucarima_canonical.Rd index 66ac647..c4a2692 100644 --- a/man/ucarima_canonical.Rd +++ b/man/ucarima_canonical.Rd @@ -7,7 +7,9 @@ ucarima_canonical(ucm, cmp = 0, adjust = TRUE) } \arguments{ -\item{ucm}{UCARIMA model returned by \code{\link[=ucarima_model]{ucarima_model()}}.} +\item{ucm}{An UCARIMA model returned by \code{\link[=ucarima_model]{ucarima_model()}}.} + +\item{cmp}{Index of the component for which we want to compute the filter} \item{adjust}{} } diff --git a/man/ucarima_estimate.Rd b/man/ucarima_estimate.Rd index 09d314b..7e998c9 100644 --- a/man/ucarima_estimate.Rd +++ b/man/ucarima_estimate.Rd @@ -7,15 +7,25 @@ ucarima_estimate(x, ucm, stdev = TRUE) } \arguments{ -\item{x}{univariate time series} +\item{x}{Univariate time series} -\item{ucm}{UCARIMA model returned by \code{\link[=ucarima_model]{ucarima_model()}}.} +\item{ucm}{An UCARIMA model returned by \code{\link[=ucarima_model]{ucarima_model()}}.} -\item{stdev}{} +\item{stdev}{TRUE if standard deviation of the components are computed} } \value{ -matrix containing the different components. +A matrix containing the different components and their standard deviations if stdev is TRUE. } \description{ Estimate UCARIMA Model } +\examples{ +mod1 <- arima_model("trend", delta = c(1,-2,1)) +mod2 <- arima_model("noise", var = 16) +hp <- ucarima_model(components=list(mod1, mod2)) +s <- log(aggregate(retail$AutomobileDealers)) +all <- ucarima_estimate(s, hp, stdev=TRUE) +plot(s, type = 'l') +t <- ts(all[,1], frequency = frequency(s), start = start(s)) +lines(t, col='blue') +} diff --git a/man/ucarima_model.Rd b/man/ucarima_model.Rd index 9d6a249..ba221ac 100644 --- a/man/ucarima_model.Rd +++ b/man/ucarima_model.Rd @@ -2,13 +2,28 @@ % Please edit documentation in R/arima.R \name{ucarima_model} \alias{ucarima_model} -\title{Title} +\title{Creates an UCARIMA model, which is composed of ARIMA models with independent innovations.} \usage{ ucarima_model(model = NULL, components, complements = NULL, checkmodel = FALSE) } \arguments{ -\item{complements}{Complements of (some) components} +\item{model}{The reduced model. Usually not provided.} + +\item{components}{The ARIMA models representing the components} + +\item{complements}{Complements of (some) components. Usually not provided} + +\item{checkmodel}{When the model is provided and \emph{checkmodel} is TRUE, we check that it indeed corresponds to the reduced form of the components; similar controls are applied on complements. Currently not implemented} +} +\value{ +A list with the reduced model, the components and their complements } \description{ -Title +Creates an UCARIMA model, which is composed of ARIMA models with independent innovations. +} +\examples{ +mod1 <- arima_model("trend", delta = c(1,-2,1)) +mod2 <- arima_model("noise", var = 1600) +hp<-ucarima_model(components=list(mod1, mod2)) +print(hp$model) } diff --git a/man/ucarima_wk.Rd b/man/ucarima_wk.Rd index 6950d42..1fdce24 100644 --- a/man/ucarima_wk.Rd +++ b/man/ucarima_wk.Rd @@ -7,10 +7,27 @@ ucarima_wk(ucm, cmp, signal = TRUE, nspectrum = 601, nwk = 300) } \arguments{ -\item{ucm}{UCARIMA model returned by \code{\link[=ucarima_model]{ucarima_model()}}.} +\item{ucm}{An UCARIMA model returned by \code{\link[=ucarima_model]{ucarima_model()}}.} -\item{nwk}{} +\item{cmp}{Index of the component for which we want to compute the filter} + +\item{signal}{TRUE for the signal (component), FALSE for the noise (complement)} + +\item{nspectrum}{Number of points used to compute the (pseudo-) spectrum of the estimator} + +\item{nwk}{Number of weights of the wiener-kolmogorov filter returned in the result} +} +\value{ +A list with the (pseudo-)spectrum, the weights of the filter and the squared-gain function (with the same number of points as the spectrum) } \description{ Wiener Kolmogorov Estimators } +\examples{ +mod1 <- arima_model("trend", delta = c(1,-2,1)) +mod2 <- arima_model("noise", var = 1600) +hp<-ucarima_model(components=list(mod1, mod2)) +wk1<-ucarima_wk(hp, 1, nwk=50) +wk2<-ucarima_wk(hp, 2) +plot(wk1$filter, type='h') +} From 948aeec517b214ebff2e8f7c4c548460d38e4717 Mon Sep 17 00:00:00 2001 From: palatej Date: Wed, 31 Jul 2024 11:01:23 +0200 Subject: [PATCH 2/3] Documentation. Cont. --- .Rbuildignore | 1 + DESCRIPTION | 2 +- R/arima.R | 29 ++++++++++++++++++----------- R/timeseries.R | 14 +++++++------- R/utils.R | 2 +- man/arima_difference.Rd | 2 +- man/arima_properties.Rd | 15 +++++++++------ man/daysOf.Rd | 16 ++++++++++++---- man/ucarima_canonical.Rd | 17 +++++++++++++---- 9 files changed, 63 insertions(+), 35 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 6e0d1c5..c07187b 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -25,3 +25,4 @@ cran-comments.md ^revdep$ ^reconf\.sh$ ^pom\.xml$ + diff --git a/DESCRIPTION b/DESCRIPTION index 26cbc7a..aeedb8e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,7 @@ Imports: checkmate, methods SystemRequirements: Java (>= 17) -License: EUPL +License: file LICENSE URL: https://github.com/rjdverse/rjd3toolkit, https://rjdverse.github.io/rjd3toolkit/ LazyData: TRUE Suggests: diff --git a/R/arima.R b/R/arima.R index 476896e..7e2bfd1 100644 --- a/R/arima.R +++ b/R/arima.R @@ -189,7 +189,7 @@ arima_lsum<-function(components){ #' #' @param left Left operand (JD3_ARIMA object) #' @param right Right operand (JD3_ARIMA object) -#' @param simplify Simplify the results if possible (common roots in the auto-regressive and in the moving average polynomials) +#' @param simplify Simplify the results if possible (common roots in the auto-regressive and in the moving average polynomials, including unit roots) #' #' @return a `"JD3_ARIMA"` model. #' @export @@ -210,20 +210,21 @@ arima_difference<-function(left, right, simplify=TRUE){ } -#' ARIMA Properties +#' Properties of an ARIMA model; the (pseudo-)spectrum and the auto-covariances of the model are returned #' #' @param model a `"JD3_ARIMA"` model (created with [arima_model()]). -#' @param nspectrum number of points in \[0, pi\] to calculate the spectrum. -#' @param nacf maximum lag at which to calculate the acf. +#' @param nspectrum number of points to calculate the spectrum; th points are uniformly distributed in \[0, pi\] +#' @param nac maximum lag at which to calculate the auto-covariances; if the model is non-stationary, the auto-covariances are computed on its stationary transformation. +#' @returns A list with tha auto-covariances and with the (pseudo-)spectrum #' #' @examples -#' mod1 <- arima_model(ar = c(0.1, 0.2), delta = 0, ma = 0) +#' mod1 <- arima_model(ar = c(0.1, 0.2), delta = c(1,-1), ma = 0) #' arima_properties(mod1) #' @export -arima_properties<-function(model, nspectrum=601, nacf=36){ +arima_properties<-function(model, nspectrum=601, nac=36){ jmodel<-.r2jd_arima(model) spectrum<-.jcall("jdplus/toolkit/base/r/arima/ArimaModels", "[D", "spectrum", jmodel, as.integer(nspectrum)) - acf<-.jcall("jdplus/toolkit/base/r/arima/ArimaModels", "[D", "acf", jmodel, as.integer(nacf)) + acf<-.jcall("jdplus/toolkit/base/r/arima/ArimaModels", "[D", "acf", jmodel, as.integer(nac)) return(list(acf=acf, spectrum=spectrum)) } @@ -299,15 +300,21 @@ ucarima_wk<-function(ucm, cmp, signal=TRUE, nspectrum=601, nwk=300){ return(structure(list(spectrum=spectrum, filter=wk, gain2=gain*gain), class="JD3_UCARIMA_WK")) } -#' Title +#' Makes a UCARIMA model canonical; more specifically, put all the noise of the components in one dedicated component #' -#' @inheritParams ucarima_wk -#' @param adjust +#' @param ucm An UCARIMA model returned by [ucarima_model()]. +#' @param cmp Index of the component that will contain the noises; 0 if a new component with all the noises will be added to the model +#' @param adjust If TRUE, some noise could be added to the model to ensure that all the components has positive (pseudo-)spectrum #' -#' @return +#' @return A new UCARIMA model #' @export #' #' @examples +#' mod1 <- arima_model("trend", delta = c(1,-2,1)) +#' mod2 <- arima_model("noise", var = 1600) +#' hp <- ucarima_model(components=list(mod1, mod2)) +#' hpc <- ucarima_canonical(hp, cmp=2) + ucarima_canonical<-function(ucm, cmp=0, adjust=TRUE){ jucm<-.r2jd_ucarima(ucm) jnucm<-.jcall("jdplus/toolkit/base/r/arima/UcarimaModels", "Ljdplus/toolkit/base/core/ucarima/UcarimaModel;", "doCanonical", diff --git a/R/timeseries.R b/R/timeseries.R index 45d0a15..3dab634 100644 --- a/R/timeseries.R +++ b/R/timeseries.R @@ -190,19 +190,19 @@ ts_adjust.data.frame <- function(s, method=c("LeapYear", "LengthOfPeriod"), reve result } -#' Title +#' Provides a list of dates corresponding to each period of the given time series #' -#' @param ts -#' @param pos +#' @param ts A time series +#' @param pos The position of the first considered period. #' -#' @return +#' @return A list of the starting dates of each period #' @export #' -#' @examples -daysOf<-function(ts, pos=0){ +#' @examples daysOf(retail$BookStores) +daysOf<-function(ts, pos=1){ start<-start(ts) jdom<-.r2jd_tsdomain(frequency(ts), start[1], start[2], length(ts)) - days<-.jcall("jdplus/toolkit/base/r/timeseries/TsUtility", "[S", "daysOf",jdom, as.integer(pos)) + days<-.jcall("jdplus/toolkit/base/r/timeseries/TsUtility", "[S", "daysOf",jdom, as.integer(pos-1)) return(as.Date(days)) } diff --git a/R/utils.R b/R/utils.R index f46727f..4658100 100644 --- a/R/utils.R +++ b/R/utils.R @@ -72,7 +72,7 @@ test_anova<-function(ssm, dfm, ssr, dfr){ #' @examples likelihood<-function(nobs, neffectiveobs=NA, nparams=0, ll, adjustedll=NA, aic, aicc, bic, bicc, ssq){ - if (is.na(neffectiveobs)) neffectiveobs<-obs + if (is.na(neffectiveobs)) neffectiveobs<-nobs if (is.na(adjustedll)) adjustedll<-ll return(structure(list(nobs=nobs, neffectiveobs=neffectiveobs, nparams=nparams, diff --git a/man/arima_difference.Rd b/man/arima_difference.Rd index 19c1678..adf6ad3 100644 --- a/man/arima_difference.Rd +++ b/man/arima_difference.Rd @@ -11,7 +11,7 @@ arima_difference(left, right, simplify = TRUE) \item{right}{Right operand (JD3_ARIMA object)} -\item{simplify}{Simplify the results if possible (common roots in the auto-regressive and in the moving average polynomials)} +\item{simplify}{Simplify the results if possible (common roots in the auto-regressive and in the moving average polynomials, including unit roots)} } \value{ a \code{"JD3_ARIMA"} model. diff --git a/man/arima_properties.Rd b/man/arima_properties.Rd index 42bb952..9682975 100644 --- a/man/arima_properties.Rd +++ b/man/arima_properties.Rd @@ -2,21 +2,24 @@ % Please edit documentation in R/arima.R \name{arima_properties} \alias{arima_properties} -\title{ARIMA Properties} +\title{Properties of an ARIMA model; the (pseudo-)spectrum and the auto-covariances of the model are returned} \usage{ -arima_properties(model, nspectrum = 601, nacf = 36) +arima_properties(model, nspectrum = 601, nac = 36) } \arguments{ \item{model}{a \code{"JD3_ARIMA"} model (created with \code{\link[=arima_model]{arima_model()}}).} -\item{nspectrum}{number of points in [0, pi] to calculate the spectrum.} +\item{nspectrum}{number of points to calculate the spectrum; th points are uniformly distributed in [0, pi]} -\item{nacf}{maximum lag at which to calculate the acf.} +\item{nac}{maximum lag at which to calculate the auto-covariances; if the model is non-stationary, the auto-covariances are computed on its stationary transformation.} +} +\value{ +A list with tha auto-covariances and with the (pseudo-)spectrum } \description{ -ARIMA Properties +Properties of an ARIMA model; the (pseudo-)spectrum and the auto-covariances of the model are returned } \examples{ -mod1 <- arima_model(ar = c(0.1, 0.2), delta = 0, ma = 0) +mod1 <- arima_model(ar = c(0.1, 0.2), delta = c(1,-1), ma = 0) arima_properties(mod1) } diff --git a/man/daysOf.Rd b/man/daysOf.Rd index b154f8d..f5dbbaf 100644 --- a/man/daysOf.Rd +++ b/man/daysOf.Rd @@ -2,13 +2,21 @@ % Please edit documentation in R/timeseries.R \name{daysOf} \alias{daysOf} -\title{Title} +\title{Provides a list of dates corresponding to each period of the given time series} \usage{ -daysOf(ts, pos = 0) +daysOf(ts, pos = 1) } \arguments{ -\item{pos}{} +\item{ts}{A time series} + +\item{pos}{The position of the first considered period.} +} +\value{ +A list of the starting dates of each period } \description{ -Title +Provides a list of dates corresponding to each period of the given time series +} +\examples{ +daysOf(retail$BookStores) } diff --git a/man/ucarima_canonical.Rd b/man/ucarima_canonical.Rd index c4a2692..ddc6b74 100644 --- a/man/ucarima_canonical.Rd +++ b/man/ucarima_canonical.Rd @@ -2,17 +2,26 @@ % Please edit documentation in R/arima.R \name{ucarima_canonical} \alias{ucarima_canonical} -\title{Title} +\title{Makes a UCARIMA model canonical; more specifically, put all the noise of the components in one dedicated component} \usage{ ucarima_canonical(ucm, cmp = 0, adjust = TRUE) } \arguments{ \item{ucm}{An UCARIMA model returned by \code{\link[=ucarima_model]{ucarima_model()}}.} -\item{cmp}{Index of the component for which we want to compute the filter} +\item{cmp}{Index of the component that will contain the noises; 0 if a new component with all the noises will be added to the model} -\item{adjust}{} +\item{adjust}{If TRUE, some noise could be added to the model to ensure that all the components has positive (pseudo-)spectrum} +} +\value{ +A new UCARIMA model } \description{ -Title +Makes a UCARIMA model canonical; more specifically, put all the noise of the components in one dedicated component +} +\examples{ +mod1 <- arima_model("trend", delta = c(1,-2,1)) +mod2 <- arima_model("noise", var = 1600) +hp <- ucarima_model(components=list(mod1, mod2)) +hpc <- ucarima_canonical(hp, cmp=2) } From 42420ad3f8cd600c1a8914537963a0d90b1bda04 Mon Sep 17 00:00:00 2001 From: palatej Date: Thu, 1 Aug 2024 08:50:16 +0200 Subject: [PATCH 3/3] Code cleanup (lint) --- R/arima.R | 2 +- R/calendars.R | 6 +++--- R/jd3rslts.R | 30 +++++++++++++++--------------- R/modellingcontext.R | 2 +- R/spec_regarima.R | 24 ++++++++++++------------ 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/R/arima.R b/R/arima.R index 7e2bfd1..7ae0974 100644 --- a/R/arima.R +++ b/R/arima.R @@ -380,7 +380,7 @@ sarima_estimate<-function(x, order=c(0,0,0), seasonal = list(order=c(0,0,0), per if (length(res$b) > 0) { names_xreg <- colnames(xreg) - if (is.null (names_xreg) && !is.null (xreg)){ + if (is.null(names_xreg) && !is.null(xreg)){ if (is.matrix(xreg)) { # unnamed matrix regressors names_xreg <- sprintf("xreg_%i", seq_len(ncol(xreg))) diff --git a/R/calendars.R b/R/calendars.R index 3ad75c6..a5ff4b1 100644 --- a/R/calendars.R +++ b/R/calendars.R @@ -691,7 +691,7 @@ weighted_calendar<-function(calendars, weights){ #' \url{https://jdemetra-new-documentation.netlify.app/} #' @export national_calendar <- function(days, mean_correction=TRUE){ - if (! is.list(days)) stop ('Days should be a list of holidays') + if (! is.list(days)) stop('Days should be a list of holidays') return(structure(list(days=days, mean_correction=mean_correction), class=c('JD3_CALENDAR', 'JD3_CALENDARDEFINITION'))) } @@ -825,7 +825,7 @@ print.JD3_CALENDAR <- function(x, ...) { } #' @export -print.JD3_CHAINEDCALENDAR <- function (x, ...) +print.JD3_CHAINEDCALENDAR <- function(x, ...) { cat("First calendar before ", x$break_date, "\n", sep = "") print(x$calendar1) @@ -839,7 +839,7 @@ print.JD3_CHAINEDCALENDAR <- function (x, ...) } #' @export -print.JD3_WEIGHTEDCALENDAR <- function (x, ...) +print.JD3_WEIGHTEDCALENDAR <- function(x, ...) { for (index_cal in seq_along(x$weights)) { cat("Calendar n", index_cal, "\n", sep = "") diff --git a/R/jd3rslts.R b/R/jd3rslts.R index 6b41c5d..235ee6f 100644 --- a/R/jd3rslts.R +++ b/R/jd3rslts.R @@ -7,7 +7,7 @@ if (!is.jnull(s)) .jcall(s, "D", "doubleValue") else - return (NaN) + return(NaN) } #' @export #' @rdname jd3_utilities @@ -38,11 +38,11 @@ .proc_ts<-function(rslt, name){ s<-.jcall(rslt, "Ljava/lang/Object;", "getData", name) if (is.jnull(s)) - return (NULL) + return(NULL) if (.jinstanceof(s, "jdplus/toolkit/base/api/timeseries/TsData")) return(.jd2r_tsdata(.jcast(s,"jdplus/toolkit/base/api/timeseries/TsData"))) else - return (NULL) + return(NULL) } #' @export #' @rdname jd3_utilities @@ -80,7 +80,7 @@ if (is.jnull(s)) return(NULL) val<-.jcall(s, "D", "getValue") - return (val) + return(val) } #' @export #' @rdname jd3_utilities @@ -102,23 +102,23 @@ s<-.jcall(rslt, "Ljava/lang/Object;", "getData", name) if (is.jnull(s)) return(NULL) - return (.jd2r_matrix(s)) + return(.jd2r_matrix(s)) } #' @export #' @rdname jd3_utilities .proc_data<-function(rslt, name){ s<-.jcall(rslt, "Ljava/lang/Object;", "getData", name) if (is.jnull(s)) - return (NULL) + return(NULL) if (.jinstanceof(s, "jdplus/toolkit/base/api/timeseries/TsData")) return(.jd2r_tsdata(.jcast(s,"jdplus/toolkit/base/api/timeseries/TsData"))) else if (.jinstanceof(s, "java/lang/Number")) - return (.jcall(s, "D", "doubleValue")) + return(.jcall(s, "D", "doubleValue")) else if (.jinstanceof(s, "jdplus/toolkit/base/api/math/matrices/Matrix")) return(.jd2r_matrix(.jcast(s,"jdplus/toolkit/base/api/math/matrices/Matrix"))) else if (.jinstanceof(s, "jdplus/toolkit/base/api/data/Parameter")){ val<-.jcall(s, "D", "getValue") - return (c(val)) + return(c(val)) } else if (.jinstanceof(s, "[Ljdplus/toolkit/base/api/data/Parameter;")){ p<-.jcastToArray(s) len<-length(p) @@ -126,14 +126,14 @@ for (i in 1:len){ all[i]<-.jcall(p[[i]], "D", "getValue") } - return (all) + return(all) } else if (.jcall(.jcall(s, "Ljava/lang/Class;", "getClass"), "Z", "isArray")) - return (.jevalArray(s, silent=TRUE)) + return(.jevalArray(s, silent=TRUE)) else if (.jinstanceof(s, "jdplus/toolkit/base/api/stats/StatisticalTest")) { - return (.jd2r_test(s)) + return(.jd2r_test(s)) } else - return (.jcall(s, "S", "toString")) + return(.jcall(s, "S", "toString")) } #' @export @@ -151,7 +151,7 @@ keys[i] <- .jcall(.jcall(jiter, "Ljava/lang/Object;", "next"), "Ljava/lang/String;", "toString") } } - return (keys) + return(keys) } #' @export @@ -167,13 +167,13 @@ keys[i] <- .jcall(.jcall(jiter, "Ljava/lang/Object;", "next"), "Ljava/lang/String;", "toString") } } - return (keys) + return(keys) } #' @export #' @rdname jd3_utilities .proc_likelihood<-function(jrslt, prefix){ - return (list( + return(list( ll=.proc_numeric(jrslt, paste(prefix,"ll", sep="")), ssq=.proc_numeric(jrslt, paste(prefix,"ssqerr", sep="")), nobs=.proc_int(jrslt, paste(prefix,"nobs", sep="")), diff --git a/R/modellingcontext.R b/R/modellingcontext.R index d78b8a6..775f6bc 100644 --- a/R/modellingcontext.R +++ b/R/modellingcontext.R @@ -312,7 +312,7 @@ modelling_context<-function(calendars=NULL, variables=NULL){ variables[[i]] <- all_var } } - if (any (ts_var)) { + if (any(ts_var)) { # case of a simple ts dictionary # Use 'r' as the name of the dictionary variables <- c(variables[!ts_var], list(r = variables[ts_var])) diff --git a/R/spec_regarima.R b/R/spec_regarima.R index 42d8086..c301e7f 100644 --- a/R/spec_regarima.R +++ b/R/spec_regarima.R @@ -67,18 +67,18 @@ add_outlier.default <- function(x, .create_outlier<-function(code, pos, name = NULL, coef=NULL){ res <- list(name=name, pos=pos, code=code, coef = .fixed_parameter(coef)) - return (res) + return(res) } .fixed_parameters<-function(coef){ ncoef<-length(coef) - if (ncoef == 0)return (NULL) + if (ncoef == 0) return(NULL) l<-lapply(coef, function(v){list(value=v, type='FIXED')}) - return (l) + return(l) } .fixed_parameter<-function(coef){ - if (is.null(coef)) return (NULL) - if (coef == 0) return (NULL) - return (list(value=coef, type='FIXED')) + if (is.null(coef)) return(NULL) + if (coef == 0) return(NULL) + return(list(value=coef, type='FIXED')) } @@ -97,7 +97,7 @@ remove_outlier.default <- function(x, date = NULL, name = NULL){ if (is.null(x$regression$outliers)) - return (x) + return(x) out_mat <- simplify2array(x$regression$outliers)[c("code", "pos", "name"),, drop = FALSE] if (is.null(type)) { out_mat["code",] <- "" @@ -115,7 +115,7 @@ remove_outlier.default <- function(x, out_id <- apply(out_mat,2, paste0, collapse = "") rm_out_id <- rbind(type = type, date = date, name = name) if (is.null(rm_out_id)) - return (x) + return(x) rm_out_id <- apply(rm_out_id,2, paste0, collapse = "") remove_out <- out_id %in% rm_out_id @@ -163,7 +163,7 @@ add_ramp.default <- function(x, .create_ramp<-function(start, end, name = NULL, coef=NULL){ res <- list(name=name, start=start, end=end, coef = .fixed_parameter(coef)) - return (res) + return(res) } #' @rdname add_outlier #' @export @@ -179,7 +179,7 @@ remove_ramp.default <- function(x, end = NULL, name = NULL){ if (is.null(x$regression$ramps)) - return (x) + return(x) rp_mat <- simplify2array(x$regression$ramps)[c("start", "end", "name"),, drop = FALSE] if (is.null(start)) { rp_mat["start",] <- "" @@ -193,7 +193,7 @@ remove_ramp.default <- function(x, rp_id <- apply(rp_mat,2, paste0, collapse = "") rm_rp_id <- rbind(start = start, end = end, name = name) if (is.null(rm_rp_id)) - return (x) + return(x) rm_rp_id <- apply(rm_rp_id,2, paste0, collapse = "") remove_rp <- rp_id %in% rm_rp_id @@ -1474,7 +1474,7 @@ add_usrdefvar.default <- function(x, label<-id } res <- list(id = id, name=label, lag=lag, coef = .fixed_parameter(coef), regeffect=regeffect) - return (res) + return(res) }