Alexander Kowarik 1,Angelika Meraner 1 and Matthias Templ 1,2 1. Statistics Austria 2. Vienna University of Technology user 2015 Aalborg, July 2015 Seasonal Adjustment with the R packages x12 and x12gu Kowarik, Meraner, Templ (STAT, TU) 1/ 20 Aalborg, 2015
Motivation X12-ARMA is widely used and state-of-the-art in many statistical o ces Statistical o ces (we) have to apply seasonal adjustment frequently and to many di erent time series Graphical analysis should always be included in the process Results should be reproducable and easy to modify (X-13-ARMA-SEATS is the successor if X12-ARMA, SEATS not yet implemented) æ R-packages x12 and x12gu Kowarik, Meraner, Templ (STAT, TU) 2/ 20 Aalborg, 2015
Features Access to X12-ARMA directly from within R (no spc, out,... files) Class oriented command line interface Change tracking for the X12-ARMA parameters and output Batch processing of multiple time series at once (in parallel) Easy generation of graphical output mport the parameter settings from spc files to R Kowarik, Meraner, Templ (STAT, TU) 3/ 20 Aalborg, 2015
Class x12single Objects of class x12single contain the following information ts - The original time serie x12parameter - The current X12-ARMA parameter setting x12output - The current X12-ARMA results x12oldparameter - All previous X12-ARMA parameter settings x12oldoutput - All previous X12-ARMA results Kowarik, Meraner, Templ (STAT, TU) 4/ 20 Aalborg, 2015
Methods x12single Methods for this class are: x12 - (Re)Run X12-ARMA setp,getp - Change/View parameters prev,cleanhistory - Revert to a previous X12 parameter setting and output plot,plotrsdacf,plotspec,plotseasfac - Plot methods s <- new("x12single", ts = AirPassengers, tsname = "air") s <- x12(s) forecast <- s@x12output@forecast Kowarik, Meraner, Templ (STAT, TU) 5/ 20 Aalborg, 2015
Class x12batch Objects of class x12batch Combination of multiple objects of class x12single nherit the methods from class x12single xb <- new("x12batch", list(airpassengers, AirPassengers, AirPassengers )) xb <- setp(xb, list(estimate = TRUE, outlier.types = "all") xb <- setp(xb, list(outlier.types = "LS", index=1) # options( x12.parallel=2) xb <- x12(xb) Kowarik, Meraner, Templ (STAT, TU) 6/ 20 Aalborg, 2015
Real example Batch - Tourism > dat <- read.csv2("http://bit.ly/1rtf31s") > tsobject <- lapply(split(dat[,5], list(dat[,2], dat[,3])), + # by state and country of origin + ts,start = c(1973,11), frequency = 12) > length(tsobject) [1] 774 > xb <- new("x12batch", tsobject[1:3]) > xb <- setp(xb,list(forecast_years=3)) The parameters for all objects are changed. > xb <- x12(xb) Time difference of 6.766999 secs Kowarik, Meraner, Templ (STAT, TU) 7/ 20 Aalborg, 2015
Real example Batch - Tourism > plot(xb@x12list[[1]], forecast = TRUE, + span = c(2008,4,2018,4), ylab = "Nights spend") Time Series with Forecasts Nights spend 30000 50000 70000 2008.1 2010.1 2012.1 2014.1 2016.1 2018.1 Date Kowarik, Meraner, Templ (STAT, TU) 8/ 20 Aalborg, 2015
Plot functions Output of the plot() method showing trend and forecasts with prediction intervals as well as the seasonally adjusted series. Time Series with Forecasts Value 100 200 300 400 500 600 700 1950.1 1952.1 1954.1 1956.1 1958.1 1960.1 1962.1 Date Original Seasonally Adjusted Trend Kowarik, Meraner, Templ (STAT, TU) 9/ 20 Aalborg, 2015
Plot functions Output of the plotrsdacf() function from the R package x12, showing the autocorrelations of the squared residuals from the regarma model. Autocorrelations of the Squared Residuals ACF 0.2 0.1 0.0 0.1 0.2 2 4 6 8 10 12 Lag Kowarik, Meraner, Templ (STAT, TU) 10 / 20 Aalborg, 2015
Plot functions Output of the plotspec() function, showing the spectrum of the seasonally adjusted series. Spectrum of the Seasonally Adjusted Series Decibels 40 35 30 0.0 0.1 0.2 0.3 0.4 0.5 Frequency Spectrum Seasonal Frequencies Trading Day Frequencies Kowarik, Meraner, Templ (STAT, TU) 11 / 20 Aalborg, 2015
Plot functions V Output of the seasonal factor plot (plotseasfac()). Seasonal Factors by period and S Ratios Value 0.8 0.9 1.0 1.1 1.2 1.3 Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Seasonal Factors Mean S Ratio Replaced S Ratio Kowarik, Meraner, Templ (STAT, TU) 12 / 20 Aalborg, 2015
Plot functions V Output of the plot() method showing outliers in the RegARMA model. Original Series and Trend Value 100 200 300 400 500 600 1950 1952 1954 1956 1958 1960 Date Original AO Trend LS TC Kowarik, Meraner, Templ (STAT, TU) 13 / 20 Aalborg, 2015
Features x12gu Overview of all (implemented) X12-ARMA parameters nteractive adjustment of the parameters nteractive graphics Visualisation of the automatically detected outliers Easy addition, removal of manually selected outliers Kowarik, Meraner, Templ (STAT, TU) 14 / 20 Aalborg, 2015
Main View x12gu > xbn <- x12gu(xb) Kowarik, Meraner, Templ (STAT, TU) 15 / 20 Aalborg, 2015
Main View x12gu Kowarik, Meraner, Templ (STAT, TU) 16 / 20 Aalborg, 2015
Graphics x12gu Kowarik, Meraner, Templ (STAT, TU) 17 / 20 Aalborg, 2015
nteractive Plots x12gu Kowarik, Meraner, Templ (STAT, TU) 18 / 20 Aalborg, 2015
nteractive Plots x12gu Kowarik, Meraner, Templ (STAT, TU) 19 / 20 Aalborg, 2015
Details and contact JSS paper Seasonal Adjustment with the R packages x12 and x12gu Contact: Alexander Kowarik alexander.kowarik@statistik.gv.at https://github.com/alexkowa/x12 Kowarik, Meraner, Templ (STAT, TU) 20 / 20 Aalborg, 2015