diff --git a/.Rbuildignore b/.Rbuildignore index 630c475..1ab290f 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -7,3 +7,5 @@ TO_DO ^docs$ ^pkgdown$ ^\.github$ + +^LICENSE$ diff --git a/.github/workflows/check-changelog.yml b/.github/workflows/check-changelog.yml new file mode 100644 index 0000000..e0c5bb1 --- /dev/null +++ b/.github/workflows/check-changelog.yml @@ -0,0 +1,17 @@ +name: Check changelog + +on: [ push, pull_request ] + +jobs: + check-changelog-job: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 + + - uses: jbangdev/jbang-action@v0.115.0 + with: + script: com.github.nbbrd.heylogs:heylogs-cli:0.7.2:bin + scriptargs: "check NEWS.md" diff --git a/DESCRIPTION b/DESCRIPTION index 17962bc..03c903e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,14 +20,14 @@ Imports: Remotes: github::rjdemetra/rjd3toolkit, github::rjdemetra/rjd3sts -SystemRequirements: Java JRE 17 or higher +SystemRequirements: Java (>= 17) License: EUPL URL: https://github.com/rjdemetra/rjd3highfreq, https://rjdemetra.github.io/rjd3highfreq/ LazyData: TRUE Suggests: knitr, rmarkdown -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 BugReports: https://github.com/rjdemetra/rjd3highfreq/issues Encoding: UTF-8 Collate: diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..20fc266 --- /dev/null +++ b/LICENSE @@ -0,0 +1,185 @@ +EUROPEAN UNION PUBLIC LICENCE v. 1.2 + +EUPL © the European Union 2007, 2016 + +This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined below) which is provided under the terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such use is covered by a right of the copyright holder of the Work). + +The Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following notice immediately following the copyright notice for the Work: + +Licensed under the EUPL + +or has expressed by any other means his willingness to license under the EUPL. + + +1. Definitions + +In this Licence, the following terms have the following meaning: + +— ‘The Licence’: this Licence. + +— ‘The Original Work’: the work or software distributed or communicated by the Licensor under this Licence, available as Source Code and also as Executable Code as the case may be. + +— ‘Derivative Works’: the works or software that could be created by the Licensee, based upon the Original Work or modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in the country mentioned in Article 15. + +— ‘The Work’: the Original Work or its Derivative Works. + +— ‘The Source Code’: the human-readable form of the Work which is the most convenient for people to study and modify. + +— ‘The Executable Code’: any code which has generally been compiled and which is meant to be interpreted by a computer as a program. + +— ‘The Licensor’: the natural or legal person that distributes or communicates the Work under the Licence. + +— ‘Contributor(s)’: any natural or legal person who modifies the Work under the Licence, or otherwise contributes to the creation of a Derivative Work. + +— ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of the Work under the terms of the Licence. + +— ‘Distribution’ or ‘Communication’: any act of selling, giving, lending, renting, distributing, communicating, transmitting, or otherwise making available, online or offline, copies of the Work or providing access to its essential functionalities at the disposal of any other natural or legal person. + + +2. Scope of the rights granted by the Licence + +The Licensor hereby grants You a worldwide, royalty-free, non-exclusive, sublicensable licence to do the following, for the duration of copyright vested in the Original Work: + +— use the Work in any circumstance and for all usage, + +— reproduce the Work, + +— modify the Work, and make Derivative Works based upon the Work, + +— communicate to the public, including the right to make available or display the Work or copies thereof to the public and perform publicly, as the case may be, the Work, + +— distribute the Work or copies thereof, + +— lend and rent the Work or copies thereof, + +— sublicense rights in the Work or copies thereof. + +Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the applicable law permits so. + +In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed by law in order to make effective the licence of the economic rights here above listed. + +The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to any patents held by the Licensor, to the extent necessary to make use of the rights granted on the Work under this Licence. + + +3. Communication of the Source Code + +The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to distribute or communicate the Work. + + +4. Limitations on copyright + +Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the exclusive rights of the rights owners in the Work, of the exhaustion of those rights or of other applicable limitations thereto. + + +5. Obligations of the Licensee + +The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those obligations are the following: + + Attribution right: The Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the Licence with every copy of the Work he/she distributes or communicates. The Licensee must cause any Derivative Work to carry prominent notices stating that the Work has been modified and the date of modification. + Copyleft clause: If the Licensee distributes or communicates copies of the Original Works or Derivative Works, this Distribution or Communication will be done under the terms of this Licence or of a later version of this Licence unless the Original Work is expressly distributed only under this version of the Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the Work or Derivative Work that alter or restrict the terms of the Licence. + Compatibility clause: If the Licensee Distributes or Communicates Derivative Works or copies thereof based upon both the Work and another work licensed under a Compatible Licence, this Distribution or Communication can be done under the terms of this Compatible Licence. For the sake of this clause, ‘Compatible Licence’ refers to the licences listed in the appendix attached to this Licence. Should the Licensee's obligations under the Compatible Licence conflict with his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail. + Provision of Source Code: When distributing or communicating copies of the Work, the Licensee will provide a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available for as long as the Licensee continues to distribute or communicate the Work. + Legal Protection: This Licence does not grant permission to use the trade names, trademarks, service marks, or names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the copyright notice. + + +6. Chain of Authorship + +The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence. + +Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence. + +Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions to the Work, under the terms of this Licence. + + +7. Disclaimer of Warranty + +The Work is a work in progress, which is continuously improved by numerous Contributors. It is not a finished work and may therefore contain defects or ‘bugs’ inherent to this type of development. + +For the above reason, the Work is provided under the Licence on an ‘as is’ basis and without warranties of any kind concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this Licence. + +This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work. + + +8. Disclaimer of Liability + +Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However, the Licensor will be liable under statutory product liability laws as far such laws apply to the Work. + + +9. Additional agreements + +While distributing the Work, You may choose to conclude an additional agreement, defining obligations or services consistent with this Licence. However, if accepting obligations, You may act only on your own behalf and on your sole responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by the fact You have accepted any warranty or additional liability. + + +10. Acceptance of the Licence + +The provisions of this Licence can be accepted by clicking on an icon ‘I agree’ placed under the bottom of a window displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms and conditions. + +Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution or Communication by You of the Work or copies thereof. + + +11. Information to the public + +In case of any Distribution or Communication of the Work by means of electronic communication by You (for example, by offering to download the Work from a remote location) the distribution channel or media (for example, a website) must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence and the way it may be accessible, concluded, stored and reproduced by the Licensee. + + +12. Termination of the Licence + +The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms of the Licence. + +Such a termination will not terminate the licences of any person who has received the Work from the Licensee under the Licence, provided such persons remain in full compliance with the Licence. + + +13. Miscellaneous + +Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the Work. + +If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or enforceability of the Licence as a whole. Such provision will be construed or reformed so as necessary to make it valid and enforceable. + +The European Commission may publish other linguistic versions or new versions of this Licence or updated versions of the Appendix, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. New versions of the Licence will be published with a unique version number. + +All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take advantage of the linguistic version of their choice. + + +14. Jurisdiction + +Without prejudice to specific agreement between parties, + +— any litigation resulting from the interpretation of this License, arising between the European Union institutions, bodies, offices or agencies, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice of the European Union, as laid down in article 272 of the Treaty on the Functioning of the European Union, + +— any litigation arising between other parties and resulting from the interpretation of this License, will be subject to the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business. + + +15. Applicable Law + +Without prejudice to specific agreement between parties, + +— this Licence shall be governed by the law of the European Union Member State where the Licensor has his seat, resides or has his registered office, + +— this licence shall be governed by Belgian law if the Licensor has no seat, residence or registered office inside a European Union Member State. +Appendix + +‘Compatible Licences’ according to Article 5 EUPL are: + +— GNU General Public License (GPL) v. 2, v. 3 + +— GNU Affero General Public License (AGPL) v. 3 + +— Open Software License (OSL) v. 2.1, v. 3.0 + +— Eclipse Public License (EPL) v. 1.0 + +— CeCILL v. 2.0, v. 2.1 + +— Mozilla Public Licence (MPL) v. 2 + +— GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3 + +— Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for works other than software + +— European Union Public Licence (EUPL) v. 1.1, v. 1.2 + +— Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong Reciprocity (LiLiQ-R+) + +The European Commission may update this Appendix to later versions of the above licences without producing a new version of the EUPL, as long as they provide the rights granted in Article 2 of this Licence and protect the covered Source Code from exclusive appropriation. + +All other changes or additions to this Appendix require the production of a new EUPL version. diff --git a/NEWS.md b/NEWS.md index f512f98..000ec51 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,12 +1,25 @@ -# rjd3highfreq dev version +# Changelog +All notable changes to this project will be documented in this file. -* New plots for `JDFractionalAirlineDecomposition` and `JDFractionalAirlineEstimation` -* Update prints -* Add documentation for plots and prints -* Update readme +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres +to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] -# rjd3highfreq 1.0.1 +### Added -First commit +- New plots for `JDFractionalAirlineDecomposition` and `JDFractionalAirlineEstimation` +- Add documentation for plots and prints + +### Changed + +- Update readme +- Update prints + + +[Unreleased]: https://github.com/rjdemetra/rjd3highfreq/compare/v2.0.0...HEAD + +## [2.0.0] - 2023-12-12 + +[2.0.0]: https://github.com/rjdemetra/rjd3highfreq/releases/tag/v2.0.0 diff --git a/R/jd3_fractionalairline.R b/R/jd3_fractionalairline.R index f0a74d4..1e96d63 100644 --- a/R/jd3_fractionalairline.R +++ b/R/jd3_fractionalairline.R @@ -1,18 +1,18 @@ #' @include utils.R NULL -ucm_extract<-function(jrslt, cmp){ - path<-paste0("ucarima.component(", cmp,")") - return (arima_extract(jrslt, path)) +ucm_extract<-function(jrslt, cmp) { + path<-paste0("ucarima.component(", cmp,")") + return (arima_extract(jrslt, path)) } -arima_extract<-function(jrslt, path){ - str<-rjd3toolkit::.proc_str(jrslt, paste0(path, ".name")) - ar<-rjd3toolkit::.proc_vector(jrslt, paste0(path, ".ar")) - delta<-rjd3toolkit::.proc_vector(jrslt, paste0(path, ".delta")) - ma<-rjd3toolkit::.proc_vector(jrslt, paste0(path, ".ma")) - var<-rjd3toolkit::.proc_numeric(jrslt, paste0(path, ".var")) - return (rjd3toolkit::arima_model(str, ar,delta,ma,var)) +arima_extract<-function(jrslt, path) { + str<-rjd3toolkit::.proc_str(jrslt, paste0(path, ".name")) + ar<-rjd3toolkit::.proc_vector(jrslt, paste0(path, ".ar")) + delta<-rjd3toolkit::.proc_vector(jrslt, paste0(path, ".delta")) + ma<-rjd3toolkit::.proc_vector(jrslt, paste0(path, ".ma")) + var<-rjd3toolkit::.proc_numeric(jrslt, paste0(path, ".var")) + return (rjd3toolkit::arima_model(str, ar,delta,ma,var)) } @@ -33,18 +33,23 @@ arima_extract<-function(jrslt, path){ #' @export #' #' @examples -#' -fractionalAirlineDecomposition <- function(y, period, sn = F, stde = F, - nbcasts = 0, nfcasts = 0, log = FALSE, y_time = NULL) -{ - checkmate::assertNumeric(y, null.ok = F) - checkmate::assertNumeric(period, len = 1, null.ok = F) - checkmate::assertLogical(sn, len = 1, null.ok = F) - jrslt <- .jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", - "Ljdplus/highfreq/base/core/extendedairline/decomposition/LightExtendedAirlineDecomposition;", - "decompose", as.numeric(y), period, sn, stde, as.integer(nbcasts), - as.integer(nfcasts)) - return(jd2r_fractionalAirlineDecomposition(jrslt, sn, stde, period, log, y_time)) +#' +fractionalAirlineDecomposition <- function(y, + period, + sn = FALSE, + stde = FALSE, + nbcasts = 0, + nfcasts = 0, + log = FALSE, + y_time = NULL) { + checkmate::assertNumeric(y, null.ok = FALSE) + checkmate::assertNumeric(period, len = 1, null.ok = FALSE) + checkmate::assertLogical(sn, len = 1, null.ok = FALSE) + jrslt <- .jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", + "Ljdplus/highfreq/base/core/extendedairline/decomposition/LightExtendedAirlineDecomposition;", + "decompose", as.numeric(y), period, sn, stde, as.integer(nbcasts), + as.integer(nfcasts)) + return(jd2r_fractionalAirlineDecomposition(jrslt, sn, stde, period, log, y_time)) } @@ -64,28 +69,26 @@ fractionalAirlineDecomposition <- function(y, period, sn = F, stde = F, #' @export #' #' @examples -#' -multiAirlineDecomposition <- function(y, periods, ndiff = 2, ar = F, stde = F, - nbcasts = 0, nfcasts = 0, log = FALSE, y_time = NULL) -{ - if (length(periods) == 1) { - return(fractionalAirlineDecomposition(y, periods, stde = stde, - nbcasts = nbcasts, nfcasts = nfcasts, - log = log, y_time = y_time)) - } - checkmate::assertNumeric(y, null.ok = F) - jrslt <- .jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", - "Ljdplus/highfreq/base/core/extendedairline/decomposition/LightExtendedAirlineDecomposition;", - "decompose", as.numeric(y), .jarray(periods), as.integer(ndiff), - ar, stde, as.integer(nbcasts), as.integer(nfcasts)) - if (length(periods) == 1) { - return(jd2r_fractionalAirlineDecomposition(jrslt, sn = F, stde, periods, - log = log, y_time = y_time)) - } - else { - return(jd2r_multiAirlineDecomposition(jrslt, stde, periods, - log = log, y_time = y_time)) - } +#' +multiAirlineDecomposition <- function(y, periods, ndiff = 2, ar = FALSE, stde = FALSE, + nbcasts = 0, nfcasts = 0, log = FALSE, y_time = NULL) { + if (length(periods) == 1) { + return(fractionalAirlineDecomposition(y, periods, stde = stde, + nbcasts = nbcasts, nfcasts = nfcasts, + log = log, y_time = y_time)) + } + checkmate::assertNumeric(y, null.ok = FALSE) + jrslt <- .jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", + "Ljdplus/highfreq/base/core/extendedairline/decomposition/LightExtendedAirlineDecomposition;", + "decompose", as.numeric(y), .jarray(periods), as.integer(ndiff), + ar, stde, as.integer(nbcasts), as.integer(nfcasts)) + if (length(periods) == 1) { + return(jd2r_fractionalAirlineDecomposition(jrslt, sn = FALSE, stde, periods, + log = log, y_time = y_time)) + } else { + return(jd2r_multiAirlineDecomposition(jrslt, stde, periods, + log = log, y_time = y_time)) + } } @@ -97,175 +100,231 @@ multiAirlineDecomposition <- function(y, periods, ndiff = 2, ar = F, stde = F, #' @param mean add constant mean to y after differencing. #' @param outliers type of outliers sub vector of c("AO","LS","WO") #' @param criticalValue Critical value for automatic outlier detection -#' @param precision Precision of the likelihood +#' @param precision Precision of the likelihood #' @param approximateHessian Compute approximate hessian (based on the optimizing procedure) #' @param nfcasts Number of forecasts -#' @param log +#' @param log a logical #' @param y_time vector of times at which `y` is indexed -#' +#' #' @return #' @export #' #' @examples -#' -fractionalAirlineEstimation <- function( - y, periods, x = NULL, ndiff = 2, ar = F, mean = FALSE, - outliers = NULL, criticalValue = 6, precision = 1e-12, - approximateHessian = F, nfcasts = 0, log = FALSE, - y_time = NULL) -{ - checkmate::assertNumeric(y, null.ok = F) - checkmate::assertNumeric(criticalValue, len = 1, null.ok = F) - checkmate::assertNumeric(precision, len = 1, null.ok = F) - checkmate::assertLogical(mean, len = 1, null.ok = F) - if (is.null(outliers)) - joutliers <- .jnull("[Ljava/lang/String;") - else joutliers = .jarray(outliers, "java.lang.String") - jrslt <- .jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", - "Ljdplus/highfreq/base/core/extendedairline/ExtendedAirlineEstimation;", "estimate", - as.numeric(y), rjd3toolkit::.r2jd_matrix(x), mean, .jarray(periods), - as.integer(ndiff), ar, joutliers, criticalValue, precision, - approximateHessian, as.integer(nfcasts),log) - - external_variables <- .proc_variable_outlier_names(jrslt$getOutliers(),jrslt$getNx()) - reg_mat <- rjd3toolkit::.proc_matrix(jrslt, "regressors") - - if (!is.null(colnames(x)) && sum(duplicated(colnames(x))) == 0) { - external_variables[seq_along(colnames(x))] <- colnames(x) - } - if (ncol(reg_mat) > 0) { - colnames(reg_mat) <- external_variables - } - - model <- list( - y = rjd3toolkit::.proc_vector(jrslt, "y"), - y_time = y_time, - periods = periods, - variables = external_variables, - # "variables " names of variables and outliers - xreg = reg_mat, - # "xreg" matrix of regressor (external variables and outliers) - b = rjd3toolkit::.proc_vector(jrslt, "b"), - bcov = rjd3toolkit::.proc_matrix(jrslt, "bvar"), - linearized = rjd3toolkit::.proc_vector(jrslt, "lin"), - residuals=rjd3toolkit::.proc_vector(jrslt,"residuals"), - component_wo = rjd3toolkit::.proc_vector(jrslt, "component_wo"), - component_ao = rjd3toolkit::.proc_vector(jrslt, "component_ao"), - component_ls = rjd3toolkit::.proc_vector(jrslt, "component_ls"), - component_outliers = rjd3toolkit::.proc_vector(jrslt, "component_outliers"), - component_userdef_reg_variables = rjd3toolkit::.proc_vector(jrslt, "component_userdef_reg_variables"), - component_mean = rjd3toolkit::.proc_vector(jrslt, "component_mean"), - log=rjd3toolkit::.proc_bool(jrslt,"log"), - missingOrNegative=rjd3toolkit::.proc_vector(jrslt, "missing")) - - estimation <- list(parameters = rjd3toolkit::.proc_vector(jrslt, "parameters"), - score = rjd3toolkit::.proc_vector(jrslt, "score"), - covariance = rjd3toolkit::.proc_matrix(jrslt, "pcov")) - - likelihood <- rjd3toolkit::.proc_likelihood(jrslt, "likelihood.") - - return(structure(list(model = model, - estimation = estimation, - likelihood = likelihood), - class = "JDFractionalAirlineEstimation")) +#' +fractionalAirlineEstimation <- function(y, + periods, + x = NULL, + ndiff = 2, + ar = FALSE, + mean = FALSE, + outliers = NULL, + criticalValue = 6, + precision = 1e-12, + approximateHessian = FALSE, + nfcasts = 0, + log = FALSE, + y_time = NULL) { + + # Input checks + checkmate::assertNumeric(y, null.ok = FALSE) + checkmate::assertNumeric(criticalValue, len = 1, null.ok = FALSE) + checkmate::assertNumeric(precision, len = 1, null.ok = FALSE) + checkmate::assertLogical(mean, len = 1, null.ok = FALSE) + + if (is.null(outliers)) { + joutliers <- .jnull("[Ljava/lang/String;") + } else { + joutliers <- .jarray(outliers, "java.lang.String") + } + jrslt <- .jcall( + obj = "jdplus/highfreq/base/r/FractionalAirlineProcessor", + returnSig = "Ljdplus/highfreq/base/core/extendedairline/ExtendedAirlineEstimation;", + method = "estimate", + as.numeric(y), + rjd3toolkit::.r2jd_matrix(x), + mean, + .jarray(periods), + as.integer(ndiff), + ar, + joutliers, + criticalValue, + precision, + approximateHessian, + as.integer(nfcasts), + log + ) + + external_variables <- .proc_variable_outlier_names( + var_out_names = jrslt$getOutliers(), + nX = jrslt$getNx() + ) + reg_mat <- rjd3toolkit::.proc_matrix(rslt = jrslt, name = "regressors") + + if (is.null(y_time) && !is.null(x)) { + y_time <- rownames(x) + } + + if (!is.null(colnames(x)) && sum(duplicated(colnames(x))) == 0) { + external_variables[seq_len(ncol(x))] <- colnames(x) + # Outliers + if (!is.null(y_time) && (length(external_variables) - ncol(x) > 0)) { + outliers <- external_variables[-seq_len(ncol(x))] + outliers_type <- substr(outliers, start = 1, stop = 2) + outliers_date <- y_time[as.integer(substr(outliers, start = 4, stop = 50))] + external_variables[-seq_len(ncol(x))] <- paste0(outliers_type, ".", outliers_date) + } + } else if (is.null(x) + && !is.null(y_time) + && length(external_variables) > 0) { + outliers <- external_variables + outliers_type <- substr(outliers, start = 1, stop = 2) + outliers_date <- y_time[as.integer(substr(outliers, start = 4, stop = 50))] + external_variables <- paste0(outliers_type, ".", outliers_date) + } + if (!is.null(reg_mat) && ncol(reg_mat) > 0) { + colnames(reg_mat) <- external_variables + } + if (!is.null(reg_mat) && nrow(reg_mat) > 0 && !is.null(y_time)) { + rownames(reg_mat) <- y_time + } + + model <- list( + y = rjd3toolkit::.proc_vector(jrslt, "y"), + y_time = y_time, + periods = periods, + variables = external_variables, + # "variables " names of variables and outliers + xreg = reg_mat, + # "xreg" matrix of regressor (external variables and outliers) + b = rjd3toolkit::.proc_vector(jrslt, "b"), + bcov = rjd3toolkit::.proc_matrix(jrslt, "bvar"), + linearized = rjd3toolkit::.proc_vector(jrslt, "lin"), + residuals = rjd3toolkit::.proc_vector(jrslt,"residuals"), + component_wo = rjd3toolkit::.proc_vector(jrslt, "component_wo"), + component_ao = rjd3toolkit::.proc_vector(jrslt, "component_ao"), + component_ls = rjd3toolkit::.proc_vector(jrslt, "component_ls"), + component_outliers = rjd3toolkit::.proc_vector(jrslt, "component_outliers"), + component_userdef_reg_variables = rjd3toolkit::.proc_vector(jrslt, "component_userdef_reg_variables"), + component_mean = rjd3toolkit::.proc_vector(jrslt, "component_mean"), + log=rjd3toolkit::.proc_bool(jrslt,"log"), + missingOrNegative = rjd3toolkit::.proc_vector(jrslt, "missing") + ) + + estimation <- list(parameters = rjd3toolkit::.proc_vector(jrslt, "parameters"), + score = rjd3toolkit::.proc_vector(jrslt, "score"), + covariance = rjd3toolkit::.proc_matrix(jrslt, "pcov")) + + likelihood <- rjd3toolkit::.proc_likelihood(jrslt, "likelihood.") + + return(structure(list(model = model, + estimation = estimation, + likelihood = likelihood), + class = "JDFractionalAirlineEstimation")) } -.proc_variable_outlier_names<-function(var_out_names,nX) { - o<-.jevalArray(var_out_names) - nO<-length(o) - - regvar_outliers<-rep(NA,nX-nO) - for(j in 1:nX-nO) { - regvar_outliers[j]=paste("x-", j)} - - if(nO>0){ - for (j in 1:nO) { - regvar_outliers[nX-nO+j]<-o[[j]]$toString()}} - return(regvar_outliers) +.proc_variable_outlier_names <- function(var_out_names, nX) { + + if (nX == 0) return(NULL) + + o <- .jevalArray(var_out_names) + nO <- length(o) + + regvar_outliers <- rep(NA_character_, nX) + + # External regressors + for(j in seq_len(nX - nO)) { + regvar_outliers[j] <- paste0("x-", j) + } + + # Outliers + for (j in seq_len(nO)) { + regvar_outliers[nX - nO + j] <- o[[j]]$toString() + } + return(regvar_outliers) } #' Title #' -#' @param y -#' @param periods -#' @param ndiff -#' @param stde -#' @param nbcasts -#' @param nfcasts +#' @param y +#' @param periods +#' @param ndiff +#' @param stde +#' @param nbcasts +#' @param nfcasts #' #' @return #' @export #' #' @examples -#' -multiAirlineDecomposition_raw<-function(y, periods, ndiff=2, ar=F, stde=F, nbcasts=0, nfcasts=0){ - checkmate::assertNumeric(y, null.ok = F) - - jrslt<-.jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", - "Ljdplus/highfreq/base/core/extendedairline/decomposition/LightExtendedAirlineDecomposition;", - "decompose", as.numeric(y), - .jarray(periods), as.integer(ndiff), ar, stde, as.integer(nbcasts), as.integer(nfcasts)) - - return (jrslt) +#' +multiAirlineDecomposition_raw<-function(y, periods, ndiff=2, ar=FALSE, stde=FALSE, nbcasts=0, nfcasts=0) { + checkmate::assertNumeric(y, null.ok = FALSE) + + jrslt<-.jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", + "Ljdplus/highfreq/base/core/extendedairline/decomposition/LightExtendedAirlineDecomposition;", + "decompose", as.numeric(y), + .jarray(periods), as.integer(ndiff), ar, stde, as.integer(nbcasts), as.integer(nfcasts)) + + return (jrslt) } #' Title #' -#' @param jdecomp +#' @param jdecomp #' #' @return #' @export #' #' @examples -multiAirlineDecomposition_ssf<-function(jdecomp){ - jssf<-.jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", - "Ljdplus/highfreq/base/core/ssf/extractors/SsfUcarimaEstimation;", "ssfDetails", jdecomp) - return (rjd3toolkit::.jd3_object(jssf, result=T)) +multiAirlineDecomposition_ssf<-function(jdecomp) { + jssf<-.jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", + "Ljdplus/highfreq/base/core/ssf/extractors/SsfUcarimaEstimation;", "ssfDetails", jdecomp) + return (rjd3toolkit::.jd3_object(jssf, result=TRUE)) } #' Title #' -#' @param y -#' @param period -#' @param sn -#' @param stde -#' @param nbcasts -#' @param nfcasts +#' @param y +#' @param period +#' @param sn +#' @param stde +#' @param nbcasts +#' @param nfcasts #' #' @return #' @export #' #' @examples -#' -fractionalAirlineDecomposition_raw<-function(y, period, sn=F, stde=F, nbcasts=0, nfcasts=0){ - checkmate::assertNumeric(y, null.ok = F) - checkmate::assertNumeric(period, len = 1, null.ok = F) - checkmate::assertLogical(sn, len = 1, null.ok = F) - jrslt<-.jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", - "Ljdplus/highfreq/base/core/extendedairline/decomposition/LightExtendedAirlineDecomposition;", - "decompose", as.numeric(y), - period, sn, stde, as.integer(nbcasts), as.integer(nfcasts)) - return (jrslt) +#' +fractionalAirlineDecomposition_raw<-function(y, period, sn=FALSE, stde=FALSE, nbcasts=0, nfcasts=0) { + checkmate::assertNumeric(y, null.ok = FALSE) + checkmate::assertNumeric(period, len = 1, null.ok = FALSE) + checkmate::assertLogical(sn, len = 1, null.ok = FALSE) + jrslt<-.jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", + "Ljdplus/highfreq/base/core/extendedairline/decomposition/LightExtendedAirlineDecomposition;", + "decompose", as.numeric(y), + period, sn, stde, as.integer(nbcasts), as.integer(nfcasts)) + return (jrslt) } #' Title #' -#' @param jdecomp +#' @param jdecomp #' #' @return #' @export #' #' @examples -fractionalAirlineDecomposition_ssf<-function(jdecomp){ - jssf<-.jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", "Ljdplus/highfreq/base/core/ssf/extractors/SsfUcarimaEstimation;", "ssfDetails", jdecomp) - return (rjd3toolkit::.jd3_object(jssf, result=T)) +fractionalAirlineDecomposition_ssf<-function(jdecomp) { + jssf<-.jcall("jdplus/highfreq/base/r/FractionalAirlineProcessor", "Ljdplus/highfreq/base/core/ssf/extractors/SsfUcarimaEstimation;", "ssfDetails", jdecomp) + return (rjd3toolkit::.jd3_object(jssf, result=TRUE)) } #' Title #' -#' @param jrslt -#' @param stde +#' @param jrslt +#' @param stde #' @param log #' @param y_time vector of times at which the time series is indexed #' @@ -273,59 +332,58 @@ fractionalAirlineDecomposition_ssf<-function(jdecomp){ #' @export #' #' @examples -#' -jd2r_multiAirlineDecomposition <- function(jrslt, stde = F, periods, - log = FALSE, y_time = NULL) -{ - ncmps <- rjd3toolkit::.proc_int(jrslt, "ucarima.size") - model <- rjd3highfreq:::arima_extract(jrslt, "ucarima_model") - cmps <- lapply(1:ncmps, function(cmp) { - return(rjd3highfreq:::ucm_extract(jrslt, cmp)) - }) - ucarima <- rjd3toolkit::ucarima_model(model, cmps) - yc <- rjd3toolkit::.proc_vector(jrslt, "y") - estimation <- list( - parameters = rjd3toolkit::.proc_vector(jrslt, "parameters"), - score = rjd3toolkit::.proc_vector(jrslt, "score"), - covariance = rjd3toolkit::.proc_matrix(jrslt, "pcov"), - periods = periods, - log = log) - likelihood <- rjd3toolkit::.proc_likelihood(jrslt, "likelihood.") - - ncmps <- rjd3toolkit::.proc_int(jrslt, "ncmps") - yc <- rjd3toolkit::.proc_vector(jrslt, "y") - sa <- rjd3toolkit::.proc_vector(jrslt, "sa") - tsi_component <- lapply(X = 1:ncmps, FUN = function(j) { - return(rjd3toolkit::.proc_vector(jrslt, paste0("cmp(", j, ")"))) - }) - names(tsi_component) <- c("t", paste0("s_", periods) , "i") - - decomposition <- c( - list(y = yc, y_time = y_time, sa = sa), - tsi_component) - - if (stde) { - tsi_stde_component <- lapply(X = 1:ncmps, FUN = function(j) { - return(rjd3toolkit::.proc_vector(jrslt, paste0("cmp_stde(", j, ")"))) +#' +jd2r_multiAirlineDecomposition <- function(jrslt, stde = FALSE, periods, + log = FALSE, y_time = NULL) { + ncmps <- rjd3toolkit::.proc_int(jrslt, "ucarima.size") + model <- rjd3highfreq:::arima_extract(jrslt, "ucarima_model") + cmps <- lapply(1:ncmps, function(cmp) { + return(rjd3highfreq:::ucm_extract(jrslt, cmp)) + }) + ucarima <- rjd3toolkit::ucarima_model(model, cmps) + yc <- rjd3toolkit::.proc_vector(jrslt, "y") + estimation <- list( + parameters = rjd3toolkit::.proc_vector(jrslt, "parameters"), + score = rjd3toolkit::.proc_vector(jrslt, "score"), + covariance = rjd3toolkit::.proc_matrix(jrslt, "pcov"), + periods = periods, + log = log) + likelihood <- rjd3toolkit::.proc_likelihood(jrslt, "likelihood.") + + ncmps <- rjd3toolkit::.proc_int(jrslt, "ncmps") + yc <- rjd3toolkit::.proc_vector(jrslt, "y") + sa <- rjd3toolkit::.proc_vector(jrslt, "sa") + tsi_component <- lapply(X = 1:ncmps, FUN = function(j) { + return(rjd3toolkit::.proc_vector(jrslt, paste0("cmp(", j, ")"))) }) - names(tsi_stde_component) <- c("t.stde", paste0("stde_", periods) , "i.stde") - - decomposition <- c(decomposition, tsi_stde_component) - } - - return(structure(list(ucarima = ucarima, - decomposition = decomposition, - estimation = estimation, - likelihood = likelihood), - class = "JDFractionalAirlineDecomposition")) + names(tsi_component) <- c("t", paste0("s_", periods) , "i") + + decomposition <- c( + list(y = yc, y_time = y_time, sa = sa), + tsi_component) + + if (stde) { + tsi_stde_component <- lapply(X = 1:ncmps, FUN = function(j) { + return(rjd3toolkit::.proc_vector(jrslt, paste0("cmp_stde(", j, ")"))) + }) + names(tsi_stde_component) <- c("t.stde", paste0("stde_", periods) , "i.stde") + + decomposition <- c(decomposition, tsi_stde_component) + } + + return(structure(list(ucarima = ucarima, + decomposition = decomposition, + estimation = estimation, + likelihood = likelihood), + class = "JDFractionalAirlineDecomposition")) } #' Title #' -#' @param jrslt -#' @param sn -#' @param stde +#' @param jrslt +#' @param sn +#' @param stde #' @param log #' @param y_time vector of times at which the time series is indexed #' @@ -333,51 +391,56 @@ jd2r_multiAirlineDecomposition <- function(jrslt, stde = F, periods, #' @export #' #' @examples -#' -jd2r_fractionalAirlineDecomposition <- function(jrslt, sn = F, stde = F, - period, log = FALSE, y_time = NULL) -{ - ncmps <- rjd3toolkit::.proc_int(jrslt, "ucarima.size") - model <- rjd3highfreq:::arima_extract(jrslt, "ucarima_model") - cmps <- lapply(1:ncmps, function(cmp) { - return(rjd3highfreq:::ucm_extract(jrslt, cmp)) - }) - ucarima <- rjd3toolkit::ucarima_model(model, cmps) - yc <- rjd3toolkit::.proc_vector(jrslt, "y") - sa <- rjd3toolkit::.proc_vector(jrslt, "sa") - s <- rjd3toolkit::.proc_vector(jrslt, "s") - - decomposition <- list(y = yc, y_time = y_time, sa = sa, s = s) - - if (!sn) { - tc <- rjd3toolkit::.proc_vector(jrslt, "t") - ic <- rjd3toolkit::.proc_vector(jrslt, "i") - decomposition <- c(decomposition, list(t = tc, i = ic)) - } - - if (stde) { - s.stde = rjd3toolkit::.proc_vector(jrslt, "s_stde") - decomposition <- c(decomposition, list(s.stde = s.stde)) - +#' +jd2r_fractionalAirlineDecomposition <- function(jrslt, + sn = FALSE, + stde = FALSE, + period, + log = FALSE, + y_time = NULL) { + ncmps <- rjd3toolkit::.proc_int(jrslt, "ucarima.size") + model <- rjd3highfreq:::arima_extract(jrslt, "ucarima_model") + cmps <- lapply( + X = 1:ncmps, + FUN = function(cmp) rjd3highfreq:::ucm_extract(jrslt, cmp) + ) + ucarima <- rjd3toolkit::ucarima_model(model, cmps) + yc <- rjd3toolkit::.proc_vector(jrslt, "y") + sa <- rjd3toolkit::.proc_vector(jrslt, "sa") + s <- rjd3toolkit::.proc_vector(jrslt, "s") + + decomposition <- list(y = yc, y_time = y_time, sa = sa, s = s) + if (!sn) { - t.stde = rjd3toolkit::.proc_vector(jrslt, "t_stde") - i.stde = rjd3toolkit::.proc_vector(jrslt, "i_stde") - decomposition <- c(decomposition, list(t.stde = t.stde, i.stde = i.stde)) + tc <- rjd3toolkit::.proc_vector(jrslt, "t") + ic <- rjd3toolkit::.proc_vector(jrslt, "i") + decomposition <- c(decomposition, list(t = tc, i = ic)) } - } - - estimation <- list( - parameters = rjd3toolkit::.proc_vector(jrslt, "parameters"), - score = rjd3toolkit::.proc_vector(jrslt, "score"), - covariance = rjd3toolkit::.proc_matrix(jrslt, "pcov"), - periods = period, - log = log) - - likelihood <- rjd3toolkit::.proc_likelihood(jrslt, "likelihood.") - - return(structure(list(ucarima = ucarima, - decomposition = decomposition, - estimation = estimation, - likelihood = likelihood), - class = "JDFractionalAirlineDecomposition")) + + if (stde) { + s.stde <- rjd3toolkit::.proc_vector(jrslt, "s_stde") + decomposition <- c(decomposition, list(s.stde = s.stde)) + + if (!sn) { + t.stde <- rjd3toolkit::.proc_vector(jrslt, "t_stde") + i.stde <- rjd3toolkit::.proc_vector(jrslt, "i_stde") + decomposition <- c(decomposition, + list(t.stde = t.stde, i.stde = i.stde)) + } + } + + estimation <- list( + parameters = rjd3toolkit::.proc_vector(jrslt, "parameters"), + score = rjd3toolkit::.proc_vector(jrslt, "score"), + covariance = rjd3toolkit::.proc_matrix(jrslt, "pcov"), + periods = period, + log = log) + + likelihood <- rjd3toolkit::.proc_likelihood(jrslt, "likelihood.") + + return(structure(list(ucarima = ucarima, + decomposition = decomposition, + estimation = estimation, + likelihood = likelihood), + class = "JDFractionalAirlineDecomposition")) } diff --git a/R/plot.R b/R/plot.R index 0c1cc53..3763bf1 100644 --- a/R/plot.R +++ b/R/plot.R @@ -2,7 +2,7 @@ #' Custom Plot Function on JD+ template #' #' This function creates a customized plot in the same template as JD+ GUI color and forms. -#' +#' #' @param x Numeric vector, x-axis values. #' @param y List of numeric vectors, y-axis values for different series. #' @param col Vector of colors for different series. @@ -11,50 +11,50 @@ #' #' @return `NULL` (invisible). #' -plot_jd <- function(x, y, col, legend_txt = NULL, ...){ - - col_bg <- "#f5f4e7" - col_grid <-"#dadad3" - y_range <- range(do.call(c, y)) - - plot.new() - rect(xleft = par("usr")[1], xright = par("usr")[2], - ytop = par("usr")[4], ybottom = par("usr")[3], col = col_bg) - par(new = TRUE) - plot(y = y[[1]], x = x, - col = col[1], type = "l", xlab = "", ylab = "", ylim = y_range, - main = "", xaxt = "n", yaxt = "n") - x_breaks <- Axis(x, side = 1) - par(xaxp = c(x_breaks[1], x_breaks[length(x_breaks)], length(x_breaks) - 1)) - grid(nx = NULL, ny = NULL, col = col_grid) - par(new = TRUE) - - plot(y = y[[1]], - x = x, - col = col[1], type = "l", xlab = "Time", ylim = y_range, - xaxt = "n", ...) - - for (k in (seq_along(y[-1]) + 1)) { - lines(y = y[[k]], - x = x, - col = col[k], ...) - } - - box(col = col_grid) - - if (!is.null(legend_txt)) { - legend("bottomleft", legend = legend_txt, - pch = 16, col = col, horiz = TRUE, xpd = TRUE, - inset = c(0, 1), bty = "n") - } - - return(invisible(NULL)) +plot_jd <- function(x, y, col, legend_txt = NULL, ...) { + + col_bg <- "#f5f4e7" + col_grid <-"#dadad3" + y_range <- range(do.call(c, y)) + + plot.new() + rect(xleft = par("usr")[1], xright = par("usr")[2], + ytop = par("usr")[4], ybottom = par("usr")[3], col = col_bg) + par(new = TRUE) + plot(y = y[[1]], x = x, + col = col[1], type = "l", xlab = "", ylab = "", ylim = y_range, + main = "", xaxt = "n", yaxt = "n") + x_breaks <- Axis(x, side = 1) + par(xaxp = c(x_breaks[1], x_breaks[length(x_breaks)], length(x_breaks) - 1)) + grid(nx = NULL, ny = NULL, col = col_grid) + par(new = TRUE) + + plot(y = y[[1]], + x = x, + col = col[1], type = "l", xlab = "Time", ylim = y_range, + xaxt = "n", ...) + + for (k in (seq_along(y[-1]) + 1)) { + lines(y = y[[k]], + x = x, + col = col[k], ...) + } + + box(col = col_grid) + + if (!is.null(legend_txt)) { + legend("bottomleft", legend = legend_txt, + pch = 16, col = col, horiz = TRUE, xpd = TRUE, + inset = c(0, 1), bty = "n") + } + + return(invisible(NULL)) } #' Plot Function for JDFractionalAirlineEstimation Objects #' #' This function creates a plot for the result of fractional airline model (class `JDFractionalAirlineEstimation`). It shows the raw data and linearized series. -#' +#' #' @param x An object of class 'JDFractionalAirlineEstimation'. #' @param from `Date` or `POSIXt` object, optional starting point for x-axis. #' @param to `Date` or `POSIXt` object, optional ending point for x-axis. @@ -64,57 +64,57 @@ plot_jd <- function(x, y, col, legend_txt = NULL, ...){ #' #' @export plot.JDFractionalAirlineEstimation <- function(x, from, to, ...) { - - col_y <- "#f1ba1d" - col_t <- "#1e6c0b" - col_sa <- "#00488c" - - col_s1 <- "#ffab78" - col_s2 <- "#9169be" - - y <- x$model$y - y_lin <- x$model$linearized - if (x$model$log) { - y_lin <- exp(y_lin) - } - - vect_x <- x$model$y_time - if (is.null(vect_x)) { - vect_x <- seq_along(y) - } else { - if (!missing(from)) { - vect_x <- vect_x[vect_x >= from] + + col_y <- "#f1ba1d" + col_t <- "#1e6c0b" + col_sa <- "#00488c" + + col_s1 <- "#ffab78" + col_s2 <- "#9169be" + + y <- x$model$y + y_lin <- x$model$linearized + if (x$model$log) { + y_lin <- exp(y_lin) } - if (!missing(to)) { - vect_x <- vect_x[vect_x <= to] + + vect_x <- x$model$y_time + if (is.null(vect_x)) { + vect_x <- seq_along(y) + } else { + if (!missing(from)) { + vect_x <- vect_x[vect_x >= from] + } + if (!missing(to)) { + vect_x <- vect_x[vect_x <= to] + } + y <- y[which(x$model$y_time %in% vect_x)] + y_lin <- y_lin[which(x$model$y_time %in% vect_x)] } - y <- y[which(x$model$y_time %in% vect_x)] - y_lin <- y_lin[which(x$model$y_time %in% vect_x)] - } - - list_args <- list(...) - list_args$main <- ifelse("main" %in% names(list_args), - yes = paste0("Raw data and linearised series", " - ", list_args$main), - no = "Raw data and linearised series") - list_args$ylab <- ifelse("ylab" %in% names(list_args), - yes = list_args$ylab, no = "") - list_args$col <- c(col_y, col_t) - - do.call(plot_jd, - c(list( - x = vect_x, y = list(y, y_lin), - legend_txt = c("Raw data", "Linearised series")), - list_args) - ) - - return(invisible(NULL)) + + list_args <- list(...) + list_args$main <- ifelse("main" %in% names(list_args), + yes = paste0("Raw data and linearised series", " - ", list_args$main), + no = "Raw data and linearised series") + list_args$ylab <- ifelse("ylab" %in% names(list_args), + yes = list_args$ylab, no = "") + list_args$col <- c(col_y, col_t) + + do.call(plot_jd, + c(list( + x = vect_x, y = list(y, y_lin), + legend_txt = c("Raw data", "Linearised series")), + list_args) + ) + + return(invisible(NULL)) } #' Plot Function for JDFractionalAirlineDecomposition Objects #' #' This function creates a plot for the result of an Arima Model Based (AMB) decomposition of one or several frequencies (class `JDFractionalAirlineDecomposition`). It shows the decomposition and the component of the model. -#' -#' +#' +#' #' @param x An object of class 'JDFractionalAirlineDecomposition'. #' @param from `Date` or `POSIXt` object, optional starting point for x-axis. #' @param to `Date` or `POSIXt` object, optional ending point for x-axis. @@ -125,99 +125,99 @@ plot.JDFractionalAirlineEstimation <- function(x, from, to, ...) { #' #' @export plot.JDFractionalAirlineDecomposition <- function( - x, from, to, type_chart = c("y-sa-trend", "cal-seas-irr"), ...) { - - if ("y-sa-trend" %in% type_chart) { - - col_y <- "#f1ba1d" - col_t <- "#1e6c0b" - col_sa <- "#00488c" - - y <- x$decomposition$y - sa <- x$decomposition$sa - tc <- x$decomposition$t - if (x$estimation$log) { - y <- exp(y) - sa <- exp(sa) - tc <- exp(tc) - } - - vect_x <- x$decomposition$y_time - if (is.null(vect_x)) { - vect_x <- seq_along(y) - } else { - if (!missing(from)) { - vect_x <- vect_x[vect_x >= from] - } - if (!missing(to)) { - vect_x <- vect_x[vect_x <= to] - } - time_lim <- which(x$decomposition$y_time %in% vect_x) - y <- y[time_lim] - sa <- sa[time_lim] - tc <- tc[time_lim] - } - - list_args <- list(...) - list_args$main <- ifelse("main" %in% names(list_args), - paste0("Decomposition AMB", " - ", list_args$main), - "Decomposition AMB") - list_args$ylab <- ifelse("ylab" %in% names(list_args), - yes = list_args$ylab, no = "") - list_args$col <- c(col_y, col_sa, col_t) - - do.call(plot_jd, - c(list( - x = vect_x, y = list(y, sa, tc), - legend_txt = c("Raw data", "Seasonnal adjusted", "Trend")), - list_args) - ) - } - - if ("cal-seas-irr" %in% type_chart) { - - col_s <- c("#ffab78", "#9169be", "#4d8076", "#c34a36", "#00c9a7") - s_variables <- names(x$decomposition) - s_variables <- s_variables[grepl("^s(?!a)", s_variables, perl = TRUE)] - - s <- x$decomposition[s_variables] - ic <- x$decomposition$i - if (x$estimation$log) { - s <- lapply(X = s, FUN = exp) - ic <- exp(ic) + x, from, to, type_chart = c("y-sa-trend", "cal-seas-irr"), ...) { + + if ("y-sa-trend" %in% type_chart) { + + col_y <- "#f1ba1d" + col_t <- "#1e6c0b" + col_sa <- "#00488c" + + y <- x$decomposition$y + sa <- x$decomposition$sa + tc <- x$decomposition$t + if (x$estimation$log) { + y <- exp(y) + sa <- exp(sa) + tc <- exp(tc) + } + + vect_x <- x$decomposition$y_time + if (is.null(vect_x)) { + vect_x <- seq_along(y) + } else { + if (!missing(from)) { + vect_x <- vect_x[vect_x >= from] + } + if (!missing(to)) { + vect_x <- vect_x[vect_x <= to] + } + time_lim <- which(x$decomposition$y_time %in% vect_x) + y <- y[time_lim] + sa <- sa[time_lim] + tc <- tc[time_lim] + } + + list_args <- list(...) + list_args$main <- ifelse("main" %in% names(list_args), + paste0("Decomposition AMB", " - ", list_args$main), + "Decomposition AMB") + list_args$ylab <- ifelse("ylab" %in% names(list_args), + yes = list_args$ylab, no = "") + list_args$col <- c(col_y, col_sa, col_t) + + do.call(plot_jd, + c(list( + x = vect_x, y = list(y, sa, tc), + legend_txt = c("Raw data", "Seasonnal adjusted", "Trend")), + list_args) + ) } - - vect_x <- x$decomposition$y_time - if (is.null(vect_x)) { - vect_x <- seq_along(ic) - } else { - if (!missing(from)) { - vect_x <- vect_x[vect_x >= from] - } - if (!missing(to)) { - vect_x <- vect_x[vect_x <= to] - } - time_lim <- which(x$decomposition$y_time %in% vect_x) - - s <- lapply(X = s, FUN = base::`[`, time_lim) - ic <- ic[time_lim] + + if ("cal-seas-irr" %in% type_chart) { + + col_s <- c("#ffab78", "#9169be", "#4d8076", "#c34a36", "#00c9a7") + s_variables <- names(x$decomposition) + s_variables <- s_variables[grepl("^s(?!a)", s_variables, perl = TRUE)] + + s <- x$decomposition[s_variables] + ic <- x$decomposition$i + if (x$estimation$log) { + s <- lapply(X = s, FUN = exp) + ic <- exp(ic) + } + + vect_x <- x$decomposition$y_time + if (is.null(vect_x)) { + vect_x <- seq_along(ic) + } else { + if (!missing(from)) { + vect_x <- vect_x[vect_x >= from] + } + if (!missing(to)) { + vect_x <- vect_x[vect_x <= to] + } + time_lim <- which(x$decomposition$y_time %in% vect_x) + + s <- lapply(X = s, FUN = base::`[`, time_lim) + ic <- ic[time_lim] + } + + list_args <- list(...) + list_args$main <- ifelse("main" %in% names(list_args), + paste0("Irregular and Seasonal components", " - ", list_args$main), + "Irregular and Seasonal components") + list_args$ylab <- ifelse("ylab" %in% names(list_args), + yes = list_args$ylab, no = "") + list_args$col <- col_s[seq_len(length(s) + 1)] + + do.call(plot_jd, + c(list( + x = vect_x, y = c(s, list(ic)), + legend_txt = c(s_variables, "Irregular")), + list_args) + ) } - - list_args <- list(...) - list_args$main <- ifelse("main" %in% names(list_args), - paste0("Irregular and Seasonal components", " - ", list_args$main), - "Irregular and Seasonal components") - list_args$ylab <- ifelse("ylab" %in% names(list_args), - yes = list_args$ylab, no = "") - list_args$col <- col_s[seq_len(length(s) + 1)] - - do.call(plot_jd, - c(list( - x = vect_x, y = c(s, list(ic)), - legend_txt = c(s_variables, "Irregular")), - list_args) - ) - } - - return(invisible(NULL)) + + return(invisible(NULL)) } diff --git a/R/print.R b/R/print.R index ee66bcd..e03c4f9 100644 --- a/R/print.R +++ b/R/print.R @@ -1,78 +1,78 @@ #' Print method for 'JDFractionalAirlineDecomposition' objects #' #' This function prints informations on the result of a Fractional Airline model (classe JDFractionalAirlineDecomposition). -#' +#' #' @param x An object of class 'JDFractionalAirlineDecomposition'. #' @param digits Number of digits to round numerical values (default is 3 or digits - 3 from options). #' #' @return The original object 'x'. #' #' @export -print.JDFractionalAirlineDecomposition <- function(x, digits = max(3L, getOption("digits") - 3L), ...) -{ - cat("Number of observations:", formatC(x$likelihood$nobs, digits = digits)) - cat("\n") - - if (!is.null(x$decomposition$y_time)) { - cat("Start:", format(x$decomposition$y_time[1]),"\n") - cat("End:", format(x$decomposition$y_time[length(x$decomposition$y_time)]), "\n") - } - - # Estimated MA parameters (coefs, se, student) - nb_freq <- length(x$estimation$parameters) - 1L - est_ma_params <- data.frame( - MA_parameter = c("Theta(1)", - paste0("Theta(", paste0("period = ", - x$estimation$periods), ")")), - Coef = x$estimation$parameters, - Coef_SE = sqrt(diag(x$estimation$covariance)), - check.names = FALSE) - est_ma_params$Tstat <- est_ma_params$Coef / est_ma_params$Coef_SE - - cat("\n") - cat("Estimate MA parameters:") - cat("\n") - print(est_ma_params, row.names = FALSE) - cat(ifelse(x$estimation$log, "Multiplicative", "Additive"), "model\n") - - cat("\n") - cat("Decomposition:") - cat("\n") - decompo_table <- do.call(cbind, x$decomposition) - if (x$estimation$log) { - decompo_table <- exp(decompo_table) - } - decompo_table <- subset(decompo_table, select = -y_time) - if (!is.null(x$decomposition$y_time)) { - rownames(decompo_table) <- format(x$decomposition$y_time) - } - print(tail(decompo_table, n = 10)) - cat("\n") - - cat("Sum of square residuals:", formatC(x$likelihood$ssq, digits = digits), - "on", x$likelihood$df, "degrees of freedom", - sep = " ") - cat("\n") - - cat("Log likelihood = ", formatC(x$likelihood$ll, digits = digits), - ", \n\taic = ", formatC(x$likelihood$aic, digits = digits), - ", \n\taicc = ", formatC(x$likelihood$aicc, digits = digits), - ", \n\tbic(corrected for length) = ", - formatC(x$likelihood$bicc, digits = digits), sep = "") - cat("\n") - - cat("Hannan–Quinn information criterion = ", - formatC(x$likelihood$hannanquinn, digits = digits), sep = "") - - cat("\n\n") - - return(invisible(x)) +print.JDFractionalAirlineDecomposition <- function(x, digits = max(3L, getOption("digits") - 3L), ...) { + cat("Number of observations:", formatC(x$likelihood$nobs, digits = digits)) + cat("\n") + + if (!is.null(x$decomposition$y_time)) { + cat("Start:", format(x$decomposition$y_time[1]),"\n") + cat("End:", format(x$decomposition$y_time[length(x$decomposition$y_time)]), "\n") + } + + # Estimated MA parameters (coefs, se, student) + nb_freq <- length(x$estimation$parameters) - 1L + est_ma_params <- data.frame( + MA_parameter = c("Theta(1)", + paste0("Theta(", paste0("period = ", + x$estimation$periods), ")")), + Coef = x$estimation$parameters, + Coef_SE = sqrt(diag(x$estimation$covariance)), + check.names = FALSE) + est_ma_params$Tstat <- est_ma_params$Coef / est_ma_params$Coef_SE + + cat("\n") + cat("Estimate MA parameters:") + cat("\n") + print(est_ma_params, row.names = FALSE) + cat(ifelse(x$estimation$log, "Multiplicative", "Additive"), "model\n") + + cat("\n") + cat("Decomposition:") + cat("\n") + decompo_table <- do.call(cbind, x$decomposition) + if (x$estimation$log) { + decompo_table <- exp(decompo_table) + } + + if (!is.null(x$decomposition$y_time)) { + decompo_table <- subset(decompo_table, select = -y_time) + rownames(decompo_table) <- format(x$decomposition$y_time) + } + print(tail(decompo_table, n = 10)) + cat("\n") + + cat("Sum of square residuals:", formatC(x$likelihood$ssq, digits = digits), + "on", x$likelihood$df, "degrees of freedom", + sep = " ") + cat("\n") + + cat("Log likelihood = ", formatC(x$likelihood$ll, digits = digits), + ", \n\taic = ", formatC(x$likelihood$aic, digits = digits), + ", \n\taicc = ", formatC(x$likelihood$aicc, digits = digits), + ", \n\tbic(corrected for length) = ", + formatC(x$likelihood$bicc, digits = digits), sep = "") + cat("\n") + + cat("Hannan–Quinn information criterion = ", + formatC(x$likelihood$hannanquinn, digits = digits), sep = "") + + cat("\n\n") + + return(invisible(x)) } #' Print method for 'JDFractionalAirlineEstimation' objects #' #' This function prints informations on the result of a Fractional Airline model (classe JDFractionalAirlineEstimation). -#' +#' #' @param x An object of class 'JDFractionalAirlineEstimation'. #' @param digits Number of digits to round numerical values (default is 3 or digits - 3 from options). #' @@ -80,94 +80,88 @@ print.JDFractionalAirlineDecomposition <- function(x, digits = max(3L, getOption #' #' @export print.JDFractionalAirlineEstimation <- function(x, digits = max(3L, getOption("digits") - 3L), ...) { - - cat("Number of observations:", formatC(x$likelihood$nobs, digits = digits)) - cat("\n") - - if (!is.null(x$model$y_time)) { - cat("Start:", format(x$model$y_time[1]),"\n") - cat("End:", format(x$model$y_time[length(x$model$y_time)]), "\n") - } - - nb_outliers <- sum(toupper(substr(x$model$variables, 1L, 2L)) %in% - c("AO", "WO", "LS")) - nb_reg_cjo <- length(x$model$variables) - nb_outliers - - summary_coeff <- data.frame( - "Variable" = x$model$variables, - "Coef" = x$model$b, - "Coef_SE" = sqrt(diag(x$model$bcov))) - summary_coeff$Tstat <- round(summary_coeff$Coef / summary_coeff$Coef_SE, digits) - summary_coeff$Coef <- round(summary_coeff$Coef, digits) - summary_coeff$Coef_SE <- round(summary_coeff$Coef_SE, digits) - - if (nb_outliers > 0) { - outliers_coeff <- summary_coeff[(nb_reg_cjo + 1L):nrow(summary_coeff), ] - + + cat("Number of observations:", formatC(x$likelihood$nobs, digits = digits)) + cat("\n") + if (!is.null(x$model$y_time)) { - outliers_type <- substr(outliers_coeff$Variable, start = 1, stop = 2) - outliers_date <- x$model$y_time[as.integer(substr(outliers_coeff$Variable, start = 4, stop = 50))] - outliers_coeff$Variable <- paste0(outliers_type, ".", outliers_date) + cat("Start:", format(x$model$y_time[1]),"\n") + cat("End:", format(x$model$y_time[length(x$model$y_time)]), "\n") } - } - - if (nb_reg_cjo > 0) { - reg_cjo_coeff <- summary_coeff[seq_len(nb_reg_cjo), ] - } - - # Estimated MA parameters (coefs, se, student) - nb_freq <- length(x$estimation$parameters) - 1L - est_ma_params <- data.frame( - MA_parameter = c("Theta(1)", - paste0("Theta(", paste0("period = ", - x$model$periods), ")")), - Coef = x$estimation$parameters, - Coef_SE = sqrt(diag(x$estimation$covariance)), - check.names = FALSE) - est_ma_params$Tstat <- est_ma_params$Coef / est_ma_params$Coef_SE - - cat("\n") - cat("Estimate MA parameters:") - cat("\n") - print(est_ma_params, row.names = FALSE) - - cat("\n") - cat("Number of calendar regressors:", nb_reg_cjo, ", Number of outliers :", nb_outliers) - cat("\n\n") - - if(nb_reg_cjo > 0) { - cat("TD regressors coefficients:") + + nb_outliers <- sum(toupper(substr(x$model$variables, 1L, 2L)) %in% + c("AO", "WO", "LS")) + nb_reg_cjo <- length(x$model$variables) - nb_outliers + + summary_coeff <- data.frame( + "Variable" = x$model$variables, + "Coef" = x$model$b, + "Coef_SE" = sqrt(diag(x$model$bcov))) + summary_coeff$Tstat <- round(summary_coeff$Coef / summary_coeff$Coef_SE, digits) + summary_coeff$Coef <- round(summary_coeff$Coef, digits) + summary_coeff$Coef_SE <- round(summary_coeff$Coef_SE, digits) + + if (nb_outliers > 0) { + outliers_coeff <- summary_coeff[(nb_reg_cjo + 1L):nrow(summary_coeff), ] + } + + if (nb_reg_cjo > 0) { + reg_cjo_coeff <- summary_coeff[seq_len(nb_reg_cjo), ] + } + + # Estimated MA parameters (coefs, se, student) + nb_freq <- length(x$estimation$parameters) - 1L + est_ma_params <- data.frame( + MA_parameter = c("Theta(1)", + paste0("Theta(period = ", x$model$periods, ")")), + Coef = x$estimation$parameters, + Coef_SE = sqrt(diag(x$estimation$covariance)), + check.names = FALSE + ) + est_ma_params$Tstat <- est_ma_params$Coef / est_ma_params$Coef_SE + cat("\n") - print(reg_cjo_coeff, row.names = FALSE) - # print(head(reg_cjo_coeff, 10), row.names = FALSE) - # if (nb_reg_cjo > 10) cat("...\n") + cat("Estimate MA parameters:") cat("\n") - } - - if(nb_outliers > 0) { - cat("Outliers coefficients:") + print(est_ma_params, row.names = FALSE) + cat("\n") - print(outliers_coeff, row.names = FALSE) - # print(head(outliers_coeff, 10), row.names = FALSE) - # if (nb_outliers > 10) cat("...\n") + cat("Number of calendar regressors:", nb_reg_cjo, ", Number of outliers :", nb_outliers) + cat("\n\n") + + if(nb_reg_cjo > 0) { + cat("TD regressors coefficients:") + cat("\n") + print(reg_cjo_coeff, row.names = FALSE) + # print(head(reg_cjo_coeff, 10), row.names = FALSE) + # if (nb_reg_cjo > 10) cat("...\n") + cat("\n") + } + + if(nb_outliers > 0) { + cat("Outliers coefficients:") + cat("\n") + print(outliers_coeff, row.names = FALSE) + # print(head(outliers_coeff, 10), row.names = FALSE) + # if (nb_outliers > 10) cat("...\n") + cat("\n") + } + + cat("Sum of square residuals:", formatC(x$likelihood$ssq, digits = digits), + "on", x$likelihood$df, "degrees of freedom", + sep = " ") + cat("\n") + + cat("Log likelihood = ", formatC(x$likelihood$ll, digits = digits), + ", \n\taic = ", formatC(x$likelihood$aic, digits = digits), + ", \n\taicc = ", formatC(x$likelihood$aicc, digits = digits), + ", \n\tbic(corrected for length) = ", + formatC(x$likelihood$bicc, digits = digits), sep = "") cat("\n") - } - - cat("Sum of square residuals:", formatC(x$likelihood$ssq, digits = digits), - "on", x$likelihood$df, "degrees of freedom", - sep = " ") - cat("\n") - - cat("Log likelihood = ", formatC(x$likelihood$ll, digits = digits), - ", \n\taic = ", formatC(x$likelihood$aic, digits = digits), - ", \n\taicc = ", formatC(x$likelihood$aicc, digits = digits), - ", \n\tbic(corrected for length) = ", - formatC(x$likelihood$bicc, digits = digits), sep = "") - cat("\n") - - cat("Hannan–Quinn information criterion = ", - formatC(x$likelihood$hannanquinn, digits = digits), sep = "") - - cat("\n\n") - return(invisible(x)) + + cat("Hannan–Quinn information criterion = ", + formatC(x$likelihood$hannanquinn, digits = digits), sep = "") + + cat("\n\n") + return(invisible(x)) } diff --git a/R/utils.R b/R/utils.R index d8fa7a0..4eec7b5 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,6 +1,6 @@ #' @importFrom rJava .jpackage .jcall .jnull .jarray .jevalArray .jcast .jcastToArray .jinstanceof is.jnull .jnew .jclass #' @importFrom RProtoBuf readProtoFiles2 #' @importFrom stats frequency is.ts pt start ts -#' @importFrom rjd3toolkit result dictionary -#' @importFrom methods new +#' @importFrom rjd3toolkit result dictionary +#' @importFrom methods new NULL diff --git a/R/zzz.R b/R/zzz.R index 4518ca3..4f475b0 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -2,15 +2,14 @@ #' @import rjd3sts .onLoad <- function(libname, pkgname) { - if (! requireNamespace("rjd3sts", quietly=T)) stop("Loading rjd3 libraries failed") + if (! requireNamespace("rjd3sts", quietly=TRUE)) stop("Loading rjd3 libraries failed") result <- .jpackage(pkgname, lib.loc=libname) if (!result) stop("Loading java packages failed") #proto.dir <- system.file("proto", package = pkgname) #RProtoBuf::readProtoFiles2(protoPath = proto.dir) - + # reload extractors .jcall("jdplus/toolkit/base/api/information/InformationExtractors", "V", "reloadExtractors") } - diff --git a/README.Rmd b/README.Rmd index f7130b3..3b1eff6 100644 --- a/README.Rmd +++ b/README.Rmd @@ -8,7 +8,7 @@ output: github_document knitr::opts_chunk$set( collapse = TRUE, comment = "#>", - fig.path = "man/figures/README-", + fig.path = "man/figures/README-", fig.align = "center", fig.dim = c(7, 4) * 1.4, out.width = "100%" @@ -55,8 +55,8 @@ Plot of the raw series: ```{r raw data plot, echo = FALSE, eval = TRUE} # Plot of the raw data ---------------------------------------------------- -rjd3highfreq:::plot_jd(x = df_daily$date, y = list(df_daily$births), - col = "#f1ba1d", main = "French daily birth", +rjd3highfreq:::plot_jd(x = df_daily$date, y = list(df_daily$births), + col = "#f1ba1d", main = "French daily birth", ylab = "Nbr birth") ``` @@ -84,8 +84,8 @@ Creation of the calendar regressor in a matrix with the package **rjd3toolkit**: ```{r regressor matrix creation, echo = TRUE, eval = TRUE} # Calendar regressor matrix cal_reg <- rjd3toolkit::holidays( - calendar = frenchCalendar, - start = "1968-01-01", length = nrow(df_daily), + calendar = frenchCalendar, + start = "1968-01-01", length = nrow(df_daily), type = "All", nonworking = 7L) colnames(cal_reg) <- c("14th_july", "8th_may", "1st_jan", "1st_may", @@ -97,8 +97,8 @@ Preprocessing with the function `fractionalAirlineEstimation`: ```{r preprocessing, echo = TRUE, eval = TRUE} pre_pro <- fractionalAirlineEstimation( - y = df_daily$births, - x = cal_reg, + y = df_daily$births, + x = cal_reg, periods = 7, # weekly frequency outliers = c("ao", "wo"), log = TRUE, y_time = df_daily$date) @@ -107,8 +107,8 @@ print(pre_pro) ```{r preprocessing plots, echo = TRUE, eval = TRUE} plot(pre_pro, main = "French births") -plot(x = pre_pro, - from = as.Date("2000-01-01"), to = as.Date("2000-12-31"), +plot(x = pre_pro, + from = as.Date("2000-01-01"), to = as.Date("2000-12-31"), main = "French births in 2000") ``` @@ -119,7 +119,7 @@ Decomposition with the AMB (Arima Model Based) algorithm: # Decomposition with weekly pattern amb.dow <- rjd3highfreq::fractionalAirlineDecomposition( y = pre_pro$model$linearized, # linearized series from preprocessing - period = 7, + period = 7, log = TRUE, y_time = df_daily$date) # Extract day-of-year pattern from day-of-week-adjusted linearised data @@ -137,8 +137,8 @@ plot(amb.dow, main = "Weekly pattern") ``` ```{r amb plot 2, echo = TRUE, eval = TRUE} -plot(amb.dow, main = "Weekly pattern - January 2018", - from = as.Date("2018-01-01"), +plot(amb.dow, main = "Weekly pattern - January 2018", + from = as.Date("2018-01-01"), to = as.Date("2018-01-31")) ``` @@ -147,8 +147,8 @@ plot(amb.doy, main = "Yearly pattern") ``` ```{r amb plot 4, echo = TRUE, eval = TRUE} -plot(amb.doy, main = "Weekly pattern - 2000 - 2002", - from = as.Date("2000-01-01"), +plot(amb.doy, main = "Weekly pattern - 2000 - 2002", + from = as.Date("2000-01-01"), to = as.Date("2002-12-31")) ``` @@ -169,10 +169,19 @@ plot(amb.multi) ``` ```{r plot amb.multi 2, echo = TRUE, eval = TRUE} -plot(amb.multi, main = "2012", - from = as.Date("2012-01-01"), +plot(amb.multi, main = "2012", + from = as.Date("2012-01-01"), to = as.Date("2012-12-31")) ``` With the package [**rjd3x11plus**](https://github.com/rjdemetra/rjd3x11plus), you can perform an X-11 like decomposition with any (non integer) periodicity. + + +## Contributing + +Any contribution is welcome and should be done through pull requests and/or issues. + +## Licensing + +The code of this project is licensed under the [European Union Public Licence (EUPL)](https://joinup.ec.europa.eu/page/eupl-text-11-12). diff --git a/README.md b/README.md index 5d258b6..a193bf6 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,8 @@ Creation of the calendar regressor in a matrix with the package ``` r # Calendar regressor matrix cal_reg <- rjd3toolkit::holidays( - calendar = frenchCalendar, - start = "1968-01-01", length = nrow(df_daily), + calendar = frenchCalendar, + start = "1968-01-01", length = nrow(df_daily), type = "All", nonworking = 7L) colnames(cal_reg) <- c("14th_july", "8th_may", "1st_jan", "1st_may", @@ -76,8 +76,8 @@ Preprocessing with the function `fractionalAirlineEstimation`: ``` r pre_pro <- fractionalAirlineEstimation( - y = df_daily$births, - x = cal_reg, + y = df_daily$births, + x = cal_reg, periods = 7, # weekly frequency outliers = c("ao", "wo"), log = TRUE, y_time = df_daily$date) @@ -132,8 +132,8 @@ plot(pre_pro, main = "French births") ``` r -plot(x = pre_pro, - from = as.Date("2000-01-01"), to = as.Date("2000-12-31"), +plot(x = pre_pro, + from = as.Date("2000-01-01"), to = as.Date("2000-12-31"), main = "French births in 2000") ``` @@ -145,7 +145,7 @@ Decomposition with the AMB (Arima Model Based) algorithm: # Decomposition with weekly pattern amb.dow <- rjd3highfreq::fractionalAirlineDecomposition( y = pre_pro$model$linearized, # linearized series from preprocessing - period = 7, + period = 7, log = TRUE, y_time = df_daily$date) # Extract day-of-year pattern from day-of-week-adjusted linearised data @@ -164,8 +164,8 @@ plot(amb.dow, main = "Weekly pattern") ``` r -plot(amb.dow, main = "Weekly pattern - January 2018", - from = as.Date("2018-01-01"), +plot(amb.dow, main = "Weekly pattern - January 2018", + from = as.Date("2018-01-01"), to = as.Date("2018-01-31")) ``` @@ -178,8 +178,8 @@ plot(amb.doy, main = "Yearly pattern") ``` r -plot(amb.doy, main = "Weekly pattern - 2000 - 2002", - from = as.Date("2000-01-01"), +plot(amb.doy, main = "Weekly pattern - 2000 - 2002", + from = as.Date("2000-01-01"), to = as.Date("2002-12-31")) ``` @@ -205,8 +205,8 @@ plot(amb.multi) ``` r -plot(amb.multi, main = "2012", - from = as.Date("2012-01-01"), +plot(amb.multi, main = "2012", + from = as.Date("2012-01-01"), to = as.Date("2012-12-31")) ``` @@ -215,3 +215,13 @@ plot(amb.multi, main = "2012", With the package [**rjd3x11plus**](https://github.com/rjdemetra/rjd3x11plus), you can perform an X-11 like decomposition with any (non integer) periodicity. + +## Contributing + +Any contribution is welcome and should be done through pull requests +and/or issues. + +## Licensing + +The code of this project is licensed under the [European Union Public +Licence (EUPL)](https://joinup.ec.europa.eu/page/eupl-text-11-12). diff --git a/man/fractionalAirlineDecomposition.Rd b/man/fractionalAirlineDecomposition.Rd index 99b46c8..a5b1866 100644 --- a/man/fractionalAirlineDecomposition.Rd +++ b/man/fractionalAirlineDecomposition.Rd @@ -7,8 +7,8 @@ fractionalAirlineDecomposition( y, period, - sn = F, - stde = F, + sn = FALSE, + stde = FALSE, nbcasts = 0, nfcasts = 0, log = FALSE, diff --git a/man/fractionalAirlineDecomposition_raw.Rd b/man/fractionalAirlineDecomposition_raw.Rd index 1c7ca70..4266a7b 100644 --- a/man/fractionalAirlineDecomposition_raw.Rd +++ b/man/fractionalAirlineDecomposition_raw.Rd @@ -7,23 +7,13 @@ fractionalAirlineDecomposition_raw( y, period, - sn = F, - stde = F, + sn = FALSE, + stde = FALSE, nbcasts = 0, nfcasts = 0 ) } \arguments{ -\item{y}{} - -\item{period}{} - -\item{sn}{} - -\item{stde}{} - -\item{nbcasts}{} - \item{nfcasts}{} } \description{ diff --git a/man/fractionalAirlineEstimation.Rd b/man/fractionalAirlineEstimation.Rd index 636628a..d210a1f 100644 --- a/man/fractionalAirlineEstimation.Rd +++ b/man/fractionalAirlineEstimation.Rd @@ -9,12 +9,12 @@ fractionalAirlineEstimation( periods, x = NULL, ndiff = 2, - ar = F, + ar = FALSE, mean = FALSE, outliers = NULL, criticalValue = 6, precision = 1e-12, - approximateHessian = F, + approximateHessian = FALSE, nfcasts = 0, log = FALSE, y_time = NULL diff --git a/man/jd2r_fractionalAirlineDecomposition.Rd b/man/jd2r_fractionalAirlineDecomposition.Rd index 4b05e63..b676968 100644 --- a/man/jd2r_fractionalAirlineDecomposition.Rd +++ b/man/jd2r_fractionalAirlineDecomposition.Rd @@ -6,20 +6,14 @@ \usage{ jd2r_fractionalAirlineDecomposition( jrslt, - sn = F, - stde = F, + sn = FALSE, + stde = FALSE, period, log = FALSE, y_time = NULL ) } \arguments{ -\item{jrslt}{} - -\item{sn}{} - -\item{stde}{} - \item{y_time}{vector of times at which the time series is indexed} } \description{ diff --git a/man/jd2r_multiAirlineDecomposition.Rd b/man/jd2r_multiAirlineDecomposition.Rd index 407e487..47b90c2 100644 --- a/man/jd2r_multiAirlineDecomposition.Rd +++ b/man/jd2r_multiAirlineDecomposition.Rd @@ -6,17 +6,13 @@ \usage{ jd2r_multiAirlineDecomposition( jrslt, - stde = F, + stde = FALSE, periods, log = FALSE, y_time = NULL ) } \arguments{ -\item{jrslt}{} - -\item{stde}{} - \item{y_time}{vector of times at which the time series is indexed} } \description{ diff --git a/man/multiAirlineDecomposition.Rd b/man/multiAirlineDecomposition.Rd index a938ac9..9c8dc04 100644 --- a/man/multiAirlineDecomposition.Rd +++ b/man/multiAirlineDecomposition.Rd @@ -8,8 +8,8 @@ multiAirlineDecomposition( y, periods, ndiff = 2, - ar = F, - stde = F, + ar = FALSE, + stde = FALSE, nbcasts = 0, nfcasts = 0, log = FALSE, diff --git a/man/multiAirlineDecomposition_raw.Rd b/man/multiAirlineDecomposition_raw.Rd index f35584e..ba74df5 100644 --- a/man/multiAirlineDecomposition_raw.Rd +++ b/man/multiAirlineDecomposition_raw.Rd @@ -8,23 +8,13 @@ multiAirlineDecomposition_raw( y, periods, ndiff = 2, - ar = F, - stde = F, + ar = FALSE, + stde = FALSE, nbcasts = 0, nfcasts = 0 ) } \arguments{ -\item{y}{} - -\item{periods}{} - -\item{ndiff}{} - -\item{stde}{} - -\item{nbcasts}{} - \item{nfcasts}{} } \description{ diff --git a/rjd3highfreq.Rproj b/rjd3highfreq.Rproj index fde0cd9..62ab696 100644 --- a/rjd3highfreq.Rproj +++ b/rjd3highfreq.Rproj @@ -1,17 +1,20 @@ Version: 1.0 -RestoreWorkspace: Default -SaveWorkspace: Default -AlwaysSaveHistory: Default +RestoreWorkspace: No +SaveWorkspace: No +AlwaysSaveHistory: No EnableCodeIndexing: Yes UseSpacesForTab: Yes -NumSpacesForTab: 2 +NumSpacesForTab: 4 Encoding: UTF-8 RnwWeave: Sweave LaTeX: pdfLaTeX +AutoAppendNewline: Yes +StripTrailingWhitespace: Yes + BuildType: Package PackageUseDevtools: Yes PackageInstallArgs: --no-multiarch --with-keep.source @@ -19,4 +22,6 @@ PackageBuildBinaryArgs: --no-multiarch PackageCheckArgs: --no-multiarch PackageRoxygenize: rd,collate,namespace,vignette +UseNativePipeOperator: Yes + SpellingDictionary: en_GB