MyNixOS website logo
Description

Data-Driven Locally Weighted Regression for Trend and Seasonality in TS.

Various methods for the identification of trend and seasonal components in time series (TS) are provided. Among them is a data-driven locally weighted regression approach with automatically selected bandwidth for equidistant short-memory time series. The approach is a combination / extension of the algorithms by Feng (2013) <doi:10.1080/02664763.2012.740626> and Feng, Y., Gries, T., and Fritz, M. (2020) <doi:10.1080/10485252.2020.1759598> and a brief description of this new method is provided in the package documentation. Furthermore, the package allows its users to apply the base model of the Berlin procedure, version 4.1, as described in Speth (2004) <https://www.destatis.de/DE/Methoden/Saisonbereinigung/BV41-methodenbericht-Heft3_2004.pdf?__blob=publicationFile>. Permission to include this procedure was kindly provided by the Federal Statistical Office of Germany.

deseats

License:GPL-3

The goal of deseats is to provide several methods to decompose seasonal time series. Among them is a new fully data-driven algorithm called DeSeaTS (deseasonalize time series) for locally weighted regression with an automatically selected bandwidth. DeSeaTS accounts for possible short-range dependence in the underlying error process. Furthermore, the base model of the BV4.1 (Berlin Procedure 4.1) can be considered as well. Permission to include the BV4.1 base model procedure was kindly provided by the Federal Statistical Office of Germany.

Installation

You can install the current version of the package from CRAN with:

install.packages("deseats")

Examples

Basic decomposition

This is a basic example which shows you how to decompose a seasonal time series using the DeSeaTS algorithm:

library(deseats)

### Locally weighted regression with automatically selected bandwidth
### (here: local cubic trend)
est <- deseats(NOLABORFORCE, set_options(order_poly = 3))
est@bwidth     # The automatically selected bandwidth
#> [1] 0.1968428

### Plot of the results
plot(est, which = 1, xlab = "Year")

Seasonal adjustment

A seasonal adjustment can subsequently be easily achieved using implemented methods.

adj <- deseasonalize(est)
plot(adj, xlab = "Year", main = "The seasonally adjusted series")

Forecasting

If a decomposition via the DeSeaTS algorithm is suitable, the residual series can be further analyzed using autoregressive moving-average (ARMA) models.

model <- s_semiarma(NOLABORFORCE, set_options(order_poly = 3))
model
#> 
#> *******************************************
#> *                                         *
#> *        Fitted Seasonal Semi-ARMA        *
#> *                                         *
#> *******************************************
#> 
#> Series: NOLABORFORCE
#> 
#> Nonparametric part (Trend + Seasonality):
#> -----------------------------------------
#> 
#>  Kernel:    Epanechnikov
#>  Boundary:  Extend
#>  Bandwidth: 0.1968
#> 
#>   Trend:
#>   ------
#>     Order of local polynomial: 3
#> 
#>   Seasonality:
#>   ------------
#>     Frequency: 12
#> 
#> Parametric part (Rest):
#> -----------------------
#> 
#> Call:
#> stats::arima(x = res, order = c(ar, 0, ma), include.mean = arma_mean)
#> 
#> Coefficients:
#>          ar1
#>       0.6743
#> s.e.  0.0387
#> 
#> sigma^2 estimated as 0.07454:  log likelihood = -43.77,  aic = 91.54

The complete model can then be used for forecasting the seasonal time series. Forecasting intervals can be obtained either through the normality assumption or via a bootstrap.

fc <- predict(model, n.ahead = 12, method = "norm")
plot(fc, xlab = "Year", main = "A forecasting example")

Filters in the frequency domain

The linear locally weighted regression filters can be quickly displayed in the frequency domain.

fr <- seq(0, 0.5, 1e-04) # Frequencies
g_funs <- gain(est, lambda = fr) # Obtain correspondiong gain function values
g_deseas <- g_funs$gain_deseason # Gain function values for deseasonalization

l <- length(g_deseas[, 1])
weights_interior <- g_deseas[(l - 1) / 2 + 1, ] # middle point filter weights

plot(fr, weights_interior, type = "l", xlab = "Frequency", ylab = "Gain",
     main = "Middle point filter in the frequency domain")

Interactive decomposition

The provided decomposition methods can also be applied interactively. Run the following code.

runDecomposition()

This starts a shiny app which lets you load data files, decompose the time series saved therein, and download the decomposed data.

Main functions

The main functions of the package are:

  • deseats(): locally weighted regression with automatically selected bandwidth for decomposition,

  • BV4.1(): BV4.1 base model for decomposition,

  • lm_decomp(): ordinary least squares for decomposition,

  • llin_decomp: local linear regression for decomposition,

  • ma_decomp(): moving averages for decomposition,

  • hamilton_filter(): the time series filter by Hamilton.

The package, however, provides many other useful functions for you to discover.

Datasets

The package contains several seasonal example time series from official sources.

Authors

  • Yuanhua Feng (Department Economics, Paderborn University, Germany) (Author)

  • Dominik Schulz (Department Economics, Paderborn University, Germany) (Author, Maintainer)

Contact

For questions, bug reports, etc., please contact the maintainer Mr. Dominik Schulz via [email protected].

Metadata

Version

1.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows