Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
AlexanderKowarik1,Angelika
Meraner1 andMatthias Templ1,2
1. Statistics Austria
2. Vienna University of
Technology
useR 2015
Aalborg, July 2015
Seasonal Adjustment with the R
packages x12 and x12GUI
Kowarik, Meraner, Templ (STAT, TU) 1 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Motivation
I X12-ARIMA is widely used and state-of-the-art in many statisticalo�ces
I Statistical o�ces (we) have to apply seasonal adjustment frequentlyand to many di↵erent time series
I Graphical analysis should always be included in the process
I Results should be reproducable and easy to modify
I (X-13-ARIMA-SEATS is the successor if X12-ARIMA, SEATS notyet implemented)
≠æ R-packages x12 and x12GUI
Kowarik, Meraner, Templ (STAT, TU) 2 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Features
I Access to X12-ARIMA directly from within R (no spc, out, . . . files)
I Class oriented command line interface
I Change tracking for the X12-ARIMA parameters and output
I Batch processing of multiple time series at once (in parallel)
I Easy generation of graphical output
I Import the parameter settings from spc files to R
Kowarik, Meraner, Templ (STAT, TU) 3 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Class x12Single
Objects of class x12Single contain the following information
I ts - The original time serie
I x12Parameter - The current X12-ARIMA parameter setting
I x12Output - The current X12-ARIMA results
I x12OldParameter - All previous X12-ARIMA parameter settings
I x12OldOutput - All previous X12-ARIMA results
Kowarik, Meraner, Templ (STAT, TU) 4 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Methods x12Single
Methods for this class are:
I x12 - (Re)Run X12-ARIMA
I setP,getP - Change/View parameters
I prev,cleanHistory - Revert to a previous X12 parameter settingand output
I 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
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Class x12Batch
Objects of class x12Batch
I Combination of multiple objects of class x12Single
I Inherit 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
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
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
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Real example Batch - Tourism
> plot(xb@x12List[[1]], forecast = TRUE,
+ span = c(2008,4,2018,4), ylab = "Nights spend")
Time Series with Forecasts
Date
Nig
hts
spen
d
3000
050
000
7000
0
2008.1 2010.1 2012.1 2014.1 2016.1 2018.1
Kowarik, Meraner, Templ (STAT, TU) 8 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Plot functions I
I Output of the plot() method showing trend and forecasts withprediction intervals as well as the seasonally adjusted series.
Time Series with Forecasts
Date
Valu
e
100
200
300
400
500
600
700
1950.1 1952.1 1954.1 1956.1 1958.1 1960.1 1962.1
Original Seasonally Adjusted Trend
Kowarik, Meraner, Templ (STAT, TU) 9 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Plot functions II
I Output of the plotRsdAcf() function from the R package x12,showing the autocorrelations of the squared residuals from theregARIMA model.
2 4 6 8 10 12
−0.2
−0.1
0.0
0.1
0.2
Autocorrelations of the Squared Residuals
Lag
ACF
Kowarik, Meraner, Templ (STAT, TU) 10 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Plot functions III
I Output of the plotSpec() function, showing the spectrum of theseasonally adjusted series.
0.0 0.1 0.2 0.3 0.4 0.5
−40
−35
−30
Spectrum of the Seasonally Adjusted Series
Frequency
Dec
ibel
s
Spectrum Seasonal Frequencies Trading Day Frequencies
Kowarik, Meraner, Templ (STAT, TU) 11 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Plot functions IV
I Output of the seasonal factor plot (plotSeasFac()).
0.8
0.9
1.0
1.1
1.2
1.3
Seasonal Factors by period and SI Ratios
Valu
e
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
●
●
●
●●●
●
●●●●●
● ●
●
●
●●
●
●●●
●●●●
●
●
●
●
●
●●
●●●
●
●●
●
●
●
●
●
●
●
●●
●
●
●
●
●
●
●
● ●
●
●
●
●
●
●●●●
●
●
●
●
●●
●
●●
●
●
●●●
●●
●
●●
●
●
●
●
●●
●●
●
●
●●
●●●
●
●
●●
●
●
●
●
●●●
●
●
●
●
●●
●●●
●●
●●
●
●
●●
●
●●●●
●
●
●
●
●
●
●●
●●
●
●●
●●●
●
●
●●
●●
●●
●●●
●
●
●
●
●
●
Seasonal FactorsMean
SI RatioReplaced SI Ratio
Kowarik, Meraner, Templ (STAT, TU) 12 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Plot functions V
I Output of the plot() method showing outliers in the RegARIMAmodel.
Original Series and Trend
Date
Value
1950 1952 1954 1956 1958 1960
100
200
300
400
500
600
OriginalAO
TrendLS TC
Kowarik, Meraner, Templ (STAT, TU) 13 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Features x12GUI
I Overview of all (implemented) X12-ARIMA parameters
I Interactive adjustment of the parameters
I Interactive graphics
I Visualisation of the automatically detected outliers
I Easy addition, removal of manually selected outliers
Kowarik, Meraner, Templ (STAT, TU) 14 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Main View x12GUI
> xbn <- x12GUI(xb)
Kowarik, Meraner, Templ (STAT, TU) 15 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Main View x12GUI
Kowarik, Meraner, Templ (STAT, TU) 16 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Graphics x12GUI
Kowarik, Meraner, Templ (STAT, TU) 17 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Interactive Plots x12GUI I
Kowarik, Meraner, Templ (STAT, TU) 18 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Interactive Plots x12GUI II
Kowarik, Meraner, Templ (STAT, TU) 19 / 20 | Aalborg, 2015
S T A T I S T I K A U S T R I A
D i e I n f o r m a t i o n s m a n a g e r
Details and contact
I JSS paper“Seasonal Adjustment with the R packages x12 andx12GUI”
I Contact: Alexander Kowarik [email protected]
I https://github.com/alexkowa/x12
Kowarik, Meraner, Templ (STAT, TU) 20 / 20 | Aalborg, 2015