Seasonal Adjustment of Multiple Series

[This article was first published on cynkra, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

seasonal is an easy-to-use and full-featured R-interface to X-13ARIMA-SEATS, the seasonal adjustment software developed by the United States Census Bureau. The latest CRAN version of seasonal makes it much easier to adjust multiple time series.

illustration
Photo by Meriç Dağlı


seasonal depends on the x13binary package to access pre-built binaries of X-13ARIMA-SEATS on all platforms and does not require any manual installation. To install both packages:

install.packages("seasonal")
        

seas is the core function of the seasonal package. By default, seas calls the automatic procedures of X-13ARIMA-SEATS to perform a seasonal adjustment that works well in most circumstances:

seas(AirPassengers)
        

For a more detailed introduction, read our article in the Journal of Statistical Software.

Multiple Series Adjusmtent

In the latest CRAN version 1.8, it is now possible to seasonally adjust multiple series in a single call to seas(). This is done by using the built-in batch mode of X-13. It removes the need for loops or lapply() in such cases, and finally brings one missing feature of X-13 to seasonal – the composite spec.

Multiple adjustments can be performed by supplying multiple time series as an "mts" object:

library(seasonal)
        m <- seas(cbind(fdeaths, mdeaths), x11 = "")
        final(m)
        

This will perform two seasonal adjustments, one for fdeaths and one for mdeaths. X-13 spec-argument combinations can be applied in the usual way, such as x11 = "". Note that if entered that way, they will apply to both series. The vignette on multiple adjustments describes how to specify options for individual series.

Backend

X-13 ships with a batch mode that allows multiple adjustments in a single call to X-13. This is now the default in seasonal (multimode = "x13"). Alternatively, X-13 can be called for each series (multimode = "R"). The results should be usually the same, but switching to multimode = "R" may be useful for debugging:

seas(cbind(fdeaths, mdeaths), multimode = "x13")
        seas(cbind(fdeaths, mdeaths), multimode = "R")
        

In general, multimode = "x13" is faster. The following comparison on a MacBook Pro shows a modest speed gain, but bigger differences have been observed on other systems:

many <- rep(list(fdeaths), 100)
        system.time(seas(many, multimode = "x13"))
        #   user  system elapsed
        #  9.415   0.653  10.079
        system.time(seas(many, multimode = "R"))
        #   user  system elapsed
        # 11.130   1.039  12.324
        

composite spec

Support for the X-13 batch mode makes it finally possible to use the composite spec – the one feature of X-13 that was missing in seasonal. Sometimes, one has to decide whether seasonal adjustment should be performed on a granular level or on an aggregated level. The composite spec helps you to analyze the problem and to compare the direct and the indirect adjustment.

The composite argument is a list with an X-13 specification that is applied on the aggregated series. Specification works identical as for other series in seas(), including the application of the defaults. If you provide an empty list, the usual defaults of seas() are used. A minimal composite call looks like this:

seas(
        cbind(mdeaths, fdeaths),
        composite = list(),
        series.comptype = "add"
        )
        

You can verify that the composite refers to the total of mdeaths and fdeaths by running:

seas(ldeaths)
        

where ldeaths is the sum of mdeaths and fdeaths.

Acknowledgement

Many thanks to Severin Thöni and Matthias Bannert, for demonstrating the benefits of the X-13 batch mode. Also to the ETH KOF, for partially funding this development.

To leave a comment for the author, please follow the link and comment on their blog: cynkra.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)