Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
TanguyBarthelemy committed Jul 12, 2024
2 parents 1bf3bcf + bcce59d commit f02d45f
Show file tree
Hide file tree
Showing 49 changed files with 1,401 additions and 203 deletions.
34 changes: 21 additions & 13 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
^appveyor\.yml$
^docs$
^_pkgdown\.yml$
^.*\.Rproj$
^\.Rproj\.user$
^.lintr$
^README.Rmd$

^\.git$
^\.github$

^README\.Rmd$
^README-.*\.png$
.travis.yml
^pkgdown$

^Meta$
^docs$
^doc$
^pkgdown$
^_pkgdown\.yml$

^\.lintr$

^appveyor\.yml$
.travis.yml

cran-comments.md
TODO.R

^\.DS_Store$

^revdep$
workspace
workspace.xml
R/test_X11.R
^\.github$
^LICENSE$
^reconf\.sh$
^pom\.xml$
5 changes: 1 addition & 4 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
workflow_dispatch

name: test-coverage

Expand Down
59 changes: 54 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
.Rproj.user
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData
.RDataTmp

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf
Meta/
inst/doc/
doc/

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# R Environment Variables
.Renviron

# pkgdown site
docs/

# translation temp files
po/*~

# RStudio Connect folder
rsconnect/

# Hidden file from mac-os
.DS_Store
workspace
workspace.xml
inst/doc
docs

# produced README.html
README.html
32 changes: 17 additions & 15 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
Package: rjd3filters
Type: Package
Title: Trend-Cycle Extraction with Linear Filters
Version: 2.1.0
Title: Trend-Cycle Extraction with Linear Filters based on JDemetra+ v3.x
Version: 2.1.1
Authors@R: c(
person("Jean", "Palate", role = c("aut", "cre"),
email = "[email protected]"),
person("Alain", "Quartier-la-Tente", role = c("aut"),
person("Jean", "Palate", role = c("aut"),
email = "[email protected]"),
person("Alain", "Quartier-la-Tente", role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0001-7890-3857"))
)
comment = c(ORCID = "0000-0001-7890-3857")),
person("Tanguy", "Barthelemy", role = c("ctb", "art"),
email ="[email protected]"),
person("Anna", "Smyk", role = c("ctb"),
email ="[email protected]")
)
Description: This package provides functions to build and apply symmetric
and asymmetric moving averages (= linear filters) for trend-cycle extraction.
In particular, it implements several moderns approaches for real-time estimates
In particular, it implements several modern approaches for real-time estimates
from the viewpoint of revisions and time delay in detecting turning points.
It includes the local polynomial approach of Proietti and Luati (2008), the
Reproducing Kernel Hilbert Space (RKHS) of Dagum and Bianconcini (2008) and
the Fidelity-Smoothness-Timeliness approach of Grun-Rehomme, Guggemos, and Ladiray (2018).
It is based on Java libraries developped around 'JDemetra+' (<https://github.com/jdemetra/jdemetra-app>),
the seasonal adjustment software officially recommended to the members
of the European Statistical System (ESS) and the European System of Central Banks.
It is based on Java libraries developped in 'JDemetra+' (<https://github.com/jdemetra>), time series analysis software.
Depends:
R (>= 3.6.0)
R (>= 4.1.0)
Imports:
rJava (>= 1.0-6),
methods,
MASS,
graphics,
stats,
rjd3toolkit (>= 3.2.2)
Remotes:
github::rjdemetra/rjd3toolkit
Remotes:
github::rjdverse/rjd3toolkit@*release
SystemRequirements: Java (>= 17)
License: EUPL
LazyData: TRUE
URL: https://github.com/rjdemetra/rjd3filters, https://rjdemetra.github.io/rjd3filters/
URL: https://github.com/rjdverse/rjd3filters, https://rjdverse.github.io/rjd3filters/
Suggests:
knitr,
rmarkdown
Expand Down
10 changes: 10 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ S3method(sum,moving_average)
S3method(to_seasonal,default)
S3method(to_seasonal,finite_filters)
export(.jd2r_finitefilters)
export(confint_filter)
export(cp)
export(cross_validation)
export(cv)
export(cve)
export(dfa_filter)
export(diagnostic_matrix)
export(filter)
Expand All @@ -50,9 +54,11 @@ export(get_moving_average)
export(get_properties_function)
export(implicit_forecast)
export(impute_last_obs)
export(is.finite_filters)
export(is.moving_average)
export(is_symmetric)
export(localpolynomials)
export(loocve)
export(lower_bound)
export(lp_filter)
export(mirror)
Expand All @@ -65,6 +71,7 @@ export(rkhs_filter)
export(rkhs_kernel)
export(rkhs_optimal_bw)
export(rkhs_optimization_fun)
export(rt)
export(simple_ma)
export(to_seasonal)
export(upper_bound)
Expand All @@ -91,8 +98,11 @@ importFrom(rjd3toolkit,.r2jd_matrix)
importFrom(stats,coef)
importFrom(stats,coefficients)
importFrom(stats,deltat)
importFrom(stats,end)
importFrom(stats,frequency)
importFrom(stats,is.ts)
importFrom(stats,qnorm)
importFrom(stats,start)
importFrom(stats,time)
importFrom(stats,ts)
importFrom(stats,ts.union)
24 changes: 21 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [2.1.1] - 2024-07-12


### Changed

* `cross_validation()` function renamed to `cve()`, `cross_validation()` is now deprecated.
* New .jar files added (related to [v2.2.0](https://github.com/jdemetra/jdplus-incubator/releases/tag/v2.2.0))

### Added

* New functions to compute functions to compute diagnostics and goodness of fit of filtered series: cross validation (`cv()`) and cross validate estimate (`cve()`), leave-one-out cross validation estimate (`loocve`), CP statistic (`cp()`) and Rice's T statistics (`rt()`).

* New function `confint_filter()` to compute confidence intervals for filtered series.

* New function `is.finite_filters()`.

* New parameter `zero_as_na` in `cbind.moving_average`, boolean indicating if trealing and leading zeros added to have a matrix form should be replaced by `NA`.

## [2.0.0] - 2023-12-12

Expand All @@ -23,6 +40,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
* New Jars


[Unreleased]: https://github.com/rjdemetra/rjd3filters/compare/v2.0.0...HEAD
[2.0.0]: https://github.com/rjdemetra/rjd3filters/releases/tag/v1.0.0...v2.0.0
[1.0.0]: https://github.com/rjdemetra/rjd3filters/releases/tag/v1.0.0
[Unreleased]: https://github.com/rjdverse/rjd3filters/compare/v2.1.1...HEAD
[2.1.1]: https://github.com/rjdverse/rjd3filters/releases/tag/v2.0.0...v2.1.1
[2.0.0]: https://github.com/rjdverse/rjd3filters/releases/tag/v1.0.0...v2.0.0
[1.0.0]: https://github.com/rjdverse/rjd3filters/releases/tag/v1.0.0
9 changes: 6 additions & 3 deletions R/1_moving_average.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ setClass("moving_average",
#' @param i,j,value indices specifying elements to extract or replace and the new value
#'
#' @param ...,drop,na.rm other parameters.
#' @param zero_as_na boolean indicating if, when merging several moving averages (`cbind`)
#' if trealing and leading zeros added to have a matrix form should be replaced by `NA`.
#'
#' @name filters_operations
NULL

Expand Down Expand Up @@ -72,7 +75,7 @@ NULL
#' @export
moving_average <- function(x, lags = -length(x), trailing_zero = FALSE, leading_zero = FALSE){
if (inherits(x, "moving_average"))
return (x)
return(x)
x <- as.numeric(x)
if (trailing_zero)
x <- rm_trailing_zero_or_na(x)
Expand Down Expand Up @@ -113,7 +116,7 @@ moving_average <- function(x, lags = -length(x), trailing_zero = FALSE, leading_
is.moving_average <- function(x){
is(x, "moving_average")
}
#' @importFrom stats coef coefficients
#' @importFrom stats coef coefficients end qnorm ts.union
#' @export
coef.moving_average <- function(object, ...){
coefs <- object@coefficients
Expand Down Expand Up @@ -190,7 +193,7 @@ setMethod("[",
indices <- seq_along(coefs)[i]
coefs[-indices] <- 0
if (all(coefs == 0))
return (moving_average(0, lags = lower_bound(x) + indices - 1))
return(moving_average(0, lags = lower_bound(x) + indices - 1))

moving_average(coefs, lags = lower_bound(x),
leading_zero = TRUE, trailing_zero = TRUE)
Expand Down
22 changes: 16 additions & 6 deletions R/2_finite_filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ setClass("finite_filters",
#' @param first_to_last boolean indicating if the first element of `rfilters` is the
#' first asymmetric filter (when only one observation is missing) or the last one (real-time estimates).
#' @param object `finite_filters` object.
#' @param x object to test the class.
#'
#' @examples
#' ff_lp <- lp_filter()
Expand All @@ -33,17 +34,17 @@ finite_filters.moving_average <- function(sfilter,
rfilters = NULL,
lfilters = NULL,
first_to_last = FALSE){
if (is.null(lfilters) & !is.null(rfilters)) {
if (is.null(lfilters) && !is.null(rfilters)) {
if (first_to_last) {
rfilters <- rev(rfilters)
}
lfilters <- rev(lapply(rfilters, rev.moving_average))
} else if (!is.null(lfilters) & is.null(rfilters)) {
} else if (!is.null(lfilters) && is.null(rfilters)) {
if (!first_to_last) {
lfilters <- rev(lfilters)
}
rfilters <- rev(lapply(lfilters, rev.moving_average))
} else if (is.null(lfilters) & is.null(rfilters)) {
} else if (is.null(lfilters) && is.null(rfilters)) {
rfilters <- lfilters <- list()

}
Expand Down Expand Up @@ -81,6 +82,11 @@ finite_filters.matrix <- function(sfilter,
finite_filters(coefs, first_to_last = first_to_last)
}

#' @rdname finite_filters
#' @export
is.finite_filters <- function(x){
is(x, "finite_filters")
}

#' @export
.jd2r_finitefilters <- function(jf, first_to_last){
Expand All @@ -100,7 +106,7 @@ finite_filters.matrix <- function(sfilter,
rfilters <- rev(rfilters)
}
} else {
if(first_to_last) {
if (first_to_last) {
lfilters <- rev(lfilters)
rfilters <- rev(rfilters)
}
Expand Down Expand Up @@ -323,7 +329,7 @@ as.matrix.finite_filters <- function(x, sfilter = TRUE, rfilters = TRUE, lfilter
sfilter_s <- rfilters_s <- lfilters_s <-
index_s <- index_r <- index_l <- NULL
if (!any(sfilter, rfilters, lfilters))
return (NULL)
return(NULL)
if (sfilter) {
sfilter_s <- list(x@sfilter)
index_s <- length(x@rfilters)
Expand Down Expand Up @@ -498,7 +504,11 @@ to_seasonal.finite_filters <- function(x, s){
#' @details
#' When combining finite filters and a moving average, the first and/or the last points cannot be computed.
#'
#' For example, using the M2X12 moving average (symmetric moving average with coefficients \eqn{\theta = \begin{pmatrix} 1/24 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/12 & 1/24 \end{pmatrix}}), the first and last 6 points cannot be computed.
#' For example, using the M2X12 moving average, that is to say the symmetric moving average with coefficients
#' \deqn{
#' \theta = \frac{1}{24}B^{6} + \frac{1}{12}B^{5}+\dots+\frac{1}{12}B^{-5}+\frac{1}{24}B^{-6},
#' }
#' the first and last 6 points cannot be computed.
#'
#' `impute_last_obs()` allows to impute the first/last points using the `nperiod` previous filtered data. With `nperiod = 1`, the last filtered data is used for the imputation, with `nperiod = 12` and monthly data, the last year filtered data is used for the imputation, etc.
#'
Expand Down
7 changes: 1 addition & 6 deletions R/RKHS.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@
#' @examples
#' rkhs <- rkhs_filter(horizon = 6, asymmetricCriterion = "Timeliness")
#' plot_coef(rkhs)
#' @return An object of class \code{"rkhs_filter"}, which is a list of 4 elements:\itemize{
#' \item{\code{"internal"}}{Java object used for internal functions}
#' \item{\code{"filters.coef"}}{The coefficients of the selected filter}
#' \item{\code{"filters.gain"}}{The gain function between 0 and pi (601 observations)}
#' \item{\code{"filters.phase"}}{The phase function between 0 and pi (601 observations)}
#' }
#' @return a [finite_filters()] object.
#' @export
rkhs_filter <- function(horizon = 6, degree = 2,
kernel = c("BiWeight", "Henderson", "Epanechnikov", "Triangular", "Uniform", "TriWeight"),
Expand Down
Loading

0 comments on commit f02d45f

Please sign in to comment.