| Title: | Seasonal Adjustment of High Frequency Data with 'JDemetra+ 3.x' |
|---|---|
| Description: | R interface to 'JDemetra+ 3.x' (<https://github.com/jdemetra>), the time series analysis software. It provides functions for seasonal adjustment of higher-frequency data, including those with multiple or non-integer periodicities. It includes pre-adjustment via the extended airline model and several seasonal decomposition methods: extended airline model based decomposition, extended X-11, and augmented STL. |
| Authors: | Jean Palate [aut], Daniel Ollech [cre, ctb], Christiane Hofer [ctb], Witthohn Thomas [ctb], Lea Hengen [ctb], Martin Stefan [ctb], Alessandro Piovani [ctb], Tanguy Barthelemy [ctb, art], Karsten Webel [ctb] (ORCID: <https://orcid.org/0000-0001-5538-5428>, X-11 method) |
| Maintainer: | Daniel Ollech <[email protected]> |
| License: | file LICENSE |
| Version: | 3.0.0 |
| Built: | 2026-09-21 11:13:57 UTC |
| Source: | https://github.com/rjdverse/rjd3highfreq |
'X11' Extreme Values Corrector
extreme_values_correction( series, period, corrected_s, lsigma = 1.5, usigma = 2.5, multiplicative = FALSE, start = 0, clean_extremities = TRUE )extreme_values_correction( series, period, corrected_s, lsigma = 1.5, usigma = 2.5, multiplicative = FALSE, start = 0, clean_extremities = TRUE )
series |
the analysed time series. |
period |
the period of the input time series if 'series' is not a '"ts"' object. |
corrected_s |
other time series if the series being corrected is different from series. |
lsigma |
the lower sigma boundaries for the detection of extreme values. |
usigma |
the upper sigma boundaries for the detection of extreme values. |
multiplicative |
boolean indicating if the decomposition is multiplicative or additive. |
start |
position of the first "complete" considered period. |
clean_extremities |
boolean indicating if the extremities should be cleaned. |
The 'X11' Extreme Values Corrector is used to compute the tables b4, b4g, b9, b9g, b17, b20, c17 and c20.
#' The returned correction contains the following columns:
obs_weightExtreme value corrections weight of each observation
correction_factorsExtreme value correction factors
extreme_values_correction(rjd3toolkit::ABS$X0.2.09.10.M, 12)extreme_values_correction(rjd3toolkit::ABS$X0.2.09.10.M, 12)
This internal function performs automatic outlier detection in high-frequency time series using Extended Airline models.
find_outliers( input, types = c("AO"), start = 0, end = 0, critical_value = 0, max_outliers = 30, max_round = 30, precision = 1e-05, deps = 1e-04 )find_outliers( input, types = c("AO"), start = 0, end = 0, critical_value = 0, max_outliers = 30, max_round = 30, precision = 1e-05, deps = 1e-04 )
input |
time series |
types |
Character vector specifying the types of outliers to detect. Default: c("AO") (additive outliers only). Common options include:
|
start |
Integer specifying the starting position (1-based R indexing) for outlier detection. Default: 0 (detection from the beginning of the series). |
end |
Integer specifying the ending position (1-based R indexing) for outlier detection. Default: 0 (detection until the end of the series). |
critical_value |
Numeric value for the critical value threshold. Uses the maximum value among the specified value and a global max-t threshold based on extreme-value theory, roughly of order sqrt(2 * log(n))). Default: 0 (global max-t threshold is used). |
max_outliers |
Integer specifying the maximum number of outliers to detect. Default: 30. |
max_round |
Integer specifying the maximum number of detection iterations. Default: 30. |
precision |
Numeric value specifying the tolerance for convergence of optimization algorithms. Default: 1e-5. |
deps |
Numeric scalar. Step in the computation of the numerical derivatives, used in the optimisation routine. Default:1e-4. |
A numeric matrix with dimensions [number of outliers detected × 2].
Outlier critical value using the Ljung algorithm as given in Ljung, G. M. (1993). On outlier detection in time series. Journal of Royal Statistical Society B 55, 559-567. Solution proposed by Brian Monsell (LBS), January 2022
series <- rjd3toolkit::Exports$Malta find_outliers(series, critical_value = 3.5, types = c("LS", "WO"))series <- rjd3toolkit::Exports$Malta find_outliers(series, critical_value = 3.5, types = c("LS", "WO"))
Performs an Arima Model Based (AMB) decomposition using a (fractional) airline model, suitable for high-frequency time series. The method decomposes the input series into trend, seasonal and irregular components, with optional signal–noise decomposition.
fractional_airline_decomposition( series, period, sn = FALSE, stde = FALSE, nbcasts = 0, nfcasts = 0, eps = 1e-09, deps = 1e-04, log = FALSE, series_time = NULL )fractional_airline_decomposition( series, period, sn = FALSE, stde = FALSE, nbcasts = 0, nfcasts = 0, eps = 1e-09, deps = 1e-04, log = FALSE, series_time = NULL )
series |
input time series. |
period |
period of the seasonal component, any positive real number. |
sn |
decomposition into signal and noise (2 components only). The signal is the seasonally adjusted series and the noise the seasonal component. Default: FALSE. |
stde |
Boolean: TRUE: compute standard deviations of the components. In some cases (e.g. memory limits), it is currently not possible to compute them. Default: FALSE. |
nbcasts |
number of backcasts. Default: 0. |
nfcasts |
number of forecasts. Default: 0. |
eps |
precision of the optimisation routine. Default:1e-9. |
deps |
step in the computation of the numerical derivatives, used in the optimisation routine. Default:1e-4 |
log |
logical indicating whether the series is on the log scale. Default: FALSE. |
series_time |
vector of times at which 'series' is indexed. Optional. |
If 'sn = TRUE', the decomposition is restricted to two components only (signal and noise). When 'stde = TRUE', the computation of standard deviations may fail for long series or high-frequency data due to memory constraints.
An object containing the AMB decomposition results, including the estimated components and, if requested, their standard deviations.
series <- rnorm(70)+100 ### Example with a daily time series with a day-of-the-week effect weekday <- rjd3highfreq::fractional_airline_decomposition( series, period = 7, log = TRUE, series_time = seq.Date(from=as.Date("2025-01-01"), by = "days", length.out = length(series)) ) ### Example with a weekly time series series <- rnorm(200)+100 weekly <- rjd3highfreq::fractional_airline_decomposition( series, period = 52.18, log = TRUE, series_time = seq.Date(from=as.Date("2025-01-01"), by = "days", length.out = length(series)) )series <- rnorm(70)+100 ### Example with a daily time series with a day-of-the-week effect weekday <- rjd3highfreq::fractional_airline_decomposition( series, period = 7, log = TRUE, series_time = seq.Date(from=as.Date("2025-01-01"), by = "days", length.out = length(series)) ) ### Example with a weekly time series series <- rnorm(200)+100 weekly <- rjd3highfreq::fractional_airline_decomposition( series, period = 52.18, log = TRUE, series_time = seq.Date(from=as.Date("2025-01-01"), by = "days", length.out = length(series)) )
This function estimates a (fractional) airline RegARIMA model and returns the linearized series together with regression effects, outlier components, estimation results and likelihood diagnostics. It is typically used as a preprocessing step prior to AMB or UCM-based decompositions.
fractional_airline_estimation( series, period, xreg = NULL, ndiff = 2, ar = FALSE, mean = FALSE, outliers = NULL, critical_value = 6, precision = 1e-12, deps = 1e-04, approximate_hessian = FALSE, nfcasts = 0, log = FALSE, series_time = NULL )fractional_airline_estimation( series, period, xreg = NULL, ndiff = 2, ar = FALSE, mean = FALSE, outliers = NULL, critical_value = 6, precision = 1e-12, deps = 1e-04, approximate_hessian = FALSE, nfcasts = 0, log = FALSE, series_time = NULL )
series |
input time series. |
period |
numeric vector of seasonal periods. Each value must be a positive real number (e.g. 7 for weekly, 365.2425 for annual seasonality). |
xreg |
optional matrix of user-defined regression variables (e.g. calendar
regressors built using |
ndiff |
integer specifying the number of regular differences. Default is 2. |
ar |
logical. If TRUE, an autoregressive component is included in the model. Default is FALSE. |
mean |
logical. If TRUE, a mean component is included in the model. Default is FALSE. |
outliers |
character vector specifying the types of outliers to detect.
Possible values include |
critical_value |
numeric. Critical value for automatic outlier detection. Larger values imply more conservative detection. Default is 6. |
precision |
numeric. Precision of the likelihood optimization.
Default is |
deps |
step in the computation of the numerical derivatives, used in the optimisation routine. Default:1e-4 |
approximate_hessian |
logical. If TRUE, compute an approximate Hessian matrix based on the optimization procedure. Default is FALSE. |
nfcasts |
number of forecasts. Default is 0. |
log |
logical. If TRUE, the model is estimated on the log-scale. Default is FALSE. |
series_time |
optional vector of time indices associated with |
Automatic outlier detection can be enabled by specifying the outlier types and a critical value for the detection threshold.
An object of class "hf_estimation" containing:
the original and linearized series,
estimated regression effects and outlier components,
model parameters and covariance matrices,
likelihood and diagnostic information.
# Simulated examples with and without regressor set.seed(125) reg <- data.frame( reg1 = round(runif(1000, min = 0, max = 1))*2-1, reg2 = round(runif(1000, min = 0, max = 1))*2-1 ) y = 100 + 2*reg$reg1 -2*reg$reg2 + rnorm(nrow(reg)) # input data data <- list( series = y, date = seq.Date(from = as.Date("2020-01-01"), by = "day", length.out = 1000) ) # Linearize the series using weekly and annual periodicities est <- fractional_airline_estimation( data$series, period = c(7, 30.4), log = FALSE, xreg = reg, series_time = data$date ) est est2 <- fractional_airline_estimation( data$series, period = c(7, 30.4), log = FALSE, series_time = data$date ) est2# Simulated examples with and without regressor set.seed(125) reg <- data.frame( reg1 = round(runif(1000, min = 0, max = 1))*2-1, reg2 = round(runif(1000, min = 0, max = 1))*2-1 ) y = 100 + 2*reg$reg1 -2*reg$reg2 + rnorm(nrow(reg)) # input data data <- list( series = y, date = seq.Date(from = as.Date("2020-01-01"), by = "day", length.out = 1000) ) # Linearize the series using weekly and annual periodicities est <- fractional_airline_estimation( data$series, period = c(7, 30.4), log = FALSE, xreg = reg, series_time = data$date ) est est2 <- fractional_airline_estimation( data$series, period = c(7, 30.4), log = FALSE, series_time = data$date ) est2
Apply Henderson linear filter
henderson(series, length, musgrave = TRUE, ic = 4.5)henderson(series, length, musgrave = TRUE, ic = 4.5)
series |
Input time series. |
length |
Length of the symmetric Henderson filter. Must be odd. |
musgrave |
Boolean indicating if Musgrave asymmetric filters should be used. Default is |
ic |
I/C ratio between the volatility of the tentative irregular and trend-cycle estimates (needed for calculating the Musgrave asymmetric filters). |
A numeric array corresponding to the estimated trend.
q <- x11plus(rjd3toolkit::ABS$X0.2.09.10.M, 12) henderson(q$decomposition$sa, 13)q <- x11plus(rjd3toolkit::ABS$X0.2.09.10.M, 12) henderson(q$decomposition$sa, 13)
Compute IC-Ratio
ic_ratio( series, frequency = NULL, trend_length = NULL, musgrave = FALSE, multiplicative = FALSE, seasonally_adjust = TRUE, sma = "S3X5", ... )ic_ratio( series, frequency = NULL, trend_length = NULL, musgrave = FALSE, multiplicative = FALSE, seasonally_adjust = TRUE, sma = "S3X5", ... )
series |
input time series |
frequency |
frequency of the seasonal component. Can be NULL if series is ts |
trend_length |
length of Henderson filter used for trend adjustment. If NULL it is nextodd(frequency) |
musgrave |
Boolean indicating if Musgrave asymmetric filters should be used in trend adjustment |
multiplicative |
boolean indicating if the decomposition is multiplicative or additive |
seasonally_adjust |
boolean. Should series be seasonally adjusted? |
sma |
seasonal moving average used in x11plus() |
... |
additional arguments for trend adjustment. See ?henderson |
In the traditional calculation of the IC-ratio, no asymmetric filters used for the preliminary trend estimation (see Ladiray and Quenneville 2001, Table B7).
Ladiray, D., Quenneville, B. (2001). The Various Tables. In: Seasonal Adjustment with the X-11 Method. Lecture Notes in Statistics, vol 158. Springer, New York, NY. https://doi.org/10.1007/978-1-4613-0175-2_5
series <- rjd3toolkit::Retail$AllOtherGenMerchandiseStores ic_ratio(series)series <- rjd3toolkit::Retail$AllOtherGenMerchandiseStores ic_ratio(series)
Performs an iterative stlplus-type decomposition for time series with multiple seasonal periods. This function provides an R interface to the JD+ Java implementation. It decomposes a time series into a trend component, several seasonal components, and an irregular component using an iterative STL-based procedure.
istl( series, period, multiplicative = TRUE, swindow = NULL, twindow = NULL, robust = NULL, ninnerloop = 1, nouterloop = 15, nojump = FALSE, weight_threshold = 0.001, weight_function = c("biweight", "uniform", "triangular", "epanechnikov", "tricube", "triweight") )istl( series, period, multiplicative = TRUE, swindow = NULL, twindow = NULL, robust = NULL, ninnerloop = 1, nouterloop = 15, nojump = FALSE, weight_threshold = 0.001, weight_function = c("biweight", "uniform", "triangular", "epanechnikov", "tricube", "triweight") )
series |
Numeric vector. Input time series to be decomposed. |
period |
Numeric vector. Seasonal periods to be modelled. For example,
|
multiplicative |
Logical. If |
swindow |
Optional integer vector. Lengths of the seasonal smoothing
windows, one for each seasonal period. If |
twindow |
Optional integer vector. Lengths of the trend smoothing
windows. If |
robust |
Boolean. Analogue to robust parameter in stats::stl (see details) |
ninnerloop |
Integer. Number of inner iterations of the ISTL algorithm. |
nouterloop |
Integer. Number of outer iterations used to compute robust
weights. Set to |
nojump |
Logical. If |
weight_threshold |
Numeric scalar in |
weight_function |
Character string specifying the weighting function
used by the LOESS smoothers. One of |
The returned decomposition contains the following columns:
seriesThe original input series.
saThe seasonally adjusted series (trend+irregular for additive, trend*irregular for multiplicative decomposition).
tThe trend component.
s<period>One seasonal component for each value supplied in
period. For example, if period = c(7, 365), the output
contains columns s7 and s365.
iThe irregular component.
fitThe fitted values from the decomposition (trend+seasonal for additive, trend*seasonal for multiplicative decomposition).
weightsThe final robust weights.
If multiplicative = TRUE, the decomposition is interpreted as a
multiplicative decomposition. If multiplicative = FALSE, it is
interpreted as an additive decomposition.
If robust = TRUE, the parameters nouterloop and ninnerloop are
overwritten, so that 15 iterations of the outer loop and one run of the
inner loop are completed. If robust = FALSE, nouterloop is set to 0,
and ninnerloop is set to 2.
An object of class "hf_decomposition", consisting of a list
with two elements:
decompositionA data.frame containing the original
series, the seasonally adjusted series, the trend, one seasonal component
for each period, the irregular component, fitted values and robust
weights.
parametersA list containing the main parameters used for the decomposition.
stlplus, mstl,
plot.hf_decomposition
q <- istl( series = rjd3toolkit::ABS$X0.2.09.10.M, period = c(12, 19) ) plot(q)q <- istl( series = rjd3toolkit::ABS$X0.2.09.10.M, period = c(12, 19) ) plot(q)
Applies a LOESS smoother to a numeric time series.
loess(series, window, degree = 1, jump = 0)loess(series, window, degree = 1, jump = 0)
series |
Numeric vector. Input time series to be smoothed. |
window |
Integer. Length of the LOESS smoothing window. Larger values produce a smoother result. |
degree |
Integer. Degree of the local polynomial. Supported values are
|
jump |
Integer. Number of jumps used to speed up the computation.
If |
This function provides a simple R interface to the JD+ Java implementation of the LOESS smoother used internally by the stlplus decomposition routines. It smoothes the input series using a local polynomial of degree 0 or 1.
This function is not the same as loess from the
stats package. It does not use a formula interface and is intended
for smoothing a single numeric series with the JD+ stlplus|loess implementation.
Also, it can handle time series with missing values.
A numeric vector containing the smoothed series.
q <- stlplus( series = rjd3toolkit::ABS$X0.2.09.10.M, period = 12 ) trend <- q$decomposition[, "t"] smoothed_trend <- loess( series = trend, window = 121 ) ts.plot( cbind(trend, smoothed_trend), col = c("black", "red") )q <- stlplus( series = rjd3toolkit::ABS$X0.2.09.10.M, period = 12 ) trend <- q$decomposition[, "t"] smoothed_trend <- loess( series = trend, window = 121 ) ts.plot( cbind(trend, smoothed_trend), col = c("black", "red") )
This function performs a statistical test to determine whether data should be transformed to logarithmic scale or kept in level (original scale)
loglevel(input, precision = 1e-05, deps = 1e-04)loglevel(input, precision = 1e-05, deps = 1e-04)
input |
time series |
precision |
Numeric value specifying the tolerance for convergence of optimization algorithms. Default: 1e-5. |
deps |
Numeric scalar. Step in the computation of the numerical derivatives, used in the optimisation routine. Default:1e-4. |
An object containing the log-level test results. First the AICc of the model in levels and then the AICc of the model with logs
series <- rjd3toolkit::Retail$BookStores loglevel(series)series <- rjd3toolkit::Retail$BookStores loglevel(series)
Performs an stlplus-type decomposition for time series with multiple seasonal periods. This function provides an R interface to the JD+ Java implementation.. It simultaneously decomposes a time series into a trend component, several seasonal components, and an irregular component.
mstl( series, period, multiplicative = TRUE, swindow = NULL, twindow = 0, robust = NULL, ninnerloop = 1, nouterloop = 15, nojump = FALSE, weight_threshold = 0.001, weight_function = c("biweight", "uniform", "triangular", "epanechnikov", "tricube", "triweight") )mstl( series, period, multiplicative = TRUE, swindow = NULL, twindow = 0, robust = NULL, ninnerloop = 1, nouterloop = 15, nojump = FALSE, weight_threshold = 0.001, weight_function = c("biweight", "uniform", "triangular", "epanechnikov", "tricube", "triweight") )
series |
Numeric vector. Input time series to be decomposed. |
period |
Numeric vector. Seasonal periods to be modelled. For example,
|
multiplicative |
Logical. If |
swindow |
Optional integer vector. Lengths of the seasonal smoothing
windows, one for each seasonal period. If |
twindow |
Integer. Length of the trend smoothing window. If set to
|
robust |
Boolean. Analogue to robust parameter in stats::stl (see details) |
ninnerloop |
Integer. Number of inner iterations of the MSTL algorithm. |
nouterloop |
Integer. Number of outer iterations used to compute robust
weights. Set to |
nojump |
Logical. If |
weight_threshold |
Numeric scalar in |
weight_function |
Character string specifying the weighting function
used by the LOESS smoothers. One of |
The returned decomposition contains the following columns:
seriesThe original input series.
saThe seasonally adjusted series (trend+irregular for additive, trend*irregular for multiplicative decomposition).
tThe trend component.
s<period>One seasonal component for each value supplied in
period. For example, if period = c(7, 365), the output
contains columns s7 and s365.
iThe irregular component.
fitThe fitted values from the decomposition (trend+seasonal(s) for additive, trend*seasonal(s) for multiplicative decomposition).
weightsThe final robust weights.
If multiplicative = TRUE, the decomposition is interpreted as a
multiplicative decomposition. If multiplicative = FALSE, it is
interpreted as an additive decomposition.
If robust = TRUE, the parameters nouterloop and ninnerloop are
overwritten, so that 15 iterations of the outer loop and one run of the
inner loop are completed. If robust = FALSE, nouterloop is set to 0,
and ninnerloop is set to 2.
An object of class "hf_decomposition", consisting of a list
with two elements:
decompositionA data.frame containing the original
series, the seasonally adjusted series, the trend, one seasonal component
for each period, the irregular component, fitted values and robust
weights.
parametersA list containing the main parameters used for the decomposition.
stlplus, plot.hf_decomposition
q <- mstl( series = rjd3toolkit::ABS$X0.2.09.10.M, period = c(12, 19) ) plot(q)q <- mstl( series = rjd3toolkit::ABS$X0.2.09.10.M, period = c(12, 19) ) plot(q)
This function performs an AMB decomposition based on (fractional) airline models allowing for multiple seasonal periodicities at once. It is intended for high-frequency time series where more than one seasonal cycle may be present (e.g. weekly and annual effects).
multi_airline_decomposition( series, period, ndiff = 2, ar = FALSE, stde = FALSE, nbcasts = 0, nfcasts = 0, eps = 1e-09, deps = 1e-04, log = FALSE, series_time = NULL )multi_airline_decomposition( series, period, ndiff = 2, ar = FALSE, stde = FALSE, nbcasts = 0, nfcasts = 0, eps = 1e-09, deps = 1e-04, log = FALSE, series_time = NULL )
series |
input time series. |
period |
numeric vector of seasonal periods. Each value must be a positive real number (e.g. 7 for weekly, 365.2425 for annual seasonality). |
ndiff |
integer specifying the number of regular differences. Default is 2. |
ar |
logical. If TRUE, an autoregressive component is included in the model. Default is FALSE. |
stde |
logical. If TRUE, compute standard deviations of the components. In some cases (e.g. memory limits), it may not be possible to compute them. Default is FALSE. |
nbcasts |
number of backcasts. Default is 0. |
nfcasts |
number of forecasts. Default is 0. |
eps |
precision of the optimisation routine. Default: 1e-9. |
deps |
step in the computation of the numerical derivatives, used in the optimisation routine. Default:1e-4 |
log |
logical. If TRUE, the decomposition is returned on the log-scale. Default is FALSE. |
series_time |
optional vector of time indices associated with |
If a single period is supplied, the function falls back to
fractional_airline_decomposition().
A decomposition object containing the estimated components for each periodicity. If multiple periods are provided, a multi-period decomposition is returned.
series <- rnorm(200)+100 dual_season <- multi_airline_decomposition( series, period = c(7, 30.4), log = TRUE, series_time = seq.Date(from=as.Date("2025-01-01"), by = "days", length.out = length(series)) )series <- rnorm(200)+100 dual_season <- multi_airline_decomposition( series, period = c(7, 30.4), log = TRUE, series_time = seq.Date(from=as.Date("2025-01-01"), by = "days", length.out = length(series)) )
Performs an STL-like seasonal decomposition. It can handle missing values and does allow a multiplicative decomposition.
stlplus( series, period, multiplicative = TRUE, swindow = 7, twindow = 0, lwindow = 0, sdegree = 0, tdegree = 1, ldegree = 1, sjump = 0, tjump = 0, ljump = 0, robust = NULL, ninnerloop = 1, nouterloop = 15, weight_threshold = 0.001, weight_function = c("biweight", "uniform", "triangular", "epanechnikov", "tricube", "triweight"), legacy = FALSE )stlplus( series, period, multiplicative = TRUE, swindow = 7, twindow = 0, lwindow = 0, sdegree = 0, tdegree = 1, ldegree = 1, sjump = 0, tjump = 0, ljump = 0, robust = NULL, ninnerloop = 1, nouterloop = 15, weight_threshold = 0.001, weight_function = c("biweight", "uniform", "triangular", "epanechnikov", "tricube", "triweight"), legacy = FALSE )
series |
Numeric vector. Input time series to be decomposed. |
period |
Numeric scalar. Seasonal period of the series. For example,
use |
multiplicative |
Logical. If |
swindow |
Integer. Length of the seasonal smoothing window. |
twindow |
Integer. Length of the trend smoothing window. If set to
|
lwindow |
Integer. Length of the low-pass filter used to remove the
trend from the seasonal component. If set to |
sdegree |
Integer. Degree of the local polynomial used for seasonal
smoothing. Usually |
tdegree |
Integer. Degree of the local polynomial used for trend
smoothing. Usually |
ldegree |
Integer. Degree of the local polynomial used for low-pass
smoothing. Usually |
sjump |
Integer. Number of jumps used in the computation of the seasonal component. Values greater than zero speed up the computation by evaluating the smoother at fewer points and interpolating between them. |
tjump |
Integer. Number of jumps used in the computation of the trend component. |
ljump |
Integer. Number of jumps used in the computation of the low-pass component. |
robust |
Boolean. Analogue to robust parameter in stats::stl (see details) |
ninnerloop |
Integer. Number of inner iterations of the STL algorithm. |
nouterloop |
Integer. Number of outer iterations used to compute robust
weights. Set to |
weight_threshold |
Numeric scalar in |
weight_function |
Character string specifying the weighting function
used by the LOESS smoothers. One of |
legacy |
Logical. If |
This function provides an R interface to the JD+ Java implementation of
STL decomposition. It decomposes a time series into trend, seasonal and
irregular components and returns the result as an object of class
"hf_decomposition".
The returned decomposition contains the following columns:
seriesThe original input series.
saThe seasonally adjusted series (trend+irregular for additive, trend*irregular for multiplicative decomposition).
tThe trend component.
sThe seasonal component.
iThe irregular component.
fitThe fitted values from the decomposition (trend+seasonal(s) for additive, trend*seasonal(s) for multiplicative decomposition).
weightsThe final robust weights.
If multiplicative = TRUE, the decomposition is interpreted as a
multiplicative decomposition. If multiplicative = FALSE, it is
interpreted as an additive decomposition.
If robust = TRUE, the parameters nouterloop and ninnerloop are
overwritten, so that 15 iterations of the outer loop and one run of the
inner loop are completed. If robust = FALSE, nouterloop is set to 0,
and ninnerloop is set to 2.
An object of class "hf_decomposition", consisting of a list
with two elements:
decompositionA data.frame containing the original
series, the seasonally adjusted series, the trend, seasonal and irregular
components, fitted values and robust weights (see details).
parametersA list containing the main parameters used for the decomposition.
decomp <- stlplus( series = rjd3toolkit::ABS$X0.2.09.10.M, period = 12 ) plot(decomp)decomp <- stlplus( series = rjd3toolkit::ABS$X0.2.09.10.M, period = 12 ) plot(decomp)
This function implements a modified version of the classical X-11 seasonal adjustment approach. The modified X-11 method is applicable to time series with arbitrary seasonal periodicity.
x11plus( series, period, multiplicative = TRUE, trend_horizon = 6, trend_degree = 3, trend_kernel = c("Henderson", "BiWeight", "TriWeight", "TriCube", "Uniform", "Triangular", "Epanechnikov", "Trapezoidal"), trend_asymmetric = c("CutAndNormalize", "Direct", "MMSRE"), trend_coefs, seas_s0 = c("S3X3", "S3X1", "S3X5", "S3X9", "S3X15"), seas_s1 = c("S3X5", "S3X3", "S3X1", "S3X9", "S3X15"), extreme_lsig = 1.5, extreme_usig = 2.5, user_defined = NULL )x11plus( series, period, multiplicative = TRUE, trend_horizon = 6, trend_degree = 3, trend_kernel = c("Henderson", "BiWeight", "TriWeight", "TriCube", "Uniform", "Triangular", "Epanechnikov", "Trapezoidal"), trend_asymmetric = c("CutAndNormalize", "Direct", "MMSRE"), trend_coefs, seas_s0 = c("S3X3", "S3X1", "S3X5", "S3X9", "S3X15"), seas_s1 = c("S3X5", "S3X3", "S3X1", "S3X9", "S3X15"), extreme_lsig = 1.5, extreme_usig = 2.5, user_defined = NULL )
series |
Input time series. |
period |
Seasonal periodicity of |
multiplicative |
Decomposition mode for |
trend_horizon |
Bandwidth of the symmetric local polynomial regression filter. Default is 6, giving a 13-term filter. See details. |
trend_degree |
Polynomial degree that should be preserved by the symmetric local polynomial regression filter. Default is 3, giving preservation of cubic polynomials. See details. |
trend_kernel |
A kernel defining the weights in the objective function. See details. |
trend_asymmetric |
Approach for deriving asymmetric local polynomial regression filters. See details. |
trend_coefs |
A filter bank containing the weights of the symmetric trend-cycle filter and its asymmetric variants. Can be an object
of class |
seas_s0 |
|
seas_s1 |
|
extreme_lsig |
Lower |
extreme_usig |
Upper |
user_defined |
A vector containing additional output tables. Default is |
The main novelty of the modified X-11 method is the implementation of advanced options for refined and final trend-cycle estimation (B7, C7, D7, and D12), generalising the use of classical Henderson filters. The following logic applies, see also Webel (2026) and Webel and Smyk (2024) for technical details:
If trend_coefs is unspecified (default), then the local polynomial regression filters suggested in Proietti and Luati (2008) are applied. The underlying regression model, from which the symmetric
trend-cycle filter arises, is further specified through the trend_horizon, trend_degree, and trend_kernel parameters:
2 * trend_horizon + 1 is the number of observations to be considered in the local trend approximation and, hence, the length of the resulting symmetric trend-cycle filter.
trend_degree is the order of the polynomial in the local trend approximation.
trend_kernel is a kernel function that defines the sequence of non-negative weights in the objective function, which is then minimised with respect to the regression parameters.
In addition, trend_asymmetric defines the method to be used for deriving the requisite asymmetric local polynomial regression filters. Three methods are currently available: the cut-and-normalise approach
of Gasser and Müller (1979) (CutAndNormalize), the direct asymmetric filters suggested in Proietti and Luati (2008) (Direct), and the minimum mean squared revision error approach developed in
Grun-Rehomme et al. (2018) (MMSRE).
If trend_coefs is specified, then all other parameters related to trend-cycle estimation are ignored, and the provided trend-cycle filter bank is applied. Note that the rjd3filters package can
be used to create filters, e.g. by setting trend_coefs = rjd3filters::rkhs_filter().
Two final warnings regarding seasonal estimation.
Extremes in the seasonal-irregular component are currently corrected only in iterations B and C, where the moving irregular standard deviation is always calculated from 5-year moving windows. That is, no final replacement values (D9) are currently computed.
Users must specify seasonal filters seas_s0 and seas_s1 that match the length of series, as there
is currently no automatic resetting of ill-specified seasonal filters. That is, any specification of seasonal filters that are too long for the given series will simply produce an error message.
An object of class "hf_decomposition". It contains the specified parameters and a matrix that stores the input series and the final estimates of the seasonally adjusted series (D11),
the trend-cyclical component (D12), the seasonal component (D10), and the irregular component (D13).
Dagum, E. B. and S. Bianconcini (2008). The Henderson Smoother in Reproducing Kernel Hilbert Space. Journal of Business and Economic Statistics 26 (4), 536–545. https://doi.org/10.1198/073500107000000322
Gasser, T. and H.-G. Müller (1979). Kernel Estimation of Regression Functions. In T. Gasser and M. Rosenblatt (Eds), Smoothing Techniques for Curve Estimation, 23–68. Heidelberg: Springer. https://doi.org/10.1007/BFb0098489
Grun-Rehomme, M., F. Guggemos and D. Ladiray (2018). Asymmetric Moving Averages Minimizing Phase Shift. In G. L. Mazzi, D. Ladiray and D. A. Riester (Eds), Handbook on Seasonal Adjustment, 391–413. Luxembourg: Publications Office of the European Union.
Proietti, T. and A. Luati (2008). Real Time Estimation in Local Polynomial Regression, with Application to Trend-Cycle Analysis. Annals of Applied Statistics 2 (4), 1523–1553. https://doi.org/10.1214/08-AOAS195
Webel, K. (2026). Some Thoughts on Modified X-11 Seasonal Adjustments for Time Series with Complex Seasonality. Deutsche Bundesbank Discussion Paper XX/2026. Forthcoming
Webel, K. and A. Smyk (2024). Seasonal Adjustment of Infra-Monthly Time Series with JDemetra+. Journal of Official Statistics 40 (4), 783–828. https://doi.org/10.1177/0282423X241277602
x11decomp <- x11plus( series = rjd3toolkit::ABS$X0.2.09.10.M, period = 12, trend_horizon = 99 )x11decomp <- x11plus( series = rjd3toolkit::ABS$X0.2.09.10.M, period = 12, trend_horizon = 99 )