50% off | Unlimited Data & AI Learning
Get 50% off unlimited learning

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

285

Version

1.1.0

License

GPL-3

Maintainer

Dominik Schulz

Last Published

July 12th, 2024

Functions in deseats (1.1.0)

SAVINGS

Quarterly Savings of Private Households in Germany
deseats-package

Deseasonalize Time Series
autoplot,hfilter-method

ggplot2 Plot Method for the Results of a Hamilton Filter
expo

Automatic Creation of Animations
expo,deseats_fc-method

Exponentiate deseats Forecasts
RAINFALL

Monthly Average Rainfall in Germany
bwidth_confint

Bootstrapping Confidence Intervals for Locally Weighted Regression Bandwidths
create.gain

Create Gain Function from a Linear Time Series Filter
fitted,hfilter-method

Fitted Components of the Hamilton Filter
gain,deseats-method

Obtain gain function values for DeSeaTS Trend and Detrend Filters
bwidth,deseats-method

Retrieve the Used Bandwidth from an Estimation Object
ma_decomp

Decomposition of Time Series Using Moving Averages
lm_decomp

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

Plot Method for Decomposition Results in the Style of ggplot2
autoplot,deseats_fc-method

ggplot2 Plot Method for Class "deseats_fc"
hamilton_filter

Time Series Filtering Using the Hamilton Filter
seasonplot

Creation of Seasonal Plots
llin_decomp

Decomposition of Time Series Using Local Linear Regression
seasonplot_gg

Creation of Seasonal Plots in the Style of ggplot2
read_ts

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

Point and Interval Forecasts for Seasonal Semi-ARMA Models
trend,decomp-method

Obtain Individual Components of a Decomposed Time Series
show,smoothing_options-method

Show Method for Smoothing Options
runDecomposition

Shiny App for Decomposing Seasonal Time Series
measures

Forecasting Accuracy Measure Calculation
order_poly,smoothing_options-method

Retrieve or Set Smoothing Options
plot,deseats_fc-method

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

Plot Method for the Results of a Hamilton Filter
s_semiarma

Fitting of a Seasonal Semiparametric ARMA Model
plot,decomp-method

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

Gain Function Generic
trend

Obtain Estimated Components of a Time Series
select_bwidth

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

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

Smoothing Option Generics
set_options

Specification of Smoothing Options
hA_calc

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

Printing of deseats Function Results
zoo_to_ts

Time Series Object Conversion from "zoo" to "ts"
show,s_semiarma-method

Show Method for Objects of Class "s_semiarma"
HOUSES

Monthly New One Family Houses Sold in the USA
BV4.1

Trend and Seasonality Estimation Using the Berlin Procedure 4.1
arma_to_ma

MA Representation of an ARMA Model
arma_to_ar

AR Representation of an ARMA Model
EXPENDITURES

Quarterly Personal Consumption Expenditures in the USA
GDP

Quarterly US GDP
COVID

Daily Confirmed New COVID-19 Cases in Germany
LIVEBIRTHS

Monthly Live Births in Germany
CIVLABOR

Monthly Civilian Labor Force Level in the USA
ENERGY

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

Monthly Total Volume of Retail Trade in Germany
CONSUMPTION

Quarterly Real Final Consumption Expenditure for Australia
animate

Automatic Creation of Animations
animate,deseats-method

Animate Locally Weighted Regression Results
TEMPERATURE

Monthly Average Temperature in Germany
DEATHS

Monthly Deaths in Germany
NOLABORFORCE

Monthly Number of US Persons Not in the Labor Force
SUNSHINE

Monthly Hours of Sunshine in Germany