Learn R Programming

deseats

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 dominik.schulz@uni-paderborn.de.

Copy Link

Version

Install

install.packages('deseats')

Monthly Downloads

442

Version

1.1.1

License

GPL-3

Maintainer

Dominik Schulz

Last Published

June 23rd, 2025

Functions in deseats (1.1.1)

RAINFALL

Monthly Average Rainfall in Germany
expo,deseats_fc-method

Exponentiate deseats Forecasts
deseats-package

Deseasonalize Time Series
NOLABORFORCE

Monthly Number of US Persons Not in the Labor Force
RETAIL

Monthly Total Volume of Retail Trade in Germany
SAVINGS

Quarterly Savings of Private Households in Germany
arma_to_ma

MA Representation of an ARMA Model
lm_decomp

Decomposition of Time Series Using Linear Regression
plot,decomp-method

Plot Method for Decomposition Results in the Style of Base R Plots
order_poly

Smoothing Option Generics
expo

Automatic Creation of Animations
bwidth_confint

Bootstrapping Confidence Intervals for Locally Weighted Regression Bandwidths
arma_to_ar

AR Representation of an ARMA Model
create.gain

Create Gain Function from a Linear Time Series Filter
ma_decomp

Decomposition of Time Series Using Moving Averages
llin_decomp

Decomposition of Time Series Using Local Linear Regression
autoplot,hfilter-method

ggplot2 Plot Method for the Results of a Hamilton Filter
hA_calc

Calculation of Theoretically Optimal Bandwidth and Its Components
bwidth,deseats-method

Retrieve the Used Bandwidth from an Estimation Object
hamilton_filter

Time Series Filtering Using the Hamilton Filter
autoplot,decomp-method

Plot Method for Decomposition Results in the Style of ggplot2
deseats

Locally Weighted Regression for Trend and Seasonality in Equidistant Time Series under Short Memory
trend

Obtain Estimated Components of a Time Series
show,smoothing_options-method

Show Method for Smoothing Options
gain

Gain Function Generic
runDecomposition

Shiny App for Decomposing Seasonal Time Series
s_semiarma

Fitting of a Seasonal Semiparametric ARMA Model
measures

Forecasting Accuracy Measure Calculation
autoplot,deseats_fc-method

ggplot2 Plot Method for Class "deseats_fc"
plot,deseats_fc-method

Plot Method for Class "deseats_fc"
zoo_to_ts

Time Series Object Conversion from "zoo" to "ts"
plot,hfilter-method

Plot Method for the Results of a Hamilton Filter
order_poly,smoothing_options-method

Retrieve or Set Smoothing Options
trend,decomp-method

Obtain Individual Components of a Decomposed Time Series
fitted,hfilter-method

Fitted Components of the Hamilton Filter
read_ts

Read in a Dataset Directly as an Object of Class "ts" or "mts"
gain,deseats-method

Obtain gain function values for DeSeaTS Trend and Detrend Filters
predict,s_semiarma-method

Point and Interval Forecasts for Seasonal Semi-ARMA Models
set_options

Specification of Smoothing Options
seasonplot

Creation of Seasonal Plots
select_bwidth

Optimal Bandwidth Estimation for Locally Weighted Regression in Equidistant Time Series under Short Memory
seasonplot_gg

Creation of Seasonal Plots in the Style of ggplot2
show,deseats-method

Printing of deseats Function Results
show,s_semiarma-method

Show Method for Objects of Class "s_semiarma"
CONSUMPTION

Quarterly Real Final Consumption Expenditure for Australia
BV4.1

Trend and Seasonality Estimation Using the Berlin Procedure 4.1
EXPENDITURES

Quarterly Personal Consumption Expenditures in the USA
animate,deseats-method

Animate Locally Weighted Regression Results
GDP

Quarterly US GDP
CIVLABOR

Monthly Civilian Labor Force Level in the USA
ENERGY

Monthly Total Production and Distribution of Electricity, Gas, Steam, and Air Conditioning for Germany
DEATHS

Monthly Deaths in Germany
HOUSES

Monthly New One Family Houses Sold in the USA
COVID

Daily Confirmed New COVID-19 Cases in Germany
LIVEBIRTHS

Monthly Live Births in Germany
SUNSHINE

Monthly Hours of Sunshine in Germany
TEMPERATURE

Monthly Average Temperature in Germany
animate

Automatic Creation of Animations