Learn R Programming

autostsm

autostsm (Automatic Structural Time Series Model) is designed to automatically detect the appropriate decomposition for a univariate time series into trend, seasonal, and cycle components using a state space approach. The package also has the functionality perform structural interpolation: i.e. interpolated a quarterly series into a monthly series using either end of period, period average, or period sum methods. The unobserved components are estimated with the Kalman filter and all model parameters are estimated using maximum likelihood. The Kalman filter and smoother are implemented in Rcpp so it is reasonably fast. This package is designed to handle time series of any frequency (standard or not), series with multiple seasonalities, seasonalities with fractional periodicities, missing data imputation, and irregularly spaced dates (i.e. daily data with missing data due to weekends and holidays, etc.).

Installation

You can install the development version of autostsm like so:

devtools::install_git("https://bitbucket.org/ajhubb/autostsm.git")

Example

This is a basic example which shows you how to use the package on some example data. See the vignette for more examples:

library(autostsm)

##### Unemployment rate #####
#Not seasonally adjusted
data("UNRATENSA", package = "autostsm") #From FRED
UNRATENSA = data.table(UNRATENSA, keep.rownames = TRUE)
colnames(UNRATENSA) = c("date", "y")
UNRATENSA[, "date" := as.Date(date)]
UNRATENSA[, "y" := as.numeric(y)]
stsm = stsm_estimate(UNRATENSA, verbose = TRUE)
stsm_fc = stsm_forecast(stsm, y = UNRATENSA, n.ahead = floor(stsm$freq)*3, plot = TRUE)
stsm_fc = merge(stsm_fc, 
                stsm_detect_anomalies(stsm, y = UNRATENSA, plot = TRUE), 
                by = "date", all = TRUE)
stsm_fc = merge(stsm_fc, 
                stsm_detect_breaks(stsm, y = UNRATENSA, plot = TRUE, show_progress = TRUE), 
                by = "date", all = TRUE)

Copy Link

Version

Install

install.packages('autostsm')

Monthly Downloads

883

Version

3.1.4

License

GPL (>= 2)

Maintainer

Alex Hubbard

Last Published

March 8th, 2024

Functions in autostsm (3.1.4)

UNRATE

Unemployment Rate Seasonally Adjusted
NA000334Q

US GDP Not Seasonally Adjusted
stsm_detect_anomalies

Detect Anomalies
stsm_dates_to_interpolate

Create dates to interpolate
stsm_ssm

State space model
UNRATENSA

Unemployment Rate Not Seasonally Adjusted
stsm_na_kalman

Missing Value Imputation by Kalman Smoothing and State Space Models
stsm_prior

Return a naive model prior decomposition
stsm_filter

Kalman Filter
stsm_fixed_pars

Fixed parameter setting
stsm_detect_cycle

Detect cycle from the data
stsm_detect_trend

Detect trend type
stsm_coxstuart

Cox-Stuart Test
stsm_init_pars

Get initial parameter estimates for estimation
SP500

S&P 500
stsm_detect_seasonality

Detect seasonality from the data
stsm_forecast

Kalman Filter and Forecast
stsm_constraints

Set the inequality constraints for estimation
stsm_format_exo

Format exo
DGS5

5 Year Treasury Yield
autostsm-package

autostsm: Automatic Structural Time Series Models
stsm_build_dates

Build the date sequence as a Date type
stsm_detect_frequency

Detect frequency and dates from the data
stsm_check_exo

Data check for input exo
stsm_check_y

Data check for input y
stsm_check_exo_fc

Data check for input exo.fc
stsm_detect_breaks

Detect Structural Breaks
stsm_estimate

Trend cycle seasonal decomposition using the Kalman filter.
stsm_bdiag

Build a block diagonal matrix from two matrices
GDP

US GDP Seasonally Adjusted
stsm_detect_multiplicative

Detect if log transformation is best