Title: | Tools to help publish the trend-cycle |
---|---|
Description: | This package provides several functions to facilitate the computation of trend-cycle component. In particular, the computation can be done: using the Cascade Linear Filter (CLF) Dagum, E. B., & Luati, A. (2008); using the classical Henderson symmetric filter and the surrogate Musgrave asymmetric filters; using a local Parametrization of the Musgrave asymmetric filters (Quartier-la-Tente 2024); extending the Henderson symmetric fiter and the surrogate Musgrave asymmetric filters to take into account additive outliers and level shifts (Quartier-la-Tente 2025). Confidence intervals can be computed and several plots are available. |
Authors: | Alain Quartier-la-Tente [aut, cre]
|
Maintainer: | Alain Quartier-la-Tente <[email protected]> |
License: | EUPL |
Version: | 0.1.0.9000 |
Built: | 2025-03-16 08:30:52 UTC |
Source: | https://github.com/AQLT/publishTC |
Get the bandwidth of a "tc_estimates"
object.
The length of the filter is then equal to .
bandwidth(x)
bandwidth(x)
x |
a |
Classical moving average for trend-cycle extraction.
henderson CLF CLF_CN local_param_est
henderson CLF CLF_CN local_param_est
henderson
is list()
of "moving_average"
.
CLF
is a "finite_filters"
.
CLF_CN
is a "finite_filters"
.
local_param_est
is list()
of "finite_filters"
.
henderson
contains the Henderson moving average of length 5, 7, 9, 13 and 23.
CLF
contains the Cascade Linear Filter (CLF) of length 13 and the associated Asymmetric Linear Filters (ALF).
CLF_CN
contains the Cascade Linear Filter (CLF) of length 13 and the associated cut and normalise asymetric filters.
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. https://doi.org/10.1080/07474930802387837.
Henderson, R. (1916). Note on graduation by adjusted average. Transactions of the actuarial society of America 17: 43‑48.
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. https://doi.org/10.1177/0282423X241283207.
Smoothing using the Cascade Linear Filter
clf_smoothing(x, endpoints = c("cut-and-normalize", "ALF"), ...)
clf_smoothing(x, endpoints = c("cut-and-normalize", "ALF"), ...)
x |
input time-series. |
endpoints |
Method used for the asymmetric filter.
If |
... |
other unused parameters. |
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. https://doi.org/10.1080/07474930802387837
Confidence Intervals plot
confint_plot( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", col_confint = "grey", xlab = "", ylab = "", level = 0.95, ... ) ggconfint_plot( object, 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, 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 |
|
xlim , ylim
|
x and y limits of the plot.
If |
col_sa , col_tc
|
color of the seasonally adjusted and trend-cycle components. |
col_confint |
color of the confidence interval. |
xlab , ylab
|
x and y axis labels. |
level |
the confidence level required. |
... |
other parameters. |
legend_tc , legend_sa , legend_confint
|
legend of the trend-cycle and seasonally adjusted components and for the confidence intervals. |
"tc_estimates"
Confidence Intervals for "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 |
a |
parm |
unused parameter. |
level |
the confidence level required. |
asymmetric_var |
if |
... |
other (unused) parameters. |
Produce several plots
ggsmoothing_plot( object, plots = c("normal", "confint", "lollypop", "implicit_forecasts"), level = 0.95, ... )
ggsmoothing_plot( object, plots = c("normal", "confint", "lollypop", "implicit_forecasts"), level = 0.95, ... )
object |
|
plots |
list of plots to use. |
level |
the confidence level required. |
... |
other unused parameters. |
Smoothing using the Henderson filter
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 |
input time-series. |
endpoints |
Method used for the asymmetric filter. By default the Musgrave method is used |
length |
the length of the |
ao |
Dates of the Additive Outliers (AO) which effects are associated to the irregular component. |
ao_tc |
Dates of the Additive Outliers (AO) which effects are associated to the trend-cycle component. |
ls |
Dates of the Level Shifts (LS) which effects are associated to the trend-cycle component. |
icr |
I/C ratio used for the asymmetric filter. |
local_icr |
if |
asymmetric_var |
when |
degree |
if |
... |
other parameters passed to |
Smoothing using the Henderson filter
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 |
input time-series. |
endpoints |
Method used for the asymmetric filter. By default the Musgrave method is used |
length |
the length of the |
icr |
I/C ratio used for the asymmetric filter. |
local_icr |
if |
asymmetric_var |
when |
degree |
if |
... |
other parameters passed to |
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. https://doi.org/10.1177/0282423X241283207.
icr()
compute the overall I/C ratio, while icrs()
compute the I/C ratios for each period.
icr(x, tc, mul = FALSE) icrs(x, tc, mul = FALSE)
icr(x, tc, mul = FALSE) icrs(x, tc, mul = FALSE)
x , tc
|
seasonally adjusted and trend-cycle components.
If |
mul |
boolean indicating if the decomposition is multiplicative or additive. |
x <- cars_registrations tc <- henderson_smoothing(x)
x <- cars_registrations tc <- henderson_smoothing(x)
Compute Implicit Forecasts
implicit_forecasts(x, ...)
implicit_forecasts(x, ...)
x |
a |
... |
other unused parameters. |
Implicit Forecasts plot
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, ... ) ggimplicit_forecasts_plot( object, col_tc = "#E69F00", col_sa = "black", col_i_f = col_sa, lty_last_tc = 2, lty_i_f = 3, 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, ... ) ggimplicit_forecasts_plot( object, col_tc = "#E69F00", col_sa = "black", col_i_f = col_sa, lty_last_tc = 2, lty_i_f = 3, legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", legend_i_f = "Implicit forecasts", ... )
object |
|
xlim , ylim
|
x and y limits of the plot.
If |
col_sa , col_tc
|
color of the seasonally adjusted and trend-cycle components. |
col_i_f |
color of the implicit forecasts. |
xlab , ylab
|
x and y axis labels. |
lty_last_tc , lty_i_f
|
line type of the last values of the trend-cycle component and for the implicit forecasts. |
... |
other parameters. |
legend_tc , legend_sa , legend_i_f
|
legend of the trend-cycle and seasonally adjusted components and for implicit forecasts. |
Lollypop plot
lollypop( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", color_points = col_sa, cex_points = 1, pch_points = 16, xlab = "", ylab = "", ... ) gglollypop( object, 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, ... )
lollypop( object, xlim = NULL, ylim = NULL, col_tc = "#E69F00", col_sa = "black", color_points = col_sa, cex_points = 1, pch_points = 16, xlab = "", ylab = "", ... ) gglollypop( object, 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, ... )
object |
|
xlim , ylim
|
x and y limits of the plot.
If |
col_sa , col_tc
|
color of the seasonally adjusted and trend-cycle components. |
color_points , cex_points
|
color and size of the points associated to the seasonnaly adjusted component. |
pch_points |
point type of the seasonally adjusted component. |
xlab , ylab
|
x and y axis labels. |
... |
other parameters. |
legend_tc , legend_sa
|
legend of the trend-cycle and seasonally adjusted components. |
lty_last_tc |
line type of the last values of the trend-cycle component. |
Month of Cyclical Dominance
mcd(x, tc, mul = FALSE)
mcd(x, tc, mul = FALSE)
x , tc
|
seasonally adjusted and trend-cycle components.
If |
mul |
boolean indicating if the decomposition is multiplicative or additive. |
"tc_estimates"
plotDefault "tc_estimates"
plot
## S3 method for class 'tc_estimates' plot( x, y = NULL, col_tc = "#E69F00", col_sa = "black", xlab = "", ylab = "", lty_last_tc = 2, ... ) ## S3 method for class 'tc_estimates' autoplot( object, col_tc = "#E69F00", col_sa = "black", legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", lty_last_tc = 2, ... )
## S3 method for class 'tc_estimates' plot( x, y = NULL, col_tc = "#E69F00", col_sa = "black", xlab = "", ylab = "", lty_last_tc = 2, ... ) ## S3 method for class 'tc_estimates' autoplot( object, col_tc = "#E69F00", col_sa = "black", legend_tc = "Trend-cycle", legend_sa = "Seasonally adjusted", lty_last_tc = 2, ... )
y |
unused parameter. |
col_sa , col_tc
|
color of the seasonally adjusted and trend-cycle components. |
xlab , ylab
|
x and y axis labels. |
lty_last_tc |
line type of the last values of the trend-cycle component. |
... |
other (unused) parameters. |
object , x
|
|
legend_tc , legend_sa
|
legend of the trend-cycle and seasonally adjusted components. |
Smoothing using several methods
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 |
input time-series. |
methods |
list of methods to use. |
endpoints |
Method used for the asymmetric filter. By default the Musgrave method is used |
length |
the length of the |
icr |
I/C ratio used for the asymmetric filter. |
asymmetric_var |
when |
degree |
if |
ao |
Dates of the Additive Outliers (AO) which effects are associated to the irregular component. |
ao_tc |
Dates of the Additive Outliers (AO) which effects are associated to the trend-cycle component. |
ls |
Dates of the Level Shifts (LS) which effects are associated to the trend-cycle component. |
... |
other unused parameters. |
Data set examples
cars_registrations french_ipi fred simulated_data
cars_registrations french_ipi fred simulated_data
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.
Detect turning points in a time series
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)
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)
x |
the input time series. |
start , end
|
the interval where to find turning points. |
digits |
number of digits used for the comparison of the values. |
k , m
|
number of observation before and after the turning point (see details). |
Zellner, Hong, et Min (1991) definition is used ,
:
we have an upturn at date when
we have a downturn at date when
Export and Import time series object to/from CSV
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 |
file |
a character string giving the name of the file to write to. |
frequency |
an integer giving the number of observations per unit of time. By default it is guessed from the data. |
list |
boolean, if |
Perform X-11 selection of the length of Henderson (x11_trend_selection()
) and
compute the associated I/C ratio used to build Musgrave fuilters (find_icr()
).
x11_trend_selection(x) find_icr(length, freq = 12)
x11_trend_selection(x) find_icr(length, freq = 12)
x |
a |
length |
length of the filter. |
freq |
frequency of the time series used to compute the I/C ratio. |
The following procedure is used in X-11 to select the length of the trend filter:
Computes the I/C ratio, with an Henderson filter of length the frequency plus 1.
The length depends on the value or :
if then the selected length is 9 for monthly data and 5 otherwise;
if then the selected length is
where
is the frequency of data (12 for monthly data, 4 for quarterly data...).
if then the selected length is 23 for monthly data and 7 otherwise.
The value of is then fixed to build Musgrave filters (
find_icr()
) :
for quarterly data, if the length is 5 then , otherwide
;
if the length if less or equal to 9 then ;
else if the length if less or equal to 13 then ;
else .