| Title: | Tools to Help to Publish the Trend-Cycle Component |
|---|---|
| Description: | Tools to facilitate the computation of the trend-cycle component of time series. In particular, the computation can be performed using: the Cascade Linear Filter ('CLF', Dagum and Luati, 2008), classical Henderson symmetric filters with surrogate Musgrave asymmetric filters, local parameterizations of Musgrave filters (Quartier-la-Tente, 2024), and robust extensions taking into account additive outliers and level shifts (Quartier-la-Tente, 2025). Computes confidence intervals and provides specialized plotting functions for publication. |
| Authors: | Alain Quartier-la-Tente [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-7890-3857>) |
| Maintainer: | Alain Quartier-la-Tente <[email protected]> |
| License: | EUPL |
| Version: | 0.2.3 |
| Built: | 2026-10-12 23:12:52 UTC |
| Source: | https://github.com/AQLT/publishTC |
Retrieves the bandwidth of the filter used in a "tc_estimates" object.
bandwidth(x)bandwidth(x)
x |
An object of class |
The bandwidth corresponds to the number of observations on each side of the central
value for a symmetric trend-cycle filter.
The total filter length is equal to .
An integer representing the bandwidth of the trend-cycle filter.
x <- french_ipi[, "manufacturing"] tc_clf <- henderson_smoothing(x) bandwidth(tc_clf)x <- french_ipi[, "manufacturing"] tc_clf <- henderson_smoothing(x) bandwidth(tc_clf)
Datasets containing coefficients of classical moving averages used for trend-cycle extraction.
henderson CLF CLF_CN local_param_esthenderson CLF CLF_CN local_param_est
henderson is a list of objects of class "moving_average".
CLF is an object of class "finite_filters".
CLF_CN is an object of class "finite_filters".
local_param_est is a nested list of objects of class "finite_filters".
The first level corresponds to the length of the filter;
the second level corresponds to the degree of the local polynomial model used for the trend-cycle;
and the third level corresponds to the target component (1 for bias, 2 for slope, and 3 for curvature).
henderson: Henderson moving averages of lengths 5, 7, 9, 13, and 23.
CLF: Cascade Linear Filter (CLF) of length 13 and associated Asymmetric
Linear Filters (ALF).
CLF_CN: Cascade Linear Filter (CLF) of length 13 and associated cut-and-normalize
asymmetric filters.
local_param_est: Moving averages used to locally estimate the bias, slope, or curvature
associated with trend-cycle estimation (via local polynomial approximation).
Dagum, E. B., & Luati, A. (2008). A Cascade Linear Filter to Reduce Revisions and False Turning Points for Real Time Trend-Cycle Estimation. Econometric Reviews, 28(1-3), 40–59. doi:10.1080/07474930802387837
Henderson, R. (1916). Note on graduation by adjusted average. Transactions of the Actuarial Society of America, 17, 43–48.
Musgrave, J. (1964). A Set of End Weights to End All End Weights. US Census Bureau [Custodian]. https://www.census.gov/library/working-papers/1964/adrm/musgrave-01.html
Quartier-la-Tente, A. (2024). Improving Real-Time Trend Estimates Using Local Parametrization of Polynomial Regression Filters. Journal of Official Statistics, 40(4), 685–715. doi:10.1177/0282423X241283207
Estimates the trend-cycle component using the Cascade Linear Filter (CLF) of length 13.
clf_smoothing(x, endpoints = c("cut-and-normalize", "ALF"), ...)clf_smoothing(x, endpoints = c("cut-and-normalize", "ALF"), ...)
x |
An input time series (object of class |
endpoints |
Character string specifying the method used for asymmetric filters.
If |
... |
Other unused parameters. |
An object of class c("tc_estimates", "clf").
See tc_estimates() for a full description of the returned object.
Dagum, E. B., & Luati, A. (2008). A Cascade Linear Filter to Reduce Revisions and False Turning Points for Real Time Trend-Cycle Estimation. Econometric Reviews 28(1-3), 40–59. doi:10.1080/07474930802387837
tc <- clf_smoothing(cars_registrations) plot(tc, xlim = c(2022, 2025))tc <- clf_smoothing(cars_registrations) plot(tc, xlim = c(2022, 2025))
Base R (confint_plot()) and ggplot2 (ggconfint_plot()) graphics for
plotting trend-cycle estimates alongside their confidence intervals.
confint_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_confint = "grey", xlab = "", ylab = "", level = 0.95, ... ) ggconfint_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_confint = "grey", legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", legend_confint = "Confidence interval", level = 0.95, ... )confint_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_confint = "grey", xlab = "", ylab = "", level = 0.95, ... ) ggconfint_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_confint = "grey", legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", legend_confint = "Confidence interval", level = 0.95, ... )
object |
An object of class |
xlim, ylim
|
Limits for the x- and y-axes.
If |
col_sa, col_tc
|
Colors used for the seasonally adjusted and trend-cycle components, respectively. |
col_confint |
Color of the confidence interval lines or shaded region. |
xlab, ylab
|
Character strings for the x- and y-axis labels. |
level |
The confidence level required (defaults to |
... |
Additional arguments (currently unused). |
legend_tc, legend_sa, legend_confint
|
Character strings specifying the legend labels for the trend-cycle, the seasonally adjusted series, and the confidence intervals, respectively. |
confint_plot() produces a base R graphic, whereas ggconfint_plot() creates a
ggplot2 object that can be further customized.
The confidence intervals are computed internally using confint().
confint_plot() returns NULL invisibly and is called for its side effect (drawing a plot).
ggconfint_plot() returns a ggplot object.
tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) confint_plot(tc_mod, xlim = c(2022, 2024.5))tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) confint_plot(tc_mod, xlim = c(2022, 2024.5))
Computes confidence intervals for trend-cycle estimates of class "tc_estimates".
## S3 method for class 'henderson' confint(object, parm, level = 0.95, asymmetric_var = TRUE, ...) ## S3 method for class 'clf' confint(object, parm, level = 0.95, asymmetric_var = TRUE, ...) ## S3 method for class 'robust_henderson' confint(object, parm, level = 0.95, asymmetric_var = TRUE, ...)## S3 method for class 'henderson' confint(object, parm, level = 0.95, asymmetric_var = TRUE, ...) ## S3 method for class 'clf' confint(object, parm, level = 0.95, asymmetric_var = TRUE, ...) ## S3 method for class 'robust_henderson' confint(object, parm, level = 0.95, asymmetric_var = TRUE, ...)
object |
An object of class |
parm |
Unused parameter, kept for compatibility with the generic function. |
level |
The confidence level required (defaults to |
asymmetric_var |
Logical. If |
... |
Additional arguments (currently unused). |
See rjd3filters::confint_filter() for details on the computation of confidence intervals.
A matrix or mts object with the filtered series and the lower and upper bounds of the confidence interval.
x <- cars_registrations tc <- henderson_smoothing(x) confint <- confint(tc) plot(confint, plot.type = "single", col = c("red", "black", "black"), lty = c(1, 2, 2), xlab = NULL, ylab = NULL) lines(x, col = "grey") legend("topleft", legend = c("x", "Smoothed", "CI (95%)"), col= c("grey", "red", "black"), lty = c(1, 1, 2))x <- cars_registrations tc <- henderson_smoothing(x) confint <- confint(tc) plot(confint, plot.type = "single", col = c("red", "black", "black"), lty = c(1, 2, 2), xlab = NULL, ylab = NULL) lines(x, col = "grey") legend("topleft", legend = c("x", "Smoothed", "CI (95%)"), col= c("grey", "red", "black"), lty = c(1, 1, 2))
Generates a list of ggplot2 graphics displaying various diagnostic and
comparative plots for a "tc_estimates" object.
ggsmoothing_plot( object, plots = c("normal", "confint", "lollypop", "implicit_forecasts", "underlying_forecasts"), level = 0.95, ... )ggsmoothing_plot( object, plots = c("normal", "confint", "lollypop", "implicit_forecasts", "underlying_forecasts"), level = 0.95, ... )
object |
An object of class |
plots |
A character vector specifying the types of plots to generate.
Available options are |
level |
The confidence level required (defaults to |
... |
Additional graphical arguments passed to internal plotting functions. |
The following plot types can be produced:
"normal": Standard plot showing trend-cycle and seasonally adjusted series via autoplot.tc_estimates().
"confint": Confidence interval plot via ggconfint_plot().
"lollypop": Lollipop chart comparing estimates via gglollypop().
"implicit_forecasts": Implicit forecasts plot via ggimplicit_forecasts_plot().
"underlying_forecasts": Underlying forecasts plot via ggunderlying_forecasts_plot().
A list of ggplot objects corresponding to the requested plots.
x <- cars_registrations tc <- henderson_smoothing(x) ggsmoothing_plot(tc)x <- cars_registrations tc <- henderson_smoothing(x) ggsmoothing_plot(tc)
Base R (growthplot()) and ggplot2 (gggrowthplot()) graphics for
plotting the growth rates of the trend-cycle estimates (solid lines) and
the seasonally adjusted series (bar-lines or lines).
growthplot( object, pct = TRUE, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", xlab = "", ylab = "", sa_bar_line = TRUE, ..., lag = -1 ) gggrowthplot( object, pct = TRUE, xlim = NULL, ylim = NULL, sa_bar_line = TRUE, col_tc = "#E69F00", col_sa = "black", col_sa_fill = "grey", legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", ..., lag = -1 )growthplot( object, pct = TRUE, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", xlab = "", ylab = "", sa_bar_line = TRUE, ..., lag = -1 ) gggrowthplot( object, pct = TRUE, xlim = NULL, ylim = NULL, sa_bar_line = TRUE, col_tc = "#E69F00", col_sa = "black", col_sa_fill = "grey", legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", ..., lag = -1 )
object |
An object of class |
pct |
Logical. If |
xlim, ylim
|
Limits for the x- and y-axes.
If |
col_sa, col_tc
|
Colors used for the seasonally adjusted and trend-cycle components, respectively. |
xlab, ylab
|
Character strings for the x- and y-axis labels. |
sa_bar_line |
Logical. If |
... |
Additional graphical parameters passed to internal plotting functions. |
lag |
Integer specifying the lag used to compute the growth rate.
Defaults to |
col_sa_fill |
Fill color of the bars for the seasonally adjusted series. |
legend_tc, legend_sa
|
Character strings specifying the legend labels for the trend-cycle and seasonally adjusted components, respectively. |
growthplot() produces a base R graphic, whereas gggrowthplot() creates a
ggplot2 object that can be further customized.
growthplot() returns NULL invisibly and is called for its side effect (drawing a plot).
gggrowthplot() returns a ggplot object.
tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) growthplot(tc_mod, xlim = c(2022, 2024.5))tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) growthplot(tc_mod, xlim = c(2022, 2024.5))
Estimates the trend-cycle component using Henderson moving averages robust to outliers (additive outliers and level shifts).
henderson_robust_smoothing( x, endpoints = c("Musgrave", "QL", "CQ", "DAF"), length = NULL, ao = NULL, ao_tc = NULL, ls = NULL, icr = NULL, local_icr = FALSE, asymmetric_var = FALSE, degree = 3, ... )henderson_robust_smoothing( x, endpoints = c("Musgrave", "QL", "CQ", "DAF"), length = NULL, ao = NULL, ao_tc = NULL, ls = NULL, icr = NULL, local_icr = FALSE, asymmetric_var = FALSE, degree = 3, ... )
x |
An input time series (object of class |
endpoints |
Character string specifying the method used for asymmetric filters.
By default, |
length |
An integer specifying the length of the symmetric filter.
If |
ao |
Vector of dates for Additive Outliers (AO) whose effects are allocated to the irregular component. |
ao_tc |
Vector of dates for Additive Outliers (AO) whose effects are allocated to the trend-cycle component. |
ls |
Vector of dates for Level Shifts (LS) whose effects are allocated to the trend-cycle component. |
icr |
Numeric value specifying the Irregular-to-Trend (I/C) ratio used for asymmetric filters. |
local_icr |
Logical. If |
asymmetric_var |
Logical. When |
degree |
Integer. When |
... |
Additional arguments passed to |
When outliers are present in a time series, standard linear filters like the Henderson moving average can spread their impact across adjacent trend estimates. This function explicitly accounts for specified Additive Outliers (AO) and Level Shifts (LS) during the filtering process to prevent distortion of the trend-cycle estimates as described in Quartier-la-Tente (2025).
In a nutshell, Henderson smoothing is equivalent to a local polynomial regression of degree 3 (or equivalently 2) estimated with weighted least squares, using specific weights to obtain the Henderson coefficients. Adding regressors to this local regression to account for outliers allows removing their influence on the estimation of polynomial coefficients and thus on the trend-cycle estimates.
An object of class c("tc_estimates", "robust_henderson").
See tc_estimates() for a full description of the returned object.
Quartier-la-Tente, A. (2025). Estimation de la tendance-cycle avec des méthodes robustes aux points atypiques. https://github.com/AQLT/robustMA.
x <- cars_registrations outliers <- x13_regarima_outliers(x) tc <- henderson_robust_smoothing(x, ao = outliers$ao, ls = outliers$ls, local_icr = TRUE) tc_henderson <- henderson_smoothing(x) plot(tc, xlim = c(2019, 2022)) lines(tc_henderson$tc, col = "blue")x <- cars_registrations outliers <- x13_regarima_outliers(x) tc <- henderson_robust_smoothing(x, ao = outliers$ao, ls = outliers$ls, local_icr = TRUE) tc_henderson <- henderson_smoothing(x) plot(tc, xlim = c(2019, 2022)) lines(tc_henderson$tc, col = "blue")
Estimates the trend-cycle component using Henderson moving averages.
henderson_smoothing( x, endpoints = c("Musgrave", "QL", "CQ", "CC", "DAF", "CN"), length = NULL, icr = NULL, local_icr = FALSE, asymmetric_var = FALSE, degree = 3, ... )henderson_smoothing( x, endpoints = c("Musgrave", "QL", "CQ", "CC", "DAF", "CN"), length = NULL, icr = NULL, local_icr = FALSE, asymmetric_var = FALSE, degree = 3, ... )
x |
An input time series (object of class |
endpoints |
Character string specifying the method used for asymmetric filters.
By default, |
length |
An integer specifying the length of the symmetric filter.
If |
icr |
Numeric value specifying the Irregular-to-Trend (I/C) ratio used for asymmetric filters. |
local_icr |
Logical. If |
asymmetric_var |
Logical. When |
degree |
Integer. When |
... |
Additional arguments passed to |
An object of class c("tc_estimates", "henderson").
See tc_estimates() for a full description of the returned object.
Henderson, R. (1916). Note on Graduation by Adjusted Average. Transactions of the Actuarial Society of America 17: 43-48.
Musgrave, J. (1964). A Set of End Weights to End All End Weights. US Census Bureau [Custodian]. https://www.census.gov/library/working-papers/1964/adrm/musgrave-01.html.
Quartier-la-Tente, A. (2024). Improving Real-Time Trend Estimates Using Local Parametrization of Polynomial Regression Filters. Journal of Official Statistics, 40(4), 685-715. doi:10.1177/0282423X241283207.
x <- cars_registrations tc <- henderson_smoothing(x) plot(tc, xlim = c(2022, 2025))x <- cars_registrations tc <- henderson_smoothing(x) plot(tc, xlim = c(2022, 2025))
icr() computes the overall I/C ratio, while icrs() computes the I/C ratios
for each lag up to the series frequency.
icr(x, tc, mul = FALSE) icrs(x, tc, mul = FALSE)icr(x, tc, mul = FALSE) icrs(x, tc, mul = FALSE)
x |
A seasonally adjusted time series or an object of class |
tc |
A time series representing the trend-cycle component. Ignored if |
mul |
Logical indicating whether the decomposition is multiplicative ( |
The I/C ratio measures the relative importance of the irregular component compared to the trend-cycle component in a time series decomposition.
For a time series of frequency , when the decomposition is additive
(mul = FALSE), the irregular component is defined as .
icrs() returns a vector containing the ratio of the mean absolute variation
of the irregular component to that of the trend-cycle component for each lag :
If the decomposition is multiplicative (mul = TRUE), the irregular component is
defined as , and the ratio of relative variations is computed as:
icr() returns the overall I/C ratio, which corresponds to the first lag ratio
.
icr() returns a single numeric value representing the overall I/C ratio,
while icrs() returns a named numeric vector of I/C ratios for lags to .
x <- cars_registrations tc <- henderson_smoothing(x) icr(tc) icrs(tc)x <- cars_registrations tc <- henderson_smoothing(x) icr(tc) icrs(tc)
Base R (implicit_forecasts_plot()) and ggplot2 (ggimplicit_forecasts_plot())
graphics for plotting trend-cycle estimates alongside their implicit forecasts.
implicit_forecasts_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_i_f = col_sa, xlab = "", ylab = "", lty_last_tc = 2, lty_i_f = 3, n_last_tc = 4, ... ) ggimplicit_forecasts_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_i_f = col_sa, lty_last_tc = 2, lty_i_f = 3, n_last_tc = 4, legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", legend_i_f = "Implicit forecasts", ... )implicit_forecasts_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_i_f = col_sa, xlab = "", ylab = "", lty_last_tc = 2, lty_i_f = 3, n_last_tc = 4, ... ) ggimplicit_forecasts_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_i_f = col_sa, lty_last_tc = 2, lty_i_f = 3, n_last_tc = 4, legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", legend_i_f = "Implicit forecasts", ... )
object |
An object of class |
xlim, ylim
|
Limits for the x- and y-axes.
If |
col_sa, col_tc
|
Colors used for the seasonally adjusted and trend-cycle components, respectively. |
col_i_f |
Color of the forecasts lines. |
xlab, ylab
|
Character strings for the x- and y-axis labels. |
lty_last_tc, lty_i_f
|
Line types used for the last values of the trend-cycle component and for the forecasts, respectively. |
n_last_tc |
Number of final values of the trend-cycle component to plot
with a distinct line type ( |
... |
Additional graphical parameters passed to internal plotting functions. |
legend_tc, legend_sa, legend_i_f
|
Character strings specifying the legend labels for the trend-cycle, the seasonally adjusted series, and the forecasts, respectively. |
implicit_forecasts_plot() produces a base R graphic, whereas
ggimplicit_forecasts_plot() creates a ggplot2 object that can be further customized.
implicit_forecasts_plot() returns NULL invisibly and is called for its side effect (drawing a plot).
ggimplicit_forecasts_plot() returns a ggplot object.
tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) implicit_forecasts_plot(tc_mod, xlim = c(2022, 2025))tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) implicit_forecasts_plot(tc_mod, xlim = c(2022, 2025))
S3 method of rjd3filters::implicit_forecasts() for "tc_estimates" objects.
## S3 method for class 'henderson' implicit_forecasts(x, ...) ## S3 method for class 'clf' implicit_forecasts(x, ...) ## S3 method for class 'robust_henderson' implicit_forecasts(x, ...)## S3 method for class 'henderson' implicit_forecasts(x, ...) ## S3 method for class 'clf' implicit_forecasts(x, ...) ## S3 method for class 'robust_henderson' implicit_forecasts(x, ...)
x |
An object of class |
... |
Additional arguments passed to internal methods (currently unused). |
See rjd3filters::implicit_forecasts() for details on the computation of implicit forecasts.
A matrix or mts object containing the implicit forecasts for the series.
tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) implicit_forecasts(tc_mod)tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) implicit_forecasts(tc_mod)
Base R (lollypop()) and ggplot2 (gglollypop()) graphics for creating
lollipop plots of trend-cycle estimates alongside seasonally adjusted series.
lollypop( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", color_points = col_sa, cex_points = 1, pch_points = 16, xlab = "", ylab = "", lty_last_tc = 2, n_last_tc = 4, ... ) gglollypop( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", color_points = col_sa, cex_points = 1, pch_points = 16, legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", lty_last_tc = 2, n_last_tc = 4, ... )lollypop( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", color_points = col_sa, cex_points = 1, pch_points = 16, xlab = "", ylab = "", lty_last_tc = 2, n_last_tc = 4, ... ) gglollypop( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", color_points = col_sa, cex_points = 1, pch_points = 16, legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", lty_last_tc = 2, n_last_tc = 4, ... )
object |
An object of class |
xlim, ylim
|
Limits for the x- and y-axes.
If |
col_sa, col_tc
|
Colors used for the seasonally adjusted and trend-cycle components, respectively. |
color_points, cex_points
|
Color and size (character/numeric) of the points associated with the seasonally adjusted component. |
pch_points |
Point symbol type (integer or character) for the seasonally adjusted component. |
xlab, ylab
|
Character strings for the x- and y-axis labels. |
lty_last_tc |
Line type for the last values of the trend-cycle component. |
n_last_tc |
Number of final values of the trend-cycle component to plot
with a distinct line type ( |
... |
Additional graphical parameters passed to internal plotting functions. |
legend_tc, legend_sa
|
Character strings specifying the legend labels for the trend-cycle and seasonally adjusted components, respectively. |
lollypop() produces a base R graphic, whereas gglollypop() creates a
ggplot2 object that can be further customized.
lollypop() returns NULL invisibly and is called for its side effect (drawing a plot).
gglollypop() returns a ggplot object.
tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) lollypop(tc_mod, xlim = c(2022, 2024.5))tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) lollypop(tc_mod, xlim = c(2022, 2024.5))
Computes the Month of Cyclical Dominance (MCD) for a time series decomposition.
mcd(x, tc, mul = FALSE)mcd(x, tc, mul = FALSE)
x |
A seasonally adjusted time series or an object of class |
tc |
A time series representing the trend-cycle component. Ignored if |
mul |
Logical indicating whether the decomposition is multiplicative ( |
The Month of Cyclical Dominance (MCD) represents the minimum number of months required for the average absolute variation of the trend-cycle component to dominate that of the irregular component. In other words, it indicates the shortest time span needed on average for the cyclical signal to outweigh irregular fluctuations.
It is computed as the smallest integer (where ) such that the I/C ratio
remains less than or equal to 1 for all lags :
If the I/C ratio never falls below or equal to 1 within the frequency , the MCD is set to .
An integer specifying the Month of Cyclical Dominance (MCD).
x <- cars_registrations tc <- henderson_smoothing(x) mcd(tc) icrs(tc)x <- cars_registrations tc <- henderson_smoothing(x) mcd(tc) icrs(tc)
Plotting methods for objects of class "tc_estimates". plot() and lines()
produce base R graphics, whereas autoplot() creates a ggplot2 object.
## S3 method for class 'tc_estimates' plot( x, y = NULL, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", xlab = "", ylab = "", lty_last_tc = 2, n_last_tc = 4, ... ) ## S3 method for class 'tc_estimates' lines(x, col_tc = "#E69F00", lty_last_tc = 2, n_last_tc = 4, ...) ## S3 method for class 'tc_estimates' autoplot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", lty_last_tc = 2, n_last_tc = 4, ... ) ## S3 method for class 'ts' autoplot(object, xlim = NULL, ylim = NULL, ...)## S3 method for class 'tc_estimates' plot( x, y = NULL, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", xlab = "", ylab = "", lty_last_tc = 2, n_last_tc = 4, ... ) ## S3 method for class 'tc_estimates' lines(x, col_tc = "#E69F00", lty_last_tc = 2, n_last_tc = 4, ...) ## S3 method for class 'tc_estimates' autoplot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", lty_last_tc = 2, n_last_tc = 4, ... ) ## S3 method for class 'ts' autoplot(object, xlim = NULL, ylim = NULL, ...)
x |
An object of class |
y |
Unused parameter, kept for compatibility with the generic function. |
xlim, ylim
|
Limits for the x- and y-axes.
If |
col_sa, col_tc
|
Colors used for the seasonally adjusted and trend-cycle components, respectively. |
xlab, ylab
|
Character strings for the x- and y-axis labels. |
lty_last_tc |
Line type for the last values of the trend-cycle component. |
n_last_tc |
Number of final values of the trend-cycle component to plot
with a distinct line type ( |
... |
Additional graphical parameters passed to internal plotting functions. |
object |
An object of class |
legend_tc, legend_sa
|
Character strings specifying the legend labels for the trend-cycle and seasonally adjusted components, respectively. |
plot.tc_estimates() and autoplot.tc_estimates() produce a plot showing both
the seasonally adjusted series and the estimated trend-cycle component.
lines.tc_estimates() adds only the trend-cycle component to an existing base R plot.
plot() and lines() return NULL invisibly and are called for their side effect (drawing a plot).
autoplot() returns a ggplot object.
tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) plot(tc_mod, xlim = c(2022, 2024.5))tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) plot(tc_mod, xlim = c(2022, 2024.5))
Estimates the trend-cycle component by segmenting a time series around known structural breakpoints.
segmented_smoothing( x, breaks = NULL, break_method = c("one-side", "two-sides"), smoothing_method = c("henderson_smoothing", "clf_smoothing"), ... )segmented_smoothing( x, breaks = NULL, break_method = c("one-side", "two-sides"), smoothing_method = c("henderson_smoothing", "clf_smoothing"), ... )
x |
An input time series (object of class |
breaks |
A vector or list of breakpoints (dates) where the series should be split for smoothing. |
break_method |
Character string specifying the method used to handle boundaries at breakpoints:
|
smoothing_method |
Function specifying the smoothing method to apply to each segment.
Must be |
... |
Additional arguments passed to |
Two methods are available to estimate the trend-cycle around breakpoints:
"one-side": The trend-cycle is estimated across the entire dataset, and the estimates
after each breakpoint are overwritten with the estimates obtained by smoothing only
the data following that breakpoint.
"two-sides": The trend-cycle is estimated independently on each segment defined
by the breakpoints, and the resulting estimates are combined to form the final trend-cycle.
The parameters field of the returned object corresponds to the parameters of the last segment
(used to compute confidence intervals and implicit forecasts).
An object of class c("tc_estimates", "henderson") if
smoothing_method is henderson_smoothing(), or c("tc_estimates", "clf")
if smoothing_method is clf_smoothing().
x <- window(publishTC::french_ipi[, "manufacturing"], start = 2015) tc_h <- henderson_smoothing(x, length = 13)$tc breaks <- list(c(2020, 3)) tc_h_2s <- segmented_smoothing(x, breaks = breaks, break_method = "two-sides", length = 13)$tc tc_h_rob <- henderson_robust_smoothing(x, ls = c(2020 + (3 - 1) / 12, 2020 + (4 - 1) / 12))$tc plot(window(x, start = 2019.5, end = 2021), main = "Smoothing around COVID-19", xlab = NULL, ylab = NULL, lty = 3 ) lines(tc_h, col = "purple") lines(tc_h_2s, col = "lightblue") lines(tc_h_rob, col = "orange") legend( "bottomright", legend = c("y", "Henderson", "Two-Sides Segmented", "Robust H. (2 LS)"), col = c("black", "purple", "lightblue", "orange"), lty = c(3, 1, 1, 1, 1), cex = 0.7 )x <- window(publishTC::french_ipi[, "manufacturing"], start = 2015) tc_h <- henderson_smoothing(x, length = 13)$tc breaks <- list(c(2020, 3)) tc_h_2s <- segmented_smoothing(x, breaks = breaks, break_method = "two-sides", length = 13)$tc tc_h_rob <- henderson_robust_smoothing(x, ls = c(2020 + (3 - 1) / 12, 2020 + (4 - 1) / 12))$tc plot(window(x, start = 2019.5, end = 2021), main = "Smoothing around COVID-19", xlab = NULL, ylab = NULL, lty = 3 ) lines(tc_h, col = "purple") lines(tc_h_2s, col = "lightblue") lines(tc_h_rob, col = "orange") legend( "bottomright", legend = c("y", "Henderson", "Two-Sides Segmented", "Robust H. (2 LS)"), col = c("black", "purple", "lightblue", "orange"), lty = c(3, 1, 1, 1, 1), cex = 0.7 )
Computes trend-cycle estimates using multiple smoothing methods simultaneously
and returns a list of "tc_estimates" objects.
smoothing( x, methods = c("henderson", "henderson_localic", "henderson_robust", "henderson_robust_localic", "clf_cn", "clf_alf"), endpoints = "Musgrave", length = NULL, icr = NULL, asymmetric_var = FALSE, degree = 3, ao = NULL, ao_tc = NULL, ls = NULL, ... )smoothing( x, methods = c("henderson", "henderson_localic", "henderson_robust", "henderson_robust_localic", "clf_cn", "clf_alf"), endpoints = "Musgrave", length = NULL, icr = NULL, asymmetric_var = FALSE, degree = 3, ao = NULL, ao_tc = NULL, ls = NULL, ... )
x |
An input time series (object of class |
methods |
A list of character strings specifying the smoothing methods to apply.
Defaults to |
endpoints |
Character string specifying the method used for asymmetric filters.
By default, |
length |
An integer specifying the length of the symmetric filter.
If |
icr |
Numeric value specifying the Irregular-to-Trend (I/C) ratio used for asymmetric filters. |
asymmetric_var |
Logical. When |
degree |
Integer. When |
ao |
Vector of dates for Additive Outliers (AO) whose effects are allocated to the irregular component. |
ao_tc |
Vector of dates for Additive Outliers (AO) whose effects are allocated to the trend-cycle component. |
ls |
Vector of dates for Level Shifts (LS) whose effects are allocated to the trend-cycle component. |
... |
Additional parameters passed to the underlying smoothing functions. |
This convenience function applies multiple trend-cycle estimation algorithms to the same input series, facilitating direct comparison between different filtering approaches (e.g., standard Henderson, Henderson with local I/C ratio, or CLF smoothing).
A named list of objects of class "tc_estimates", where each element
corresponds to one of the specified methods in methods.
x <- french_ipi[, "manufacturing"] outliers <- x13_regarima_outliers(x) all_methods <- smoothing(x, ao = outliers$ao, ao_tc = outliers$ao_tc, ls = outliers$ls) plot(all_methods$henderson, xlim = c(2023, 2025)) lines(all_methods$henderson_localic, col_tc = "blue")x <- french_ipi[, "manufacturing"] outliers <- x13_regarima_outliers(x) all_methods <- smoothing(x, ao = outliers$ao, ao_tc = outliers$ao_tc, ls = outliers$ls) plot(all_methods$henderson, xlim = c(2023, 2025)) lines(all_methods$henderson_localic, col_tc = "blue")
Computes the smoothness ratio of trend-cycle estimates relative to the seasonally adjusted series following Picard and Matthews (2016).
smoothness(x)smoothness(x)
x |
An object of class |
Smoothness is evaluated as the ratio of month-to-month growth rate variances:
This metric quantifies the relative variability of the trend-cycle compared to the seasonally adjusted series. A lower value indicates a smoother trend-cycle.
A numeric value representing the smoothness index of the trend-cycle estimates.
Picard, F., & Matthews, S. (2016). The Addition of Trend-Cycle Estimates to Selected Publications at Statistics Canada. Proceedings of the Survey Methods Section, Statistical Society of Canada (SSC) Annual Meeting. https://ssc.ca/sites/default/files/imce/pdf/picard_ssc2016.pdf
x <- french_ipi[, "manufacturing"] tc_clf <- clf_smoothing(x) tc_henderson <- henderson_smoothing(x) smoothness(tc_clf) smoothness(tc_henderson)x <- french_ipi[, "manufacturing"] tc_clf <- clf_smoothing(x) tc_henderson <- henderson_smoothing(x) smoothness(tc_clf) smoothness(tc_henderson)
Constructor and S3 methods for objects of class "tc_estimates".
tc_estimates(tc, sa, parameters = NULL, extra_class = NULL, ...) is_tc_estimates(x) ## S3 method for class 'tc_estimates' summary(object, ...)tc_estimates(tc, sa, parameters = NULL, extra_class = NULL, ...) is_tc_estimates(x) ## S3 method for class 'tc_estimates' summary(object, ...)
tc |
Time series object ( |
sa |
Time series object ( |
parameters |
A list of parameters used to compute the trend-cycle estimates (e.g., filter coefficients, variance, or degree of polynomial). |
extra_class |
Character string specifying an additional class to append to the returned object. |
... |
Additional arguments passed to or from other methods (currently unused). |
x |
An object of class |
object |
An object of class |
Objects of class "tc_estimates" store trend-cycle estimates along with the
original series and metadata required for summary statistics, confidence intervals,
and implicit forecasts.
tc_estimates() returns an object of class c("tc_estimates", extra_class),
which is a list containing the following components:
tc: The estimated trend-cycle time series.
x: The original (seasonally adjusted) time series.
parameters: A list of parameters used during estimation.
The summary() method returns a list of class "summary.tc_estimates" containing:
I/C ratio: The overall Irregular-to-Trend-Cycle ratio (see icr()).
I/C ratios: The I/C ratio per period (see icrs()).
MCD: The Month of Cyclical Dominance statistic (see mcd()).
Length: The length of the symmetric trend-cycle filter.
x <- cars_registrations tc <- henderson_smoothing(x) summary(tc) print(tc)x <- cars_registrations tc <- henderson_smoothing(x) summary(tc) print(tc)
Example datasets used in Quartier-la-Tente (2025).
cars_registrations french_ipi fred simulated_data etipcars_registrations french_ipi fred simulated_data etip
An object of class ts of length 177.
An object of class mts (inherits from ts, matrix, array) with 416 rows and 3 columns.
An object of class mts (inherits from ts, matrix, array) with 766 rows and 2 columns.
An object of class mts (inherits from ts, matrix, array) with 84 rows and 6 columns.
An object of class ts of length 590.
cars_registrations: Monthly new passenger car registrations in France,
published in October 2024.
french_ipi: Monthly Industrial Production Index (IPI) in France for crude
petroleum, motor vehicles, and manufacturing, published in October 2024.
fred: The series CE16OV (Civilian Employment Level) and RETAILx
(Retail and Food Services Sales) from the FRED-MD database, published in
November 2022.
simulated_data: Simulated trends of degree 0, 1, and 2 with an Additive
Outlier (AO) or Level Shift (LS) in January 2022.
etip: Expected trend in production (balance of opinion) in the French
manufacturing industry, published in May 2024 in the monthly business survey
in goods-producing industries by INSEE.
Quartier-la-Tente, A. (2025). Estimation de la tendance-cycle avec des méthodes robustes aux points atypiques. https://github.com/AQLT/robustMA. McCracken, Michael W., et Serena Ng. 2016. FRED-MD: A Monthly Database for Macroeconomic Research. Journal of Business & Economic Statistics 34 (4): 574‑89. https://doi.org/10.1080/07350015.2015.1086655.
Identifies turning points (upturns and downturns) and unwanted short-term ripples in a time series object using local extremum criteria.
turning_points(x, start = NULL, end = NULL, digits = 6, k = 3, m = 1) upturn(x, start = NULL, end = NULL, digits = 6, k = 3, m = 1) downturn(x, start = NULL, end = NULL, digits = 6, k = 3, m = 1) unwanted_ripples(x, start = NULL, end = NULL, digits = 6, k = 3, m = 1)turning_points(x, start = NULL, end = NULL, digits = 6, k = 3, m = 1) upturn(x, start = NULL, end = NULL, digits = 6, k = 3, m = 1) downturn(x, start = NULL, end = NULL, digits = 6, k = 3, m = 1) unwanted_ripples(x, start = NULL, end = NULL, digits = 6, k = 3, m = 1)
x |
An input time series (object of class |
start, end
|
Numeric vectors specifying the start and end of the time interval
(e.g., |
digits |
Integer specifying the number of decimal digits used when comparing
values to determine turning points. Defaults to |
k, m
|
Integers specifying the required number of preceding ( |
Turning points are identified following the operational definition adapted from
Zellner, Hong, and Min (1991), typically with and :
An upturn occurs at time if:
A downturn occurs at time if:
An unwanted ripple is defined as any occurrence where two turning points of the same type (two upturns or two downturns) occur within a 10-month window (i.e., short cycles lasting less than 11 months).
turning_points() returns a named list with two components: "upturn" and
"downturn", each containing a vector of dates (or empty vectors if none found).
upturn() and downturn() return a vector of dates corresponding to the
detected upturns or downturns, respectively.
unwanted_ripples() returns an integer representing the number of unwanted
ripples detected in the series.
Zellner, A., Hong, C., & Min, C. (1991). Forecasting Turning Points in International Growth Rates using Bayesian Exponential Smoothing Methods. Journal of Econometrics, 49(1–2), 275–304. doi:10.1016/0304-4076(91)90016-7
tc <- henderson_smoothing(french_ipi[, "manufacturing"]) turning_points(tc) unwanted_ripples(tc)tc <- henderson_smoothing(french_ipi[, "manufacturing"]) turning_points(tc) unwanted_ripples(tc)
Base R (underlying_forecasts_plot()) and ggplot2 (ggunderlying_forecasts_plot())
graphics for plotting trend-cycle estimates alongside their underlying forecasts.
underlying_forecasts_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_i_f = col_sa, xlab = "", ylab = "", lty_last_tc = 2, lty_i_f = 3, n_last_tc = 4, ... ) ggunderlying_forecasts_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_i_f = col_sa, lty_last_tc = 2, lty_i_f = 3, n_last_tc = 4, legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", legend_i_f = "Implicit forecasts", ... )underlying_forecasts_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_i_f = col_sa, xlab = "", ylab = "", lty_last_tc = 2, lty_i_f = 3, n_last_tc = 4, ... ) ggunderlying_forecasts_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_i_f = col_sa, lty_last_tc = 2, lty_i_f = 3, n_last_tc = 4, legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", legend_i_f = "Implicit forecasts", ... )
object |
An object of class |
xlim, ylim
|
Limits for the x- and y-axes.
If |
col_sa, col_tc
|
Colors used for the seasonally adjusted and trend-cycle components, respectively. |
col_i_f |
Color of the forecasts lines. |
xlab, ylab
|
Character strings for the x- and y-axis labels. |
lty_last_tc, lty_i_f
|
Line types used for the last values of the trend-cycle component and for the forecasts, respectively. |
n_last_tc |
Number of final values of the trend-cycle component to plot
with a distinct line type ( |
... |
Additional graphical parameters passed to internal plotting functions. |
legend_tc, legend_sa, legend_i_f
|
Character strings specifying the legend labels for the trend-cycle, the seasonally adjusted series, and the forecasts, respectively. |
underlying_forecasts_plot() produces a base R graphic, whereas
ggunderlying_forecasts_plot() creates a ggplot2 object that can be further customized.
underlying_forecasts_plot() returns NULL invisibly and is called for its side effect (drawing a plot).
ggunderlying_forecasts_plot() returns a ggplot object.
tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) underlying_forecasts_plot(tc_mod, xlim = c(2022, 2025))tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) underlying_forecasts_plot(tc_mod, xlim = c(2022, 2025))
S3 method of rjd3filters::underlying_forecasts() for "tc_estimates" objects.
## S3 method for class 'henderson' underlying_forecasts(x, ...) ## S3 method for class 'clf' underlying_forecasts(x, ...) ## S3 method for class 'robust_henderson' underlying_forecasts(x, ...)## S3 method for class 'henderson' underlying_forecasts(x, ...) ## S3 method for class 'clf' underlying_forecasts(x, ...) ## S3 method for class 'robust_henderson' underlying_forecasts(x, ...)
x |
An object of class |
... |
Additional arguments passed to internal methods (currently unused). |
See rjd3filters::underlying_forecasts() for details on the computation of underlying forecasts.
A matrix or mts object containing the underlying forecasts for the series.
tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) underlying_forecasts(tc_mod)tc_mod <- henderson_smoothing(french_ipi[, "manufacturing"]) underlying_forecasts(tc_mod)
write.ts() exports a time series object ("ts") or a list of time series to
a CSV file, adding a "time" column. read.ts() imports a CSV file whose first
column contains dates and reconstructs the corresponding ts object.
write.ts(x, file, ...) read.ts(file, frequency = NULL, list = FALSE)write.ts(x, file, ...) read.ts(file, frequency = NULL, list = FALSE)
x |
A time series object (class |
file |
A character string specifying the path to the CSV file to write or read. |
... |
Additional arguments passed to |
frequency |
An integer specifying the number of observations per unit of time
(e.g., 12 for monthly, 4 for quarterly). If |
list |
Logical. If |
write.ts() formats the time index into a dedicated date column (e.g., YYYY-MM-DD or
fractional years) alongside the data series. When reading back with read.ts(), the time
index is parsed to reconstruct regular R time series objects.
write.ts() returns NULL invisibly and is called for its side effect (writing a CSV file).
read.ts() returns a "ts" object, a multiple time series ("mts"), or a list of "ts" objects depending on list.
file <- tempfile(fileext = ".csv") write.ts(AirPassengers, file) read.ts(file)file <- tempfile(fileext = ".csv") write.ts(AirPassengers, file) read.ts(file)
Performs X-11 selection for the length of the Henderson filter
(x11_trend_selection()) and computes the associated I/C ratio used
to build Musgrave filters (find_icr()).
x11_trend_selection(x) find_icr(length, freq = 12)x11_trend_selection(x) find_icr(length, freq = 12)
x |
A |
length |
Integer specifying the length of the filter. |
freq |
Integer specifying the frequency of the time series used to compute the I/C ratio (e.g., 12 for monthly, 4 for quarterly). |
The following procedure is used in X-11 to select the length of the trend filter:
Computes the I/C ratio, , with a Henderson filter of length equal
to the series frequency plus 1.
The selected length depends on the value of :
If , the selected length is 9 for monthly data and 5 otherwise.
If , the selected length is
(i.e., 13 for monthly data, 5 for quarterly data).
If , the selected length is 23 for monthly data and 7 otherwise.
The value of is then mapped to build Musgrave filters (find_icr()):
For quarterly data, if the length is 5, then ; otherwise, .
For other frequencies, if the length is less than or equal to 9, then .
Else, if the length is less than or equal to 13, then .
Else, .
x11_trend_selection() returns a named numeric vector containing the selected length
and the associated I/C ratio.
find_icr() returns a single numeric value corresponding to the I/C ratio
associated with the specified filter length and frequency in the X-11 algorithm.
x11_trend_selection(cars_registrations) find_icr(length = 13, freq = 12)x11_trend_selection(cars_registrations) find_icr(length = 13, freq = 12)
Wrapper around rjd3x13::regarima_outliers() to detect Additive Outliers (AO) or
Level Shifts (LS) in a seasonally adjusted series.
x13_regarima_outliers( y, order = c(0, 1, 1), mean = FALSE, ao = TRUE, ls = TRUE )x13_regarima_outliers( y, order = c(0, 1, 1), mean = FALSE, ao = TRUE, ls = TRUE )
y |
A time series object (class |
order |
An integer vector of length 3 specifying the non-seasonal ARIMA orders
|
mean |
Logical. If |
ao, ls
|
Logical flags indicating whether Additive Outliers (AO) and Level Shifts (LS) should be detected, respectively. |
This function uses an underlying RegARIMA model via rjd3x13 to automatically identify structural breaks and temporary shocks in the input series, returning their locations for downstream robust trend-cycle estimation.
A list with two components:
ao: A vector of dates where Additive Outliers were detected (or NULL if none).
ls: A vector of dates where Level Shifts were detected (or NULL if none).
x13_regarima_outliers(cars_registrations)x13_regarima_outliers(cars_registrations)